[英]Can't connect Entity Framework to local SQL Server Express
I have the connection string: 我有连接字符串:
<connectionStrings>
<add name="SolrLocal" providerName="System.Data.SqlClient" connectionString="Data Source=.\SQLExpress;Initial Catalog=SpeedOfLightRailDB;Integrated Security=true" />
</connectionStrings>
But I'm getting the error: 但是我得到了错误:
"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的连接时发生了与网络相关或特定于实例的错误。找不到服务器或无法访问该服务器。请验证实例名称正确并且已将SQL Server配置为允许远程连接。(提供者: SQL网络接口,错误:26-错误定位服务器/实例指定)
This is my first time playing with SQL Server Express so I might be missing something obvious.... 这是我第一次使用SQL Server Express,所以我可能会遗漏一些明显的东西。
Can anyone at least confirm that this is what the connection string should look like for Entity Framework -> SQL Sever Express? 至少有人能确认这是实体框架-> SQL Sever Express的连接字符串的样子吗? I've been changing it around trying to get it to work.
我一直在努力尝试使之工作。
services.msc
from the RUN command bar (windows key + R). services.msc
来获得服务。 If it is not running then start it. .txt
to .udl
. .txt
重命名为.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. NotePad
or rename the extension back to .txt
and open it in NotePad
. NotePad
打开文件,或将扩展名重命名为.txt
,然后在NotePad
打开文件。 The connection string will be on the 2nd line in the text file. .config
file. .config
文件即可。 If none of this works then report back with what you have found and any errors you are getting. 如果以上方法均无效,请报告发现的内容和遇到的任何错误。
Try this: 尝试这个:
<connectionStrings>
<add name="SolrLocal"
providerName="System.Data.SqlClient"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=SpeedOfLightRailDB;Integrated Security=True;MultipleActiveResultSets=True"/>
</connectionStrings>
Also check if .\\SQLEXPRESS
is accessible from SQL Server Management Studio, and if SQL Server is configured to allow remote connections in SQL Server Configuration Manager. 还检查是否可以从SQL Server Management Studio访问
.\\SQLEXPRESS
,以及是否将SQL Server配置为允许SQL Server Configuration Manager中的远程连接。
It can be launched from cmd like this: C:\\Windows\\SysWOW64\\mmc.exe /32 C:\\Windows\\SysWOW64\\SQLServerManager12.msc
可以像这样从cmd启动它:
C:\\Windows\\SysWOW64\\mmc.exe /32 C:\\Windows\\SysWOW64\\SQLServerManager12.msc
You are using .\\SQLExpress
and I think your local servername is different. 您正在使用
.\\SQLExpress
,我认为您的本地服务器名称不同。 What you can do is open your SQL Server and then while connecting see the server name used. 您可以做的是打开SQL Server,然后在连接时查看使用的服务器名称。 You must enter the same name in your web config.
您必须在网络配置中输入相同的名称。 Refer the below image which shows the server name while connecting to the SQL server, In my case I need to replace
.\\SQLExpress
with RAJSHEKAR-PC\\SQLEXPRESS
请参考下图,该图显示了连接到SQL Server时的服务器名称,对于我来说,我需要将
.\\SQLExpress
替换为RAJSHEKAR-PC\\SQLEXPRESS
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.