无法连接到LocalDB,文件未找到异常

时间:2016-08-25 07:31:36

标签: c# sql-server app-config

这是连接字符串

<add name="Tapo_ModelContainer" connectionString="metadata=res://*/filename.csdl|res://*/filename.ssdl|res://*/filename.msl;provider=System.Data.SqlClient;provider connection string='Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=APTapo;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework'" providerName="System.Data.SqlClient" />

例外

System.Data.EntityException {"The underlying provider failed on Open."}

内部异常

"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)"

内部异常

"The system cannot find the file specified"

如果我使用普通的SqlConnection类,我可以连接到数据库。

1 个答案:

答案 0 :(得分:0)

可能是因为权限。 在身份验证部分。如果无法编写正确的连接字符串,可以使用“工具”菜单项中的“连接到数据库”选项,如果“测试连接”正常,则复制连接字符串。