无法将Entity Framework连接到本地SQL Server Express [英] Can't connect Entity Framework to local SQL Server Express

查看:81
本文介绍了无法将Entity Framework连接到本地SQL Server Express的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有连接字符串:

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

但是我收到错误:

与SQL Server建立连接时发生与网络相关或特定于实例的错误,未找到服务器或无法访问。验证实例名称是否正确,并且SQL Server是否配置为允许远程连接(提供者:SQL网络接口,错误:26 - 定位服务器/实例指定错误)

"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,所以我可能会丢失一些明显的东西....

This is my first time playing with SQL Server Express so I might be missing something obvious....

任何人至少可以确认这是连接字符串应该是什么样子实体框架 - > SQL Sever Express?我一直在改变它,试图让它工作。

Can anyone at least confirm that this is what the connection string should look like for Entity Framework -> SQL Sever Express? I've been changing it around trying to get it to work.

推荐答案


  1. 检查你的Windows服务并确保sql server express Windows服务正在运行。您可以通过从RUN命令栏(Windows键+ R)运行 services.msc 获得服务。如果没有运行,那么启动它。

  2. 您是否安装了Sql Server Management Tools?如果是这样,您可以尝试使用这些工具进行连接。如果您无法连接到您的sql server express实例,很可能您无法从代码连接。如果你没有安装这个没有后顾之忧,你仍然可以用下一步测试。

  3. 如果你需要帮助建立连接字符串,下一个是一个很好的方法。在桌面上创建一个文本文件。将扩展名从 .txt 重命名为 .udl 。打开文件,您将获得一个数据链接属性屏幕,从第一个选项卡开始(它默认为选项卡2),然后填写第二个选项卡。一旦你测试你的连接,它的工作原理,你可以使用 NotePad 打开文件,或将扩展名重新命名为 .txt 并在 NotePad 中打开它。
    连接字符串将在文本文件的第二行。只需复制并粘贴到您的 .config 文件。

  1. Check your windows services and make sure that the sql server express windows service is running. You can get to services by running services.msc from the RUN command bar (windows key + R). If it is not running then start it.
  2. Do you have Sql Server Management Tools installed? If so you can try to connect using those tools. If you cant connect to your sql server express instance from there, most likely you will not be able to connect from code either. If you do not have this installed no worries, you can still test it with the next step.
  3. If you need help building the connection string this next one is a great way to do it. Create a text file on your desktop. Rename the extension from .txt to .udl. Open the file and you will get a Data Link Properties screen, start with the 1st tab (it defaults to tab 2) and then fill in the second one also. Once you test your connection here and it works you can open the file using NotePad or rename the extension back to .txt and open it in NotePad. The connection string will be on the 2nd line in the text file. Just copy and paste it to your .config file.

如果没有这个工作然后回报你发现了什么,你收到的任何错误。

If none of this works then report back with what you have found and any errors you are getting.

这篇关于无法将Entity Framework连接到本地SQL Server Express的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆