基于我所学到的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