debugsqlMinor
Linked Server to Mirrored Database Fails
Viewed 0 times
mirroredfailsdatabaseserverlinked
Problem
I've setup up a mirrored database on two servers Server1 and Server 2.
On Server3, I'm trying to setup a linked server that will work regardless of which server has the active database.
I'm using this to setup the linked server.
As long as MyDatabase on Server1 is the principal, the linked server works. When I manually failover to Server2, the linked server fails.
The error messages are:
The 18456 and 4060 error messages repeat until the query times out after 60 seconds.
On Server1, I can see repeated failures trying to login to "MyDatabase". It's failing because Server1 is the mirror. I see no attempts to connect to Server2 which is the principal.
If I recreate the linked server with Server2 as the Primary and Server1 as the Mirror, it will work until I fail back to Server1.
The mirrored servers are SQL Server 2012 and the box I'm trying to create a linked server on i
On Server3, I'm trying to setup a linked server that will work regardless of which server has the active database.
I'm using this to setup the linked server.
EXEC sp_addlinkedserver
@server = N'MyLinkedServer',
@srvproduct = N'',
@provider = N'SQLNCLI',
@provstr = N'Server=SERVER1;FailoverPartner=SERVER2;Network=dbmssocn',
@catalog = N'MyDatabase';
EXEC master.dbo.sp_serveroption
@server = N'MyLinkedServer',
@optname = N'data access',
@optvalue = N'true';
EXEC master.dbo.sp_serveroption
@server = N'MyLinkedServer',
@optname = N'rpc',
@optvalue = N'false';
EXEC master.dbo.sp_serveroption
@server = N'MyLinkedServer',
@optname = N'rpc out',
@optvalue = N'true';
EXEC master.dbo.sp_serveroption
@server = N'MyLinkedServer',
@optname = N'connect timeout',
@optvalue = N'60';
EXEC master.dbo.sp_addlinkedsrvlogin
@rmtsrvname = N'MyLinkedServer',
@locallogin = NULL,
@useself = N'False',
@rmtuser = N'sqluser',
@rmtpassword = N'sqlpassword';As long as MyDatabase on Server1 is the principal, the linked server works. When I manually failover to Server2, the linked server fails.
The error messages are:
Msg 11001, Level 16, State 1, Line 0
TCP Provider: No such host is known.
Msg 18456, Level 14, State 1, Line 1
Login failed for user 'sqluser'.
Msg 4060, Level 11, State 1, Line 1
Cannot open database "MyDatabase" requested by the login. The login failed.The 18456 and 4060 error messages repeat until the query times out after 60 seconds.
On Server1, I can see repeated failures trying to login to "MyDatabase". It's failing because Server1 is the mirror. I see no attempts to connect to Server2 which is the principal.
If I recreate the linked server with Server2 as the Primary and Server1 as the Mirror, it will work until I fail back to Server1.
The mirrored servers are SQL Server 2012 and the box I'm trying to create a linked server on i
Solution
This is a known issue. Linked servers which are looking for database mirroring logins only work for Windows logins not SQL Logins as talked about on this connect item. Basically you need to either hard code a username and password in the linked server, which isn't recommended or use Windows authentication to access the linked server.
Another option would be to setup alerts and SQL Agent jobs on the two machines so that when the database becomes active on those machines they automatically reconfigure the linked server with the correct servername.
Another option would be to setup alerts and SQL Agent jobs on the two machines so that when the database becomes active on those machines they automatically reconfigure the linked server with the correct servername.
Context
StackExchange Database Administrators Q#44404, answer score: 4
Revisions (0)
No revisions yet.