Error 40: Could not open a connection to SQL Serve

2019-08-28 13:46发布

问题:

This question already has an answer here:

  • Provider named pipes provider error 40 could not open a connection to SQL Server error 2 [duplicate] 9 answers

I am running a windows application on my computer but, while I connect to my SQL Server database an error occurs which says

Named pipes Error 40 Could not open a connection to SQL server.

I tried several MSDN pages and links, which includes firewall setting change, SQL configuration settings, but nothing works.

Please help

回答1:

SOLVED !! Simply, Instead of using "Microsoft SQL Server (SqlClient)" as The DataSource Use ".NET Framework Data Provider for MySQL" Use your Credentials for the MySQL Connection (ServerName,User,Password,DB-Optional) It should work now.

I've used ADO Entity DATA Model Wizard for My Project and configure .Net as My DataSource. If you have the "error 40..." in different occausion verify your DataSource to the right one.

I tried like most of you to look for Firewall settings, server settings, but it was simple than i thought, so check it out...

For download --->.NET Framework Data Provider for MySQL as your data source/provider:

http://dev.mysql.com/get/Downloads/Connector-Net/mysql-connector-net-6.7.4.msi

It worked for me !



回答2:

please check the SQL Server Configuration Manager

http://msdn.microsoft.com/en-us/library/ms174212.aspx

enable the protocols, mine pipes, tcp and others. and also check the sql browser service is running



回答3:

The various causes fall into five categories:

1 Incorrect connection string, such as using SqlExpress.

2 NP was not enabled on the SQL instance.

3 Remote connection was not enabled.

4 Server not started, or point to not a real server in your connection string.

5 Other reasons such as incorrect security context.

For more visit

http://blogs.msdn.com/b/sql_protocols/archive/2007/03/31/named-pipes-provider-error-40-could-not-open-a-connection-to-sql-server.aspx



回答4:

In my case the problem was fixed after I "started" "SQL Server(SQLEXPRESS)" under

Computer Management > Services and Applications > Services



回答5:

Search for services in control panel, there you will find Services(Local) in Admin tool section.

select it that will show a window with all services in your system, find your service SQLEXPRESS (MSSQLSERVER) and click on Start.

It should start your server instance.