Anil Namde Anil Namde - 1 month ago 5
C# Question

Need assistance with querying SQL Server

I am planning for monitoring application which will use SQL Server 2005/08 database. It will monitor old server(s) which are using SQL Server 2000 database. Tools task is to pick the data from the servers do some statistics and insert the data back into tools own database for reporting purpose.

I am using .NET(C#) as development environment.

What I would really like to do is implement stored procedures which will pick the monitoring data from other servers and insert it into the monitoring tools databases table.

Now I would like to know whether its possible to write stored procedure like this ? Or I would have to pick the data from servers in program using one connection and then insert it into tools database using the other connection?

Please let me know if in case you can foresee any complication that I should be aware of.

Also some informative/helpful pointers(links, books) will be helpful.

Thanks all for valuable inputs.

Answer

You can do it using stored procedures (assuming both servers can see each other of course), by using Linked Servers.

Once setup, you can query across servers by fully qualifying the object name:

SELECT * FROM [AnotherDbServer].[DatabaseName].[Schema].[TableName]