c# - 无法将 Entity Framework 连接到本地 SQL Server Express

标签 c# sql-server entity-framework

我有连接字符串:

  <connectionStrings>
    <add name="SolrLocal" providerName="System.Data.SqlClient" connectionString="Data Source=.\SQLExpress;Initial Catalog=SpeedOfLightRailDB;Integrated Security=true" />
  </connectionStrings>

但是我得到了错误:

"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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"

这是我第一次使用 SQL Server Express,所以我可能遗漏了一些明显的东西......

至少有人可以确认这是 Entity Framework -> SQL Sever Express 的连接字符串的样子吗?我一直在努力让它发挥作用。

最佳答案

  1. 检查您的 windows 服务并确保 sql server express windows 服务正在运行。您可以通过从“运行”命令栏(Windows 键 + R)运行 services.msc 来获取服务。如果它没有运行,则启动它。
  2. 您是否安装了 SQL Server 管理工具?如果是这样,您可以尝试使用这些工具进行连接。如果您无法从那里连接到您的 sql server express 实例,很可能您也无法通过代码连接。如果您没有安装它,不用担心,您仍然可以通过下一步对其进行测试。
  3. 如果您在构建连接字符串方面需要帮助,下一个是一个很好的方法。在桌面上创建一个文本文件。将扩展名从 .txt 重命名为 .udl。打开文件,你会得到一个 Data Link Properties屏幕,从第一个选项卡开始(默认为选项卡 2),然后也填写第二个选项卡。一旦您在这里测试您的连接并且它工作正常,您可以使用 NotePad 打开文件或将扩展名重命名回 .txt 并在 NotePad 中打开它. 连接字符串将位于文本文件的第二行。只需将其复制并粘贴到您的 .config 文件即可。

如果以上方法均无效,请报告您发现的内容以及遇到的任何错误。

关于c# - 无法将 Entity Framework 连接到本地 SQL Server Express,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35677781/

相关文章:

c# - .NET System.Windows.Forms DateTimePicker CustomFormat 不正确

c# - 关闭基于奖励的视频广告时 Unity 游戏崩溃

c# - 为什么 Int32 类型的最大值为 2³¹ − 1?

python - MS SQL 无效的对象名称

mysql - 如何从我的 mysql 数据库导出存储过程

c# - VSTO:不包含列标题

sql - 如何查找花费大量时间的 SQL Server 查询?

c# - 使用附加子句更新实体

c# - 如何使用 Code First 在 ASP.NET MVC 5 Identity 2.0 中为 AspNetUser 表(Id 列)的客户表(CreatedBy 列)添加外键

.net - Azure表存储: questions regarding the structure of objects in a table