I found the following techniques helpful:
我发现以下技巧很有帮助:
-
Make sure your database engine is configured to accept remote connections:
- Start > All Programs > SQL Server 2005 > Configuration Tools > SQL Server Surface Area Configuration
- Click on Surface Area Configuration for Services and Connections
- Select the instance that is having a problem > Database Engine > Remote Connections
- Enable local and remote connections
- Restart instance
-
You may need to create an exception on the firewall for the SQL Server instance and port you are using:
- Start > Run > Firewall.cpl
- Click on exceptions tab
- Add sqlservr.exe (typically located in
C:\Program Files (x86)\Microsoft SQL Server\MSSQL.x\MSSQL\Bin
, check your installs for the actual folder path) and port (default is 1433
)
- Check your connection string as well
-
Check if your SQL server services is up and running properly:
- Go to All Programs > Microsoft SQL Server 2008 > Configuration Tools > SQL Server Configuration Manager > SQL Server Services
- Check to make sure SQL Server service status is Running.
In addition, ensure that your remote server is in the same network. Run sqlcmd -L
to ascertain if your server is included in your network list.
-
Enable TCP/IP in SQL Server Configuration
When two or more SQL Servers are connected across network they do all communication using TCP/IP. The default port of SQL Server installation is 1433. This port can be changed through SQL Server Configuration Manager. TCP/IP should be enabled for SQL Server to be connected.
- Go to All Programs >> Microsoft SQL Server 2008 >> Configuration Tools >> SQL Server Configuration Manager >> Select TCP/IP
- Right Click on TCP/IP >> Click on Enable
You must restart SQL Server Services for all the changes to take effect. Right click and go to menu properties to select location where default port of SQL Server can be changed.
I got Solution for me :
我有自己的解决方案:
Open "SQL Server Configuration Manager"
Now Click on "SQL Server Network Configuration" and Click on "Protocols for Name"
Right Click on "TCP/IP" (make sure it is Enabled) Click on Properties
Now Select "IP Addresses" Tab -and- Go to the last entry "IP All"
Enter "TCP Port" 1433.
Now Restart "SQL Server .Name." using "services.msc" (winKey + r)
It Will Work...
它会成功的..。
Adding my heavily upvoted comment as an answer with screenshots.
添加我的高度赞扬的评论作为带有屏幕截图的回答。
I spent a lot of time on this, finally what worked for me is:
我在这上面花了很多时间,最后对我起作用的是:
- Open Sql Server Configuration Manager --> SQL Server Network configuration --> Protocols for <(INSTANCE)> --> TCP/IP (double click on it).
Select --> IP Addresses(Tab).
Go to the last entry IP All and mention TCP Port 1433.
Press Win+R and enter services.msc.
Now restart SQL Server <(INSTANCE)>.
After this, the problem got resolved!
在这之后,问题就解决了!
I am solving that problem by opening Services then start running Sql Server (Sqlexpress) service.
我正在通过打开服务然后开始运行SQL Server(SqlExpress)服务来解决这个问题。
This Error mainly came when the SQL Service is stopped.You need to Restart the service.To go to this window you have to search the Services like this-
此错误主要发生在SQL服务停止时。您需要重新启动服务。要转到此窗口,您必须搜索服务,如下所示-
Then Search for SQLSERVER(MSSQLSERVER) and Restart the service.
然后搜索SQLSERVER(MSSQLSERVER)并重新启动服务。
Hope this will work.
希望这能奏效。
In case you're using the Express Edition:
如果您使用的是Express Edition:
You need to add \SQLEXPRESS
after your server name
您需要在服务器名称后添加\SQLEXPRESS
e.g. MY-SERVER\SQLEXPRESS
例如MY-SERVER\SQLEXPRESS
I had the same error when I wanted to run my WinForms project (that includes working with a SQL Server database and that worked perfectly on my PC) on another PC. The problem was in Windows Firewall on my PC. I solved this by adding two rules. This is the whole procedure how to allow SQL Server through Windows Firewall:
当我想要在另一台PC上运行我的WinForms项目(包括使用SQL Server数据库,它在我的PC上运行得很好)时,我也遇到了同样的错误。问题出在我电脑上的Windows防火墙中。我通过添加两条规则解决了这个问题。以下是允许SQL Server通过Windows防火墙的整个过程:
- Open "Run" and enter
services.msc
- Find the service for SQL Server (instance name) and SQL Server Browser. One at a time, right click, select "Properties", copy the path to exe file
- Then open
firewall.cpl
, click allow an application or add rule, add the previously copied path (there is a procedure you need to follow), check Domain and Private, uncheck Public.
This is the YouTube link where you can see this procedure: Allow SQL Server through Windows Firewall
这是YouTube链接,您可以在其中看到此过程:允许SQL Server通过Windows防火墙
Press window + R (Run window Open)
and in run window type "services.msc"
and new services open find SQL SERVER with instance name in my case it's SQL SERVER(SQLEXPRESS)
then start this service and try again it works for me Hope Its Works for You also.
按Window+R(运行窗口打开),在运行窗口中输入“services.msc”,打开新的服务,找到实例名为SQL SERVER的SQL SERVER,在我的例子中它是SQL SERVER(SQLEXPRESS),然后启动该服务并重试,它对我起作用,希望它也对你起作用。
I encountered the same problem
In my case, I solved the problem in this way
我遇到了同样的问题,我用这种方式解决了问题
Step 1: From start menu went to SQL server configuration manager
步骤1:从“开始”菜单转到“SQL服务器配置管理器”。
Step 2: Enabled TCP/IP
第2步:启用了TCP/IP
Step 3: Double clicked TCP/IP and went to IP Address last entry IP ALL and entered TCP Port 1433 then applied
步骤3:双击TCP/IP,转到IP地址,最后输入IP All,然后输入TCP端口1433,然后应用
Step 4 : then pressed win+r and wrote services.msc opened the Services then scrolled down then right clicked on SQL Server (MSSQLSERVER) choose restart
步骤4:然后按Win+r并编写服务。msc打开服务,然后向下滚动,然后右击SQL Server(MSSQLServer),选择重新启动
That resolved my problem.
Even if doing all of the above steps do not solve the problem then simply restart the PC then hopefully it will work.
这解决了我的问题。即使执行上述所有步骤都不能解决问题,也只需重新启动PC,希望它能正常工作。
This solution resolves both issues Network Error
& service
behind SQL server
I answered a similar question here, you need to stat the other open Run type-> services.msc
- under services -> sort by stopped
you will see a bunch of stopped SQL services Right click and start
我在这里回答了一个类似的问题,您需要统计另一个打开的运行类型->services.msc-在服务->Sort by Stoped下,您将看到一堆已停止的SQL服务,右键单击并启动
To begin - there are 4 issues that could be causing the common LocalDb SqlExpress Sql Server connectivity errors SQL Network Interfaces, error: 50 - Local Database Runtime error occurred
, before you begin you need to rename the v11 or v12 to (localdb)\mssqllocaldb
开始之前-有4个问题可能导致常见的LocalDb SqlExpress SQL Server连接错误SQL网络接口,错误:50-本地数据库运行时错误,在开始之前,您需要将v11或v12重命名为(Localdb)\mssqlLocaldb
Troubleshooting Steps
- You do not have the services running run this cmd,
net start MSSQLSERVER
or net start MSSQL$ instancename
- You do not have the firewall ports here
configured
- Your install has and issue/corrupt (the steps below help give you a nice clean start)
- You did not rename the V11 or 12 to mssqllocaldb/SqlServer
I found that the simplest is to do the below - I have attached the pics and steps for help.
我发现最简单的就是做下面的事情--我已经附上了帮助的图片和步骤。
Resolution Steps:
First verify which instance you have installed, you can do this by checking the registry and by running cmd
首先验证您安装了哪个实例,您可以通过检查注册表和运行cmd来完成此操作
cmd> Sqllocaldb.exe i
cmd> Sqllocaldb.exe s "whicheverVersionYouWantFromListBefore"
if this step fails, you can delete with option d
cmd> Sqllocaldb.exe d "someDb"
cmd> Sqllocaldb.exe c "createSomeNewDbIfyouWantDb"
cmd> Sqllocaldb.exe start "createSomeNewDbIfyouWantDb"
Restart MSSql Server
or Simply restart your machine!
重新启动MSSQL Server或简单地重新启动您的计算机!
Hold/Press to open the CMD, window + R
and Type "services.msc"
按住/按打开CMD,Window+R并键入“services.msc”
Now look for sql server services, open find SQL SERVER with instance name
then ReStart
this service and try again
现在查找SQL服务器服务,打开使用实例名称查找SQL服务器,然后重新启动此服务并重试
If none of the above solutions work (nothing worked for me) then just RESTART your computer and you will be able to connect to your sql server (localhost).
如果上述解决方案都不起作用(对我来说都不起作用),那么只需重新启动您的计算机,您就可以连接到您的SQL服务器(本地主机)。
After doing everything mentioned here:
http://blog.sqlauthority.com/2009/05/21/sql-server-fix-error-provider-named-pipes-provider-error-40-could-not-open-a-connection-to-sql-server-microsoft-sql-server-error/
Still did not work for me.
在做了这里提到的所有事情之后:http://blog.sqlauthority.com/2009/05/21/sql-server-fix-error-provider-named-pipes-provider-error-40-could-not-open-a-connection-to-sql-server-microsoft-sql-server-error/仍然不适合我。
Steps worked for me:
这些步骤对我很管用:
Start > Run > cmd > sqlcmd -L
开始>运行>命令>命令-L
It will prompt you the server name. Make sure this server name is same as the one you are trying to get connected to in CONNECT TO SERVER box of SQL management studio.
它将提示您服务器名称。请确保此服务器名称与您在SQL Management Studio的连接到服务器框中尝试连接的服务器名称相同。
I made this silly mistake I keep using MSSQLSERVER
rather using this server name.
我犯了一个愚蠢的错误,我一直使用MSSQLServer,而不是使用这个服务器名称。
Hope this helps for the people who make silly mistake like me.
希望这对像我一样犯愚蠢错误的人有所帮助。
Thanks.
谢谢。
I am using SQL Server 2016 and Window 10.
First thing is to allow remote connection to SQL Server.
What I did is to type sqlservermanager13.msc at start menu in order to open the SQL Server Configuration Manager. Make sure the TCP/IP status is enabled.
第一件事是允许远程连接到SQL Server。我所做的是在开始菜单中输入sqlserverranger13.msc,以打开SQL Server配置管理器。确保TCP/IP状态为已启用。
Check your TCP port number by double click TCP/IP protocol name. Usually it is 1433 by default.
通过双击TCP/IP协议名称检查您的TCP端口号。通常默认为1433。
The following procedures configure the Windows Firewall by using the Windows Firewall with Advanced Security Microsoft Management Console (MMC) snap-in. The Windows Firewall with Advanced Security only configures the current profile.
以下过程使用具有高级安全性的Windows防火墙Microsoft管理控制台(MMC)管理单元配置Windows防火墙。具有高级安全性的Windows防火墙仅配置当前配置文件。
To open a port in the Windows firewall for TCP access
- On the Start menu, click Run, type WF.msc, and then click OK.
- In the Windows Firewall with Advanced Security, in the left pane, right-click Inbound Rules, and then click New Rule in the action pane.
- In the Rule Type dialog box, select Port, and then click Next.
- In the Protocol and Ports dialog box, select TCP. Select Specific local ports, and then type the port number of the instance of the
Database Engine, such as 1433 for the default instance. Click Next.
- In the Action dialog box, select Allow the connection, and then click Next.
- In the Profile dialog box, select any profiles that describe the computer connection environment when you want to connect to the
Database Engine, and then click Next.
- In the Name dialog box, type a name and description for this rule, and then click Finish.
Another thing to configure.
另一件需要配置的事情。
To open access to SQL Server when using dynamic ports
- On the Start menu, click Run, type WF.msc, and then click OK.
- In the Windows Firewall with Advanced Security, in the left pane,
right-click Inbound Rules, and then click New Rule in the action
pane.
- In the Rule Type dialog box, select Program, and then click Next.
- In the Program dialog box, select This program path. Click Browse,
and navigate to the instance of SQL Server that you want to access
through the firewall, and then click Open. By default, SQL Server is
at C:\Program Files\Microsoft SQL
Server\MSSQL13.MSSQLSERVER\MSSQL\Binn\Sqlservr.exe. Click Next.
- In the Action dialog box, select Allow the connection, and then
click Next.
- In the Profile dialog box, select any profiles that describe the
computer connection environment when you want to connect to the
Database Engine, and then click Next.
- In the Name dialog box, type a name and description for this rule,
and then click Finish.
Have a look at Microsoft doucmentation
Configure a Windows Firewall for Database Engine Access
了解Microsoft如何为数据库引擎访问配置Windows防火墙
You can test the following methods.
您可以测试以下方法。
a
- Check the connection string of the project.
b
- Go to services and restart SQLServer Instance.
c
- Open 'SQLServer Configuration Manager'
- In the left panel select 'SQLServer Network Configuration' and expanding it
- Select 'Protocols for MSSQLServer'
- In the right panel dbl click on 'TCP/IP'
- In the 'Protocol' tab set the 'Enabled' to 'Yes'
- In the 'IP Addresses' tab scroll to down
- In the 'IPAll' set 'TCP Port' to 1433
- d
- Open 'Firewall with advanced security'
- In the right tab select 'Inbound Rules'
In the middle tab find the record that 'local Port' is 1433, If you can't found it try to created it with following levels
在中间的选项卡中找到“local port”为1433的记录,如果您找不到它,请尝试使用以下级别创建它
- In the Start menu, click Run, type 'WF.msc', and then click OK
- In the left panel click the 'Windows Firewall with Advanced Security'
- In the right panel right-click 'Inbound Rules', and then click 'New Rule'
- In the Rule Type dialog box, select 'Port', and then click Next
- In the Protocol and Ports dialog box, select 'TCP', and select 'Specific Local Ports', and then type the port number 1433, Click Next
- In the Action dialog box, select Allow the connection, and then click Next
- In the 'Profile' dialog box, checking the Domain, Private and Public, Then click Next
- In the 'Name' dialog box, type 'SQL 1433 Port' and for a description write description for own. Then click Finish
- Then in the middle tab double click the found item(Instance) or created item of 'SQL 1433 Port' name by you.
- Select 'Scope' tab in opened dialog box(SQL Server Properties)
- In the Local PC Go to google.com in your Browser and search 'My IP'.
- then copy of your 'IP'
- Go to the remote server and in the 'SQL Server Properties' dialog box of 'Scope' tab, in the 'Remote IP Address' select the 'These IP Addresses' option and click 'Add' button
- In the opened dialog box(IP Address) select 'This IP Address or Subnet' option and paste your 'IP', click OK button.
I have to run SQL Server Browser service into SQL Server Configuration Manager.
Installation can't discover newly created service without this.
我必须在SQL Server配置管理器中运行SQL Server Browser服务。如果没有此设置,安装将无法发现新创建的服务。
I tried all the other answers on this question and some if not all probably played a part in getting this working for me, but I still couldn't connect to the DB remotely. I was using a SQL Server on an Azure VM.
我尝试了这个问题的所有其他答案,其中一些(如果不是全部的话)可能对我的工作起到了一定的作用,但我仍然无法远程连接到数据库。我在Azure VM上使用SQL Server。
I eventually remembered that the VM has endpoints that are controlled by the Azure account proxy, so I went on to the Azure Portal and added 1433 as an available endpoint and I could connect to my SQL instance.
我最终记起,该VM具有由Azure帐户代理控制的终结点,因此我继续访问Azure门户并将1433添加为可用终结点,我可以连接到我的SQL实例。
Hope this helps someone who has tried all the other answers and is still having no luck!
希望这对那些已经尝试了所有其他答案但仍然没有成功的人有所帮助!
I was experiencing the same problem and the problem was that I hade several projects in the solution (Web
and Droid
) and even though Default project
was choosen in the Package Manager Console
it used the connection string from the Droid
project:
我遇到了同样的问题,问题是我在解决方案中有几个项目(Weband Droid),即使在包管理器控制台中选择了Default项目,它也使用了Droid项目的连接字符串:
PM> update-database -Verbose
Using StartUp project 'Droid'. <-- DROID
Using NuGet project 'Web'. <-- WEB
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
<!-- BAD TARGET DATABASE -->
Target database is: 'DefaultConnection' (DataSource: .\SQLEXPRESS, Provider: System.Data.SqlClient, Origin: Convention).
System.Data.SqlClient.SqlException (0x80131904): 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)
[REMOVED TEXT]
ClientConnectionId:00000000-0000-0000-0000-000000000000
Error Number:-1,State:0,Class:20
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)
After setting the Startup Project
to Web
and the Default Project
in Package Manger Console
I got it to work.
在将“启动项目”设置为“Web”并在“包管理器”控制台中设置为“默认项目”后,我让它正常工作。
You may check service status of MS SQL Server 2014. In Windows 7 you can do that by:
您可以查看MS SQL Server 2014的服务状态。在Windows 7中,您可以通过以下方式做到这一点:
- Go to search and Type "SQL Server 2014 Configuration Manager
- Then click on "SQL Server Service" on left menu
- Check the instance of SQL Server service status if it is stopped or running
- If it has stopped, please change the status to running and log in to SQL Server Management Studio 2014
Just restart SQL Server (MSSQLSERVER) service.
只需重新启动SQL Server(MSSQLServer)服务。
While the above solutions should work in 90% of the cases, but if you are still reading this answer!!! You are probably trying to connect to a different server than intended. It may be due to a configuration file pointing to a different SQL server than the actual server you think you are trying to connecting to.
虽然上面的解决方案在90%的情况下都应该有效,但如果你仍然在阅读这个答案!您可能正在尝试连接到不同于预期的服务器。这可能是因为配置文件指向不同的SQL服务器,而不是您认为要尝试连接的实际服务器。
Happened to me atleast.
至少发生在我身上。
My issue started when I tried to change the server from IIS Express to Local IIS (while using LocalDB).
当我试图将服务器从IIS Express更改为Local IIS(同时使用LocalDB)时,我的问题开始了。
I was using LocalDB (for dev purposes), and when I went to revert from Local IIS to IIS Express, Visual Studio had switched my data source from Data Source=(LocalDb)\MSSQLLocalDB to Data Source=.\SQLEXPRESS
我正在使用LocalDB(出于开发目的),当我从本地IIS恢复到IIS Express时,Visual Studio已将我的数据源从Data Source=(LocalDb)\MSSQLLocalDB切换为Data Source=.\SQLEXPRESS
Incorrect connection string
错误的连接字符串
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\SurveyTestsDB.mdf;Initial Catalog=SurveyTestsDB;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
Correct connection string
正确的连接字符串
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\SurveyTestsDB.mdf;Initial Catalog=SurveyTestsDB;Integrated Security=True" providerName="System.Data.SqlClient" />
Hope this helps someone out there.
希望这对外面的人有帮助。
When I experienced this error in Visual Studio,
当我在Visual Studio中遇到此错误时,
“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)”
...it was during the execution of the following C# code, which was attempting to obtain my SQL Server data to display it in a grid. The break occurred exactly on the line that says connect.Open():
...它是在执行以下C#代码时发生的,该代码试图获取我的SQL Server数据以将其显示在网格中。断开恰好发生在显示Connect.Open()的行上:
using (var connect = Connections.mySqlConnection)
{
const string query = "SELECT Name, Birthdate, Narrative FROM Friends";
using (var command = new SqlCommand(query, connect))
{
connect.Open();
using (var dr = command.ExecuteReader())
{
while (dr.Read())
{
// blah
}
}
}
}
It was inexplicable because the SQL query was very simple, I had the right connection string, and the database server was available. I decided to run the actual SQL query manually myself in SQL Management Studio and it ran just fine and yielded several records. But one thing stood out in the query results: there was some improperly encoded HTML text inside a varchar(max) type field within the Friends table (specifically, some encoded comment symbols of the sort <!--
lodged within the "Narrative" column's data). The suspect data row looked like this:
这是令人费解的,因为SQL查询非常简单,我有正确的连接字符串,并且数据库服务器可用。我决定自己在SQL Management Studio中手动运行实际的SQL查询,它运行得很好,并产生了几条记录。但是在查询结果中有一件事很突出:Friends表中的varchar(Max)类型字段中有一些不正确编码的HTML文本(具体地说,一些<!--类型的编码注释符号位于“Narrative”列的数据中)。可疑数据行如下所示:
Name Birthdate Narrative
==== ========= ==============
Fred 21-Oct-79 <!--HTML Comment -->Once upon a time...
Notice the encoded HTML symbol "<
", which stood for a "<" character. Somehow that made its way into the database and my C# code could not pick it up! It failed everytime right at the connect.Open() line! After I manually edited that one row of data in the database table Friends and put in the decoded "<" character instead, everything worked! Here's what that row should have looked like:
请注意编码的HTML符号““,它代表“<”字符。不知何故,它进入了数据库,而我的C#代码却无法拾取它!它每次都在连接处失败。打开()行!在我手动编辑数据库表Friends中的一行数据并放入解码的“<”字符之后,一切都正常!这一行应该是这样的:
Name Birthdate Narrative
==== ========= ==============
Fred 21-Oct-79 <!--HTML Comment -->Once upon a time...
I edited the one bad row I had by using this simple UPDATE statement below. But if you had several offending rows of encoded HTML, you might need a more elaborate UPDATE statement that uses the REPLACE function:
我使用下面这条简单的UPDATE语句编辑了我的一行错误。但是,如果您有几行令人不快的编码HTML,则可能需要使用REPLACE函数的更详细的UPDATE语句:
UPDATE Friends SET Narrative = '<!--HTML Comment -->Once upon a time...' WHERE Narrative LIKE '<%'
So, the moral of the story is (at least in my case), sanitize your HTML content before storing it in the database and you won't get this cryptic SQL Server error in the first place! (Uh, properly sanitizing/decoding your HTML content is the subject of another discussion worthy of a separate StackOverflow search if you need more information!)
因此,这个故事的寓意是(至少在我的例子中),在将您的HTML内容存储到数据库之前对其进行清理,这样您就不会从一开始就得到这个神秘的SQL Server错误!(如果您需要更多信息,那么适当地清理/解码您的HTML内容是另一个值得单独搜索StackOverflow的讨论的主题!)
Why this error is so boresome and noisy, just because it can occur in varied situation.
为什么这个错误如此烦人和嘈杂,只是因为它可以在不同的情况下发生。
I have done all approchs above here, and still being sucked. So make sure u have done the same as me before browsing downward.
我已经在上面做了所有的接近,但仍然被吸。所以,在向下浏览之前,请确保你已经做了和我一样的事情。
Maybe I am not able to fix ur situation instantly, but I can point out a direction or thinking to u(The one who finally slide down here). I have started to ponder the error of my running program occurring after I made sure that the instance name is clearly right and set my database to allow remote control following the methods above. After then, I suspected something wrong happening in my code snippet of SQL connection.
也许我不能马上解决你的问题,但我可以为你(最终滑到这里的那个人)指出一个方向或思考。在确保实例名称明确正确并将数据库设置为允许按照上面的方法进行远程控制之后,我已经开始考虑运行程序时出现的错误。在那之后,我怀疑我的SQL连接代码片段中发生了一些错误。
Solution of my problem:
- Check my sqlconnection function
- Click to see its configuration
It works for me with pondering what exactly happen in the process of connection.Hope my thinking will lead u to kill ur error.
这对我来说很管用,我在思考连接的过程中到底发生了什么。希望我的想法能引导你消除你的错误。
Try adding a ,
and a port number (as in ,1433
) to the end of your connection string.
尝试在连接字符串的末尾添加、和端口号(如1433)。
Summary
总结
To fix this issue encountered while running local app vs remote database, use SQL Server Configuration Manager to add an alias for the remote database.
若要解决在运行本地应用程序与远程数据库时遇到的此问题,请使用SQL Server配置管理器为远程数据库添加别名。
Details
细节
I had run into this problem recently when transitioning from a Windows 7 to a Windows 10 laptop. I was running a local development and runtime environment accessing our Dev database on a remote server. We access the Dev database through a server alias setup through SQL Server Client Network Utility (cliconfg.exe). After confirming that the alias was correctly setup in both the 64 and 32 bit versions of the utility and that the database server was accessible from the new laptop via SSMS, I still got the error seen by the OP (not the OP's IP address, of course).
最近,我在从Windows 7过渡到Windows 10笔记本电脑时遇到了这个问题。我正在运行一个本地开发和运行时环境,访问远程服务器上的开发人员数据库。我们通过通过SQL Server客户端网络实用程序(cliconfg.exe)设置的服务器别名来访问开发人员数据库。在确认在64位和32位版本的实用程序中都正确设置了别名,并且可以从新的笔记本电脑通过SSMS访问数据库服务器之后,我仍然收到了OP看到的错误(当然,不是OP的IP地址)。
It was necessary to use SQL Server Configuration Manager to add an alias for the remote Dev database server. Fixed things right up.
需要使用SQL Server配置管理器为远程开发人员数据库服务器添加别名。把事情修好了。
In my situation MSSQLSERVER service had a problem so I restarted the service and problem solved.
在我的情况下,MSSQLSERVER服务有问题,所以我重新启动了服务并解决了问题。
So I recommend to go to Services app by : Windows key, search "Services", then find your Sql instance usually "SQL Server (MSSQLSERVER)" at for Microsoft sql server.
Right click on service and click on Start, if disabled click on Restart.
因此,我建议通过以下方式进入服务应用程序:Windows键,搜索“Services”,然后找到您的SQL实例,通常是“SQL Server(MSSQLSERVER)”for Microsoft SQL Server。右键单击服务,然后单击启动,如果禁用,请单击重新启动。
I moved from a work laptop on Windows 7 to a work laptop on Windows 10.
I had been successfully using SSMS2016 on Windows 7.
我从Windows 7上的工作笔记本电脑换成了Windows 10上的工作笔记本电脑。我在Windows 7上成功地使用了SSMS2016。
The same issue was applied using SSMS2012 or SSMS2016.
My access to the 10 SQL servers using windows authentication was still the same. I could test this from another server.
However, 2 of the 10 servers would not connect from my laptop.
Both were ms SQL server 9 but I could connect to another SQL server 9 databases.
同样的问题也适用于SSMS2012或SSMS2016。我使用Windows身份验证对10台SQL服务器的访问仍然相同。我可以在另一台服务器上进行测试。然而,10台服务器中有2台无法从我的笔记本电脑连接。两者都是MS SQL SERVER 9,但我可以连接到另一个SQL SERVER 9数据库。
The solution was to add a firewall rule (using Windows Firewall with Advanced Security).
解决方案是添加防火墙规则(使用具有高级安全性的Windows防火墙)。
Create an Incoming rule for each SSMS
eg C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\ManagementStudio\Ssms.exe
为每个SSMS创建传入规则,例如C:\Program Files(X86)\Microsoft SQL Server\130\Tools\Binn\ManagementStudio\Ssms.exe
I'm not a network expert so I've not included the details but hopefully, it will point you in the right direction.
我不是网络专家,所以我没有包括细节,但希望它能为你指明正确的方向。
Error msg (pre firewall rule)
"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) (.Net SqlClient Data Provider)"
错误消息(防火墙前规则)“建立与SQL Server的连接时出现与网络相关的错误或特定于实例的错误。找不到服务器或无法访问服务器。请验证实例名称是否正确,以及是否将SQL Server配置为允许远程连接。(提供程序:SQL网络接口,错误:26-定位指定的服务器/实例时出错)(.Net SqlClient数据提供程序)”
If you're encountering this while debugging in Visual Studio, make sure that the project build path points to a local drive, or follow these steps to grant permissions to the network folder.
如果在Visual Studio中调试时遇到此问题,请确保项目生成路径指向本地驱动器,或按照以下步骤授予对网络文件夹的权限。
Along with trying everything as suggested by Teo Chuen Wei Bryan, make sure you are also referring to the correct Server/Instance name in the connection string.
除了按照Teo Chuen wei Bryan的建议尝试所有方法外,还要确保您在连接字符串中引用了正确的服务器/实例名称。
If you are using the short form of host name/Instance on the database server or in the web.config file, make sure you use the fully qualified domain name(FQDN)/Instance
如果在数据库服务器上或在web.config文件中使用主机名/实例的缩写形式,请确保使用完全限定的域名(FQDN)/实例
Also, to test connectivity from a server where SQL server client is NOT present,
此外,若要测试来自不存在SQL Server客户端的服务器的连接性,
--> create a text file and change its file extension to .udl
-->创建文本文件并将其文件扩展名更改为.udl
--> Right click the file and you can see connection tab.
-->右击文件,可以看到Connection页签。
--> Input server name and log on information to test connection to the database server.
-->输入服务器名称和登录信息,测试与数据库服务器的连接。
Hope this helps.
希望这能帮上忙。
If you suddenly encounter this error say in a production environment and nothing has changed, try the following 4 items in the order below to see if it gets fixed.
如果您突然遇到此错误(比如在生产环境中),并且没有任何变化,请按下面的顺序尝试以下4个项目,看看它是否得到修复。
- restart the sql server service.
- restart the service (say IIS) that is calling into sql server. (the problem is probably here if the time between the start of the service call to SQL server and the time you end up getting the response error is super short (about one or two second).
- restart the server sql server is on.
- restart the server the calling service is on.
更多回答
Enable TCP/IP in SQL Server Configuration was the solution for me when using SQL Server 2014 Express.
在使用SQL Server 2014 Express时,在SQL Server配置中启用TCP/IP是我的解决方案。
Today I spent a lot of time on this, finally what worked for me is: Open Sql Server Configuration Manager --> Protocols for <INSTANCE> --> TCP/IP --> IP Addresses(Tab). Go to the last entry IP All and mention TCP Port 1433. Now restart SQL Server (<INSTANCE>) using services.msc. After this, the problem got resolved!
今天我花了很多时间在这上面,最后对我起作用的是:打开SQL Server配置管理器--><实例>-->TCP/IP-->IP地址的协议(选项卡)。转到最后一个条目IP All并提到TCP端口1433。现在使用services.msc重新启动SQL Server(<实例>)。在这之后,问题就解决了!
I was also facing the particular problem on my local Sql server and solved by checking the local services of operating system and Searched for the specific Sql services and start them one by one. It worked perfect.
我还面临着我的本地SQL服务器上的特定问题,并通过检查操作系统的本地服务和搜索特定的SQL服务并逐一启动它们来解决。一切都很完美。
I too had the same problem, logged on to sql server found that mssqlserer service was stopped, started it. Was able to connect to the instance now
我也遇到了同样的问题,登录到SQL SERVER发现mssqlserer服务停止,于是启动了它。现在能够连接到该实例
Also REMEMBER to ENABLE SQL Server Browser
service. Have setup a number of SQL servers in my time... Yet this step always seems to have different scenarios involved :)
还要记住启用SQL Server Browser服务。在我的时间里安装了许多SQL服务器...然而,这一步似乎总是涉及不同的场景:)
In SQL Server 2014 use (localdb)\mssqllocaldb instead of (localdb)\v11.0
在SQL Server 2014中,使用(Localdb)\mssqlLocaldb而不是(Localdb)\v11.0
Copy pasted my comment (which was posted on 24th Feb 2015 - 7 months before your post) as an answer without giving me credits! :P
Copy粘贴了我的评论(发布于2015年2月24日-您的帖子前7个月)作为回复,没有给我信用!:p
This worked. I was not able to connect to SQL Server 2016. Made these changes and it worked ! Thanks.
这招奏效了。我无法连接到SQL Server 2016。做出了这些改变,而且奏效了!谢谢。
it works for me. just had to start the services in "service.msc" after enabling TCP/IP and Named Pipes in configuration manager.
这对我很管用。在配置管理器中启用了TCP/IP和命名管道后,只需启动“service.msc”中的服务。
worked like magic! I'm using SQL Server 2017 btw.. but still worked
像变魔术一样工作!我使用的是SQL Server 2017 btw。但仍在工作
Worked for me, SQL Express 2012
适用于我,SQL Express 2012
Worked for me in sql server 2012 after enable TCP, Added Port number 1433 to TCP ALL, and restart the service!
我在SQL SERVER 2012中启用了tcp后,将端口号1433添加到tcp all中,并重新启动服务!
For me additionally I had to allow TCP 1433 and UDP 1434 in the Firewall
对于我来说,我还必须允许在防火墙中使用TCP 1433和UDP 1434
yes, setting port number 1433 did it, seems like by default that's just empty
是的,设置端口号1433就是这样做的,默认情况下似乎是空的
I have seen where SQL Server windows service was set to Manual Startup Type, so it did not restart on a reboot. It should be set to Automatic.
我已经看到了将SQL Server Windows服务设置为手动启动类型的位置,因此它不会在重新启动时重新启动。应将其设置为自动。
This is exactly what i did, My Status was Running and StartupType was Automatic , but still i faced the issue , so i used services from Run window type services.msc
then i right clicked SQL Server (SQL EXPRESS) for context menu and just Stop and Start the service again and works fine for me, hope helps.
这就是我所做的,我的状态是Running,StartupType是自动的,但我仍然面临这个问题,所以我使用了Run窗口类型的服务。msc然后我右击SQL Server(SQL Express)的上下文菜单,然后只是停止并再次启动服务,对我来说工作得很好,希望能帮上忙。
I had a problem where I was using \\ instead of \ . For some reason, one of my applications worked, and another one didn't. even though the 2nd one was a stripped down copy of 1st one.
我在使用\\而不是\时遇到了问题。由于某种原因,我的一个应用程序工作了,而另一个应用程序没有。尽管第二个应用程序是第一个应用程序的精简版。
Works perfectly for me. Important: Add browser and server in the firewall! +1
对我来说很合适。重要提示:在防火墙中添加浏览器和服务器!+1
I was having a hard time locating the sqlservr.exe file, this did the trick in locating it.
我很难找到sqlservr.exe文件,这很好地定位了它。
The answer was provided previously. Dont get any reason post it again
答案已经在前面提供了。不要找任何理由再发一次
buddy am facing same problem but i do not know hot open services window then i found a way and i thought share with people
巴迪也面临着同样的问题,但我不知道如何打开服务窗口,于是我找到了一种方法,我想和人们分享
Now another person @Debendra copied from your answer and got more votes than you.
现在,另一个人@Debendra抄袭了你的答案,获得了比你更多的选票。
what can I say on that.
关于这一点我能说什么呢。
This is the same answer as @ani627 above, answered about 4 years before on July 28 2016. And upvoted for just copying.
这与上面的@ani627的答案相同,大约4年前的2016年7月28日回答了这个问题。并因只是抄袭而获得好评。
I faced the same problem more than a year ago and solved it in this way thus, I shared this.
我在一年多前就面对过同样的问题,并以这种方式解决了它,因此,我分享了这一点。
The reason why this will work, it´s because you just installed Sql Server and has not restarted the computer as the installation told you to. So, do it and then the services will be created and all the necessary configuration that is missing.
之所以可以这样做,S是因为您刚刚安装了SQL Server,并且没有按照安装程序告诉您的那样重新启动计算机。因此,执行此操作后,服务将被创建,而所有必要的配置将丢失。
Why is everyone here assuming it's a local database????
为什么这里的每个人都认为这是一个本地数据库?
On my PC Windows 10 the sql server instance is at C:\Program Files\Microsoft SQL Server\MSSQL13.SQLEXPRESS\MSSQL\Binn\Sqlservr.exe
在我的PC Windows10上,SQL服务器实例位于C:\Program Files\MicrosoftSQL Server\MSSQL13.SQLEXPRESS\MSSQL\Binn\Sqlservr.exe
There are many ways to block SQL Server from being accessed. The SQL Browser should get around it but turning it off and then checking what is listed above, narrows down the issue to login permission, TCP Port access through the firewall and that assumes remote connections are allowed. Remote connections are default so the two main issues are the Port access (like 192.168.1.2,60122) where the port for the instance is 60122, and the firewall rule. Thanks Fred.
有许多方法可以阻止访问SQL Server。SQL浏览器应该绕过它,但关闭它,然后检查上面列出的内容,将问题缩小到登录权限、通过防火墙的TCP端口访问,并假设允许远程连接。远程连接是默认的,因此两个主要问题是端口访问(如192.168.1.2,60122),其中实例的端口是60122,以及防火墙规则。谢谢,弗雷德。
Im not there yet but i'm getting closer. In Visual studio after doing this also disconnect and reconnect, getting the same error still but now at least from behind VS2015 i can no create tables, and databases i create seam to run now. (ea ,no dark cross icon over them)
我还没到那一步,但我越来越近了。在Visual Studio中,这样做之后也会断开连接并重新连接,仍然收到相同的错误,但现在至少从VS2015后面我不能创建表,而我创建的Seam数据库现在可以运行。(EA,上面没有黑色十字图标)
note after your command, this resulted in server name on a local machine Start > Run > cmd > sqlcmd -L
注意:在您的命令之后,这将导致本地计算机上的服务器名开始>运行>命令>SQLcmd-L
More than 4 people have given this same answer, and some even with screenshots before your answer.
超过4个人给出了同样的答案,有些人甚至在你的答案之前附上了截图。
Happened to me as well. Should have checked that before checking trying to diagnose the firewall. I had the right connection string, but I was running the the wrong project in the solution...
也发生在我身上。在尝试诊断防火墙之前,应该检查过这一点。我有正确的连接字符串,但我在解决方案中运行了错误的项目...
Also do not make the silly mistake of using / instead of \ in the connection string.
另外,不要犯在连接字符串中使用/而不是\的愚蠢错误。
This is great and very helpful.
这很好,非常有帮助。
This helped me find that I needed to REMOVE the port number for a LocalDB connection string, when using Entity Framework.
这帮助我发现,在使用实体框架时,我需要删除LocalDB连接字符串的端口号。
More than 3 people have given this same answer, and some even with screenshots before your answer.
超过3个人给出了同样的答案,有些人甚至在你的答案之前附上了截图。
Also your last statement "if disabled click on Restart" is incorrect. If it is disabled you can't restart. You need to change the disabled status to Manual
or Automatic
, and then "Start" the service.
另外,您的最后一句话“如果禁用,请单击重新启动”是不正确的。如果它被禁用,您将无法重新启动。您需要将禁用状态更改为手动或自动,然后“启动”该服务。
我是一名优秀的程序员,十分优秀!