2015-02-11 112 views
1

我已經構建了一個.asmx Web服務,它從本地sql server 2014數據庫中檢索信息。 一切工作在本地主機上正常,但將Web服務發佈到Azure中後,我得到的錯誤:Web服務 - SQL連接字符串

An unhandled exception of type 'System.Web.Services.Protocols.SoapException' occurred in System.Web.Services.dll

Additional information: Server was unable to process request. ---> 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

SQL Server配置爲允許遠程連接。

我的連接字符串是這樣的:

string con2 = @"Data Source=OfficePc\MSSQLSERVER2014;Initial Catalog=Database;Persist Security Info=True;User ID=Admin;Password=123456"; 

是錯誤的東西從連接字符串中缺少的結果,還是我失去了一些配置的變化?

+0

您確定這是正確的連接字符串嗎?例如,如果您使用Visual Studio,則可以在「服務器資源管理器」窗口上進行檢查。 – 2015-02-11 11:42:00

+1

基於Azure的Web服務知道'OfficePc \ MSSQLSERVER2014'在哪裏?這不應該是一個IP或什麼? – 2015-02-11 11:44:51

回答

1

正如保羅在這個問題下的評論中提到,你的連接字符串指向本地數據庫資源(可能在您的開發機器上)。即使您將本地數據庫服務器配置爲支持遠程連接,地址OfficePc\MSSQLSERVER2014也不可尋址,因爲這不等同於機器地址(IP地址)。

您的應用程序需要通過訪問的IP地址(這可能需要你做你的本地網絡上的某些端口轉發,或在防火牆上打開的端口)連接到你的數據庫。

或者,您可以天青(或者與在虛擬機中的SQL Server或SQL數據庫服務)遷移數據庫。

請記住:如果您正在訪問來自Azure的本地(本地)數據庫服務器,會有延遲增加,以及一些出口帶寬的成本。

0

它看起來像SQL Server實例沒有運行或無法訪問。嘗試使用SSMS連接到同一個數據庫,並且如果得到相同的錯誤,那麼該實例沒有運行。

+0

連接字符串嘗試引用本地數據庫服務器,而Azure中不存在該服務器。 – 2015-02-11 13:15:49

0

大多數情況下,當數據庫服務器未找到時發生錯誤。重新檢查是否正確提及服務器名稱(數據源)。如果手動生成連接字符串,則使用.uld文件生成連接字符串。

要自動生成使用.UDL文件的連接字符串:

  1. Create a sampe.txt file.
  2. Rename it as sample.udl file.
  3. Then double click on it, It will show you window entitled 'Data Link Properties'.
  4. Configure the connection there.
  5. Then Test the connection using test connection button.
  6. Then open the file with notepad. It will show you the exact connection string.

enter image description here

更多參考檢查:MSDN