基於我所學到的here,我使用這個連接字符串:爲什麼我連接到本地SQL Server數據庫失敗?
using (var conn = new SqlConnection(@"AttachDBFilename=C:\HoldingTank\AdventureWorksLT2012_Database\AdventureWorksLT2012_Data.MDF;Integrated Security=True;User Instance=true"))
...以(試圖)連接到本地SQL Server數據庫,但我在運行時得到此異常:
System.Data.SqlClient.SqlException was unhandled by user code
HResult=-2146232060
Message=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)
Source=.Net SqlClient Data Provider
基於我的遺產的MS Access連接字符串,我以前還曾有過:
Provider=System.Data.SqlClient;
之前的「附加DBFilename = ...「連接字符串的一部分,但導致它自己的例外...
「B. Clay Shannon的答案是使用集成安全性的LocalDB連接字符串的一個很好的例子。」 B.粘土香農是解開這個問題的貓。 –
不錯的鏈接!現在可以使用: Data Source =(LocalDb)\ v11.0; AttachDBFilename = C:\ HoldingTank \ AdventureWorksLT2012_Database \ AdventureWorksLT2012_Data.MDF; Integrated Security = True;「 –
對不起,我已經編輯了我的答案,很高興你的工作。 – agileMike