2017-03-04 89 views
0

我的連接字符串有什麼問題? 我將文件從一臺計算機複製到另一臺。然後我改變了我的連接字符串,因爲我從另一臺計算機移動了我的文件,它沒有連接到數據庫。當我嘗試連接到SQL Management Studio時,它成功連接到我的服務器,當我嘗試運行我的代碼時,它沒有。數據庫連接:Web.config Asp.net

這裏是我的連接字符串:(Web.config文件) - 我的服務器是Windows身份驗證

<add name="ConnectionStringMe" connectionString="Data Source=ZOZOW-PC\MSSQLEXPRESS;Database=sample_db;Persist Security Info = True" providerName="System.Data.SqlClient" /> 

它給我的錯誤:

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 服務器身份驗證然後我將它移動到Windows身份驗證

謝謝。

+0

如果你使用Windows身份驗證而不是SQL身份驗證去,那麼你將需要線「集成安全性=真」,你必須確保你的SQL數據庫中添加了具有正確權限的用戶。另外...你可以ping'ZOZOW-PC'...錯誤說「服務器找不到」... – beeker

+0

爲了將來的參考 - 當我有關於連接字符串的問題時,我總是喜歡看:http:// connectionstrings。 com/ – confusedandamused

+0

@beeker我不知道如何ping。教我。謝謝 – EnzoZow

回答

0

我相信你需要這個集成安全性= true到你的連接字符串,它應該工作。如果你的連接字符串中沒有這個,你需要指定密碼和用戶名。

<add name="ConnectionStringMe" connectionString="Data Source=ZOZOW-PC\MSSQLEXPRESS;Database=sample_db;Persist Security Info = True;Integrated Security=True" providerName="System.Data.SqlClient" /> 
+0

謝謝。 – EnzoZow

+0

另外,當我嘗試將它連接到我的daagridview的數據源時,它無法檢索模式,我該如何解決它? – EnzoZow

+0

您確定您已連接只有一個數據庫?因爲如果第一次連接,沒有理由第二次不通過。您也可以嘗試將數據源指定爲'。'這與當您指定全名ZOZOW-PC \ MSSQLEXPRESS時相同的方式連接到本地數據庫。這裏是我的數據庫連接字符串正在尋找