2013-09-01 57 views
1

我試圖使用C#連接到SQL Server 2012數據庫,服務器和程序都在同一臺計算機上。當我嘗試連接時,出現異常:無法連接到SQL Server 2012

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: 25 - Connection string is not valid)

有一個內部異常,簡單地說{「The parameter is incorrect」}。

我試圖用這個

SqlConnection sql = new SqlConnection("Server=(local)\\MSSQLSERVER;Database=Test;User ID=logger;Password=logger;Trusted_Connection=False"); 
sql.Open(); 

我有一個名爲記錄器使用相同的文字作爲密碼SQL登錄連接,並把它映射數據庫測試。我相信我已經設置了服務器進行遠程登錄。

任何想法我缺少什麼?

回答

0

嘗試

SqlConnection sql = new SqlConnection("Server=.;Database=Test;User ID=logger;Password=logger;Trusted_Connection=False"); 

或者

SqlConnection sql = new SqlConnection("Server=local;Database=Test;User ID=logger;Password=logger;Trusted_Connection=False"); 
+0

第一個似乎已經奏效,讓我,爲什麼。謝謝。現在我只需要弄清楚爲什麼我的查詢不返回數據。 –

0

我相信它應該是(localdb)而非(local)

connectionstrings

錯誤消息確實狀態(末):

Connection string is not valid

,所以你需要在鏈接頁面確認。