2015-05-25 174 views
0

我試圖調試應用程序,但是當我運行它,我收到以下錯誤信息:SQL連接字符串連接失敗SQL實例

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)

我已經打開了檢查雙端口1433和它從我目前的位置開放並且可以到達。我還啓用了TCP/IP遠程連接,並可以使用SQL Server Studio Manager進行遠程連接。

我使用的連接字符串是:

Data Source=xx.xx.xxx.xx, 1433;Network Library=DBMSSOCN;Initial Catalog=KnightOwl-Demo;Persist Security Info=True;User ID=KnightOwlGentleshaw; Password=xxxxxx 

我90%肯定有一些錯誤的連接字符串,但我不知道是什麼?

+0

你能夠在SSMS中連接嗎? –

+0

是的,我可以從SSMS –

+0

和同一臺機器連接?用相同的用戶名,服務器網址? –

回答

2

如果您不能確定在連接字符串,使用UDL文件來進行測試:

  1. 創建一個新的文本文件。
  2. 擴展名更改爲.UDL(如1.txt1.udl
  3. 轉到Connection標籤
  4. 插入您的憑據(服務器名\實例,用戶名+密碼/ Windows安全等)
  5. 檢查Allow saving password複選框
  6. 點擊Test Connection並獲得成功消息。
  7. 單擊確定(這將關閉表單)
  8. 打開1.udl文件在文本編輯器 - 它將包括用於連接成功

現在你可以比較一下連接的連接字符串字符串/使用你現在工作的那個...

祝你好運!

enter image description here

0

試試這個代碼

Data Source=xx.xx.xxx.xx;Initial Catalog=KnightOwl-Demo;Persist Security Info=True;