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? I've been changing it around trying to get it to work.
至少有人能确认这就是实体框架-> SQL Sever Express的连接字符串的样子吗?我一直在改变它,试图让它发挥作用。
3 个解决方案
#1
2
- 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. - 检查您的windows服务,并确保sql server express windows服务正在运行。您可以通过运行服务来访问服务。来自运行命令栏的msc (windows key + R)。如果它没有运行,请启动它。
- 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.
- 是否安装了Sql Server管理工具?如果可以,您可以尝试使用这些工具进行连接。如果您不能从那里连接到您的sql server express实例,很可能您也无法从代码中连接。如果您没有安装这个,不用担心,您仍然可以在下一步测试它。
- 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 usingNotePad
or rename the extension back to.txt
and open it inNotePad
. The connection string will be on the 2nd line in the text file. Just copy and paste it to your.config
file. - 如果您需要帮助构建连接字符串,下一个是一个很好的方法。在桌面创建一个文本文件。将扩展名从.txt重命名为.udl。打开文件,您将得到一个数据链接属性屏幕,从第一个选项卡(默认为选项卡2)开始,然后再填充第二个选项卡。一旦您在这里测试了您的连接并且它工作了,您可以使用记事本打开文件,或者将扩展名重命名为.txt并在记事本中打开它。连接字符串将位于文本文件的第二行。只需复制并粘贴到.config文件中。
If none of this works then report back with what you have found and any errors you are getting.
如果这些方法都不起作用,那么报告您发现的内容和您正在得到的任何错误。
#2
1
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
#3
0
You are using .\SQLExpress
and I think your local servername is different. What you can do is open your SQL Server and then while connecting see the server name used. 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
您正在使用。\SQLExpress和我认为您的本地服务器名不同。您可以做的是打开SQL服务器,然后在连接时查看使用的服务器名。必须在web配置中输入相同的名称。请参考下面的图片,在连接SQL服务器时显示服务器名称,在我的情况下,我需要用RAJSHEKAR-PC\ SQLExpress替换
#1
2
- 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. - 检查您的windows服务,并确保sql server express windows服务正在运行。您可以通过运行服务来访问服务。来自运行命令栏的msc (windows key + R)。如果它没有运行,请启动它。
- 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.
- 是否安装了Sql Server管理工具?如果可以,您可以尝试使用这些工具进行连接。如果您不能从那里连接到您的sql server express实例,很可能您也无法从代码中连接。如果您没有安装这个,不用担心,您仍然可以在下一步测试它。
- 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 usingNotePad
or rename the extension back to.txt
and open it inNotePad
. The connection string will be on the 2nd line in the text file. Just copy and paste it to your.config
file. - 如果您需要帮助构建连接字符串,下一个是一个很好的方法。在桌面创建一个文本文件。将扩展名从.txt重命名为.udl。打开文件,您将得到一个数据链接属性屏幕,从第一个选项卡(默认为选项卡2)开始,然后再填充第二个选项卡。一旦您在这里测试了您的连接并且它工作了,您可以使用记事本打开文件,或者将扩展名重命名为.txt并在记事本中打开它。连接字符串将位于文本文件的第二行。只需复制并粘贴到.config文件中。
If none of this works then report back with what you have found and any errors you are getting.
如果这些方法都不起作用,那么报告您发现的内容和您正在得到的任何错误。
#2
1
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
#3
0
You are using .\SQLExpress
and I think your local servername is different. What you can do is open your SQL Server and then while connecting see the server name used. 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
您正在使用。\SQLExpress和我认为您的本地服务器名不同。您可以做的是打开SQL服务器,然后在连接时查看使用的服务器名。必须在web配置中输入相同的名称。请参考下面的图片,在连接SQL服务器时显示服务器名称,在我的情况下,我需要用RAJSHEKAR-PC\ SQLExpress替换