Say I have a mirrored database on two servers: PRIMARY and SECONDARY.
I want to create a linked server on a 3rd machine that allows me to access the database on the mirrored pair.
This is what I'm using:
EXEC master.dbo.sp_addlinkedserver
@.server = N'MIRROR',
@.srvproduct=N'',
@.provider=N'SQLNCLI',
@.provstr=N'Server=PRIMARY;FailoverPartner=SECONDARY;'
select count (*) from mirror.pubs.dbo.authors
and it works fine if the database on PRIMARY is alive. however when the mirror has failed over to SECONDARY and PRIMARY is no longer available, I get the following when I try to query the database via the linked server:
OLE DB provider "SQLNCLI" for linked server "MIRROR" returned message "Login timeout expired".
OLE DB provider "SQLNCLI" for linked server "MIRROR" returned message "An error has occurred while establishing a connection to the server. When
connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.".
Msg 10061, Level 16, State 1, Line 0
TCP Provider: No connection could be made because the target machine actively refused it.
As far as I can tell, it doesn't try to contact SECONDARY at all. If I switch PRIMARY and SECONDARY in the connection string (ie @.provstr=N'Server=SECONDARY;FailoverPartner=PRIMARY;') then it works when SECONDARY is online, but not when the mirror has failed back to PRIMARY.
Any ideas?
Piers.
It is quit possible that the connection to the primary take long to fail before making second connection to the secondary. The default timeout value is 15 seconds for a connection. You can try extend the timeout value or you can upgrade to SP1 which has better retry logic that can deal with timeout better.|||All 3 servers are running 9.0.2047sp1/x64 on WS2k3sp1/x64.
I've also tried extending the connection timeout with
EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'connect timeout', @.optvalue=N'120'
but I still get the same error after ~20 seconds (regardless of the value I specify). I've looked at the network traffic and it never seems to attempt to establish a connection to the secondary.
here's the entire script I'm using:
EXEC master.dbo.sp_dropserver @.server= N'MIRROR'
EXEC master.dbo.sp_addlinkedserver
@.server = N'MIRROR',
@.srvproduct=N'',
@.provider=N'SQLOLEDB',
@.provstr=N'Server=PRIMARY;FailoverPartner=SECONDARY;'
GOEXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'collation compatible', @.optvalue=N'true'
EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'data access', @.optvalue=N'true'
EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'dist', @.optvalue=N'false'
EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'pub', @.optvalue=N'false'
EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'rpc', @.optvalue=N'true'
EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'rpc out', @.optvalue=N'true'
EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'sub', @.optvalue=N'false'
EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'connect timeout', @.optvalue=N'1000'
EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'collation name', @.optvalue=null
EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'lazy schema validation', @.optvalue=N'false'
EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'query timeout', @.optvalue=N'0'
EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'use remote collation', @.optvalue=N'true'select top 10 * from MIRROR.pubs.dbo.authors
What am I missing?
Piers.
No comments:
Post a Comment