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