Welcome to WebmasterWorld Guest from 50.16.47.14

Forum Moderators: ocean10000

Message Too Old, No Replies

Connect to another server with sql syntax

   
4:14 pm on Jul 25, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



I need to connect to server b from server a using sql syntax to truncate a table. I cannot add it as a linked server. I've seen you can use openrowset but I need to truncate a table and I don't know how to do that. Any ideas?
5:21 am on Jul 26, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I have never tried it but SQL Server Integration Services [en.wikipedia.org] might due what your looking for.

[msdn.microsoft.com...]
5:28 am on Jul 26, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Scratch the previous post. I think I found a much much better way for you to do this ("OpenDataSource").

[msdn.microsoft.com...]

Example:

SELECT *
FROM OPENDATASOURCE('SQLNCLI',
'Data Source=London\Payroll;Integrated Security=SSPI')
.AdventureWorks2012.HumanResources.Employee
2:02 pm on Jul 26, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Yes, I was actually going to post back today, that's exactly what I used. I just had to create a stored procedure because I needed to truncate tables. So create the sp to truncate the tables on the actual database, and then from the other server EXEC OPENDATASOURCE('SQLNCLI','Data Source=SERVER\INSTANCE;Initial Catalog=dbName;User Id=user;Password=pass').[dbName].dbo.spName