您好我正尝试连接到Windows窗体项目中的本地SQL Server Compact数据库(.sdf
),并且一直面临此问题很长一段时间。我不允许为项目使用数据集,所有查询和连接都写在应用程序中。SDF本地数据库连接错误:40
System.Data.SqlClient.SqlException
A network-related or instance-specific error occurredwhile 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)
代码:
SqlConnection _Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["restaurant"].ToString());
SqlCommand _Command = _Connection.CreateCommand();
_Connection.Open(); // <- throws exception
谢谢!这有帮助! – Chris