sqlsql-serverauthenticationtrustedconnection

How to run Distributed SQL Server Query with trusted connection


I want to run SQL Server query on the remote machine and this is what I am doing

EXEC sp_addlinkedserver 
   N'remote-server',
   N'SQL Server';
//I don't want to do this step, and want to use trusted connection to remote server
EXEC sp_addlinkedsrvlogin 'remote-server', 'false', NULL, 'sa', 'mypassword';

select * from [remote-server].[db_test].[dbo].[test_table];

EXEC sp_droplinkedsrvlogin 'remote-server',NULL;
EXEC sp_dropserver 'remote-server', 'droplogins';

I want to use the trusted connection to remote server, Is there any way so I can skip the username and password giving step and use the trusted connection as -T switch do in bcp utility?

or any other workaround? Currenty if I skip the sp_addlinkedsrvlogin then the distributed query select * from [remote-server].[db_test].[dbo].[test_table]; gives authentication failed error.


Solution

  • Try using EXEC sp_addlinkedsrvlogin 'remote-server' without other parameters

    check the link http://msdn.microsoft.com/en-us/library/ms189811(v=SQL.90).aspx