2

我有一个连接到SQL Server的VB.NET应用程序。未使用故障转移伙伴的VB.NET应用程序

我们最近增加了数据库镜像以防服务器故障。

当然,我们的SQL Server失败了,但VB.NET应用程序没有执行故障转移。

我发现,在我们的代码,是不是在连接字符串中指定故障转移合作伙伴,所以我更新了连接字符串,如下所示:

sConnectionString = "Data Source=PROD-SQL;Failover Partner=FAILOVER-SQL;Initial Catalog=DB;User ID=****;Password=******;" 

SqlClient.SqlConnection对象接受此连接字符串,但是当我打电话了.Open()命令它失败,并出现以下错误:

"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)" 

这是为什么?我们的Intranet应用程序发生故障(使用无DSN连接的传统ASP)。

应用程序在故障转移成功之前是否必须至少有一次成功的初始连接到主服务器?

谢谢!

+2

那么,错误指示命名管道都参与其中,并有[此警告(http://msdn.microsoft.com/en-us/library/ms366348 (v = sql.105).aspx):“因为命名管道不使用TCP/IP重试算法,所以在很多情况下,在连接到镜像数据库之前命名管道连接尝试可能会超时。你能够调整尝试使用TCP/IP吗? – 2012-08-03 14:39:37

+0

那么,如果我切换连接字符串以首先连接到故障转移服务器,它工作正常。我将如何调整它以尝试使用TCP/IP呢? – Tom 2012-08-03 15:36:46

+1

看我链接到的页面。将'Network = dbmssocn;'添加到连接字符串中。 – 2012-08-04 04:27:42

回答

0

运行这对你的本金分贝

SELECT DB_NAME(database_id) AS 'DatabaseName' 
, mirroring_role_desc 
, mirroring_safety_level_desc 
, mirroring_state_desc 
, mirroring_partner_instance 
FROM 
sys.database_mirroring WHERE mirroring_guid IS NOT NULL; 

在mirroring_partner_instance返回的值是将您的连接进行故障切换,故障转移不-SQL中使用的服务器名称。 FAILOVER-SQL将在第一次尝试获取连接时使用,但无法联系PROD-SQL。如果PROD-SQL可用,故障转移伙伴将从sql server值mirroring_partner_instance设置到缓存中。

这里看到更多的信息:http://blogs.msdn.com/b/spike/archive/2010/12/15/running-a-database-mirror-setup-with-the-sqlbrowser-service-off-may-produce-unexpected-results.aspx