HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Why am I getting a "login failed" when creating this linked server?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
thiswhycreatinglogingettingfailedwhenserverlinked

Problem

I'm creating a linked server from ServerA to ServerB, both of them are SQL Server 2008 servers. I need to create the linked server using a domain service account so that anyone will be able to utilize the linked server. ServerB only accepts Windows authentication, so I've added the service domain account to ServerB with proper permissions. I've verified the permissions by logging in with the service domain account to ServerB and everything looks great. But when I create a linked server on ServerA with the script below, I get a "login failed for user". Is this script incorrect, or am I missing something else?

USE [master]
GO

EXEC master.dbo.sp_addlinkedserver @server = N'ServerB', @srvproduct=N'', @provider=N'SQLNCLI', @datasrc=N'ServerB', @catalog=N'MyDatabase'
GO
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'ServerB',@useself=N'False',@locallogin=NULL,@rmtuser=N'mydomain\myuser',@rmtpassword='mypassword'
GO

Solution


  • Log in to the serverA using "mydomain\myuser" credentials.



-
Run below TSQL :

EXEC master.dbo.sp_addlinkedserver 
                            @server = N'serverB', 
                            @srvproduct=N'', 
                            @provider=N'SQLNCLI', 
                            @datasrc=N'serverB', 
                            @catalog=N'MyDatabase',
                            @provstr='Integrated Security=SSPI;'
GO
EXEC sp_addlinkedsrvlogin 'serverB', true  
go


-
Check if the "serverB" exists in sys.servers :

select * from sys.servers


-
Check if the "serverB" works from ServerA

select * from serverB.master.dbo.sysdatabases

Code Snippets

EXEC master.dbo.sp_addlinkedserver 
                            @server = N'serverB', 
                            @srvproduct=N'', 
                            @provider=N'SQLNCLI', 
                            @datasrc=N'serverB', 
                            @catalog=N'MyDatabase',
                            @provstr='Integrated Security=SSPI;'
GO
EXEC sp_addlinkedsrvlogin 'serverB', true  
go
select * from sys.servers
select * from serverB.master.dbo.sysdatabases

Context

StackExchange Database Administrators Q#43350, answer score: 3

Revisions (0)

No revisions yet.