Run one Query in all SQL Server instance which are in same network [closed]

StackOverflow https://stackoverflow.com/questions/20352308

  •  07-08-2022
  •  | 
  •  

سؤال

I have one query, need to execute in all SQL Server(around 70 instances from SQL 2000 to 2012 version) instances which are in same network and store the results to one centralized table.

Can any one help on this to design SSIS package?. I would like to design this in BIDS 2008.

Thanks in Advance

Sriram

لا يوجد حل صحيح

نصائح أخرى

This solution will take the same general form as any other SSIS solution that needs to perform the same task multiple times.

  1. Create a Connection Manager. I'm assuming OLE DB will suit your purpose and point it at the first instance. I will refer to it as SRC (source).

  2. Create a second Connection Manager for your central audit server. I will refer to it as DST (destination).

  3. You will want to use add a Foreach Loop Container onto the canvas. This will consume a list of values (your servers) to enable you to change the Connection Manager for each value in the list.

  4. Add a Data Flow task.

    1. Add an OLE DB Source component. Use the Connection Manaager SRC and change your query type from Table to Query and write your query (SELECT @@version as ServerVersion). Your query can be whatever data you need to acquire from the source systems but the metadata must remain consistent across all your instances. Columns cannot change data types.

    2. Add an OLE DB Destination component. Use the Connection Manager DST and select the table you wish to have the auditing data written to. Ensure that the "Fast Load" is selected to get optimal performance.

  5. Server list source - I have not addressed this as this is dependent on how you have defined your list.

    • Execute SQL Task If you have your servers in a table, then you can simply query it and store those values in an SSIS Variable of type Object. Wire the Execute SQL Task to point to the Foreach Loop. You will then modify the Foreach Loop Container to shred the list. If you search on that term, you'll have a host of examples walking you through it.

    • If you have a static, predefined list, you can change the enumerator type on the Foreach Loop Container and simply add each value in there.

    • Web service task - Perhaps you have a centralized service that emits some XML for you to consume. Shred that XML in your Foreach Loop Container.

    • WMI It might be possible to use WMI to find all the SQL Servers on your network. Experiment, have fun

  6. Expression - The net result of all this shredding is that for each value in your list, you will pop a value out of your list into an SSIS Variable. You will need to then use this Variable (server, server + instance) to make the SRC change each time the loop enumerates (otherwise you'll run the same query on the same server N times). This is done by right-clicking on the SRC Connection Manager and choosing Properties. In the Properties window, you will find Expressions and click the ellipses ... I find it's simpler to just change the whole ConnectionString property but you might be able to get by with just changing the Server/ServerName value.

At this point, you should have 2-3 objects on your Control Flow canvas, 2 Connection Managers, 1 of those Connection Managers has an Expression on it and 1-2 Variables defined.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top