【问题标题】:Cannot connect to LocalDB, file not found exception无法连接到 LocalDB,找不到文件异常
【发布时间】:2017-01-01 12:41:16
【问题描述】:

这里是连接字符串

<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 类,我可以连接到数据库。

【问题讨论】:

  • 确保服务正在你的机器上运行.....
  • 内部异常告诉你它无法连接到的问题:(LocalDB)\MSSQLLocalDB 看看:connectionstrings.com/sql-server-2012 我猜正确的数据源将是localhost.\SqlExpress\ 并确保服务是运行

标签: c# sql-server app-config


【解决方案1】:

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

【讨论】:

  • 或创建一个文本文件并将其从 .txt 重命名为 .udl。然后双击它,您将拥有一个可以构建和测试连接字符串的表单。
猜你喜欢
  • 2016-08-10
  • 2022-01-20
  • 1970-01-01
  • 1970-01-01
  • 2017-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多