IIS 7 can't connect to SQLServer 2008 - sql-server

Sorry if this is the most seen question on the web, but this is my turn. I am trying to publish my asp.net mvc app on IIS 7 under MS Sql Server 2008. I am on a Windows Server 2008 virtual machine. I get the following classical 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)
Under SQLServer, Allow remote connections is checked. My connection string is:
Data Source=.\MSSQLSERVER;Initial Catalog=mydbname;User Id=sa;Password=mypassword
I also tried with no username/password and "Integrated Security=true". There is only one instance of SQLServer installed.
I tried to access my web page locally and remotely. There is no active firewall on the virtual machine.

Make sure you have TCP/IP set up as a transport in your SQL Server configuration tool.

Thanks guys for the try. I found the solution and it is related to an info that I forgot to give. I hope it can help someone as new as me on these things.
I use NHibernate, and the connection string is actually in the nhibernate.cfg.xml file. The one in the web.config file is actually used by my various providers (users/roles). I fixed that by removing the connection string from the NH config file. I now retrieve it with:
string connectionString = ConfigurationManager.
ConnectionStrings["myConnectString"].ConnectionString;
and I set it in NH with:
Configuration cfg = new Configuration();
cfg.Configure(cfgFile);
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionString, connectionString);
Now I get:
Cannot open database "mydb"
requested by the login. The login
failed. Login failed for user 'NT
AUTHORITY\NETWORK SERVICE'.
But this is another story, for another question if I can't find the answer.
PS: I had to use "." as the server name otherwise .\MSSQLSERVER was producing a new error "invalid connection string". Thx Ian and Jared for the tip.

is that the actual data source line from the web config?
If so then it's should be in quotes of course, for safety add a ; on the end and check that is the actual name of your instance, you can check windows services for your instance name.
try substituting localhost instead of . and can you connect from sql server management studio using the credentials in your connection string?

As mentioned by Robert, try:
ConnectionString="Data Source=(LOCAL)\MSSQLSERVER;Initial Catalog=mydbname;User ID=sa;Password=mypassword"
I'm not sure if connection strings are case sensitve, but I notice that you have 'Id' instead of 'ID'.
Edit:
Am not sure if you need \MSSQLSERVER?

are you sure it's a named instance of SQL?
try
Data Source=.;Initial Catalog=mydbname;User Id=sa;Password=mypassword
UPDATE:
from this site
did you try the following:
Make sure the server machine is reachable, e.g, DNS can be resolve correctly, you are able to ping the server (not always true).
Make sure SQL Browser service is running on the server.
If firewall is enabled on the server, you need to put sqlbrowser.exe and/or UDP port 1434 into exception.

Well I am facing the same above issue since morning (past 8 hours) did lots of stuff like create a Domain Name, setup a new application pool identity but nothing worked :(
I just made a small changes in web.config file for connection string that is:
Integrated Security=False instead of True... and now it is working perfectly

Related

SQL Server connection string windows 7 and windows 10 - Named Pipes Provider, error 40 [duplicate]

I can't seem to connect to my database from a site. I get this error:
Named Pipes Provider, error: 40 - Could not open a connection to SQL Server
I tried using the local IP address to connect as well as a public one. I've tried:
Yes, the site can communicate with the server
Named pipes/TCP is enabled.
Remote connections are allowed.
Windows Firewall is off
Created an exception for port 1433 in Windows Firewall.
Enabled everything in SQL Server Configuration Manager.
What else can I do here?
Solving this problem is very easy:
Go to control panel.
search for services.
Open Local services window from your search results
Restart your MSSQLSERVER service.
Screenshot of the steps:
And the simplest solution - check if your slash is back...
I spent about an hour trying to figure out what's wrong with SERVER/INSTANCENAME when everything is configured correctly, named pipes, user access rights... and suddenly it struck me, it's not a slash, it's a backslash (\).
The horror, the shame...
It's a three step process really after installing SQL Server:
Enable Named Pipes
SQL Config Manager --> SQL Server Network Consif --> Protocols --> Named Pipes --> Right-click --> Restart
Restart the server
SQL Config Manager --> SQL Server Services --> SQL Server (SQLEXPRESS) --> Right-click --> Restart
Use proper server and instance names (both are needed!)
Typically this would be .\SQLEXPRESS, for example see the screenshot from QueryExpress connection dialog.
There you have it.
I had just installed SQL SERVER 2012 developer. When I was creating my first SSIS package, I received this pipes error when I was trying to create a data connection task in SQL Server 2012 Data Tools in the Connection Manager box. I resolved with the help of the post above.
If choose a named instance and you call your named instance SSQDatabase1 and your pc's name is PCX1. You must enter PCX1\SSQDatabase1 not just SSQDatabase1
or you will receive the named pipes error.
A thread on MSDN Social, Re: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server, has a pretty decent list of possible issues that are related to your error. You may want to see if any of them could be what you're experiencing.
Incorrect connection string, such as using SqlExpress
Named Pipes(NP) was not enabled on the SQL instance
Remote connection was not enabled
Server not started, or point to not a real server in your connection string
Other reasons such as incorrect security context
try basic connectivity tests between the two machines you are working on
i Just enabled TCP/IP,VIA,Named Pipes in Sql Server Configuration manager , My problem got solved refer this for more info Resolving Named Pipes Error 40
Use SERVER\\ INSTANCE NAME .Using double backslash in my project solved my problem.
Thanks to Damian...
TCP/IP
Named Pipes
... both enabled
Web Config....(for localhost)
<add name="FooData" connectionString="Data Source=localhost\InstanceName;Initial Catalog=DatabaseName;Integrated Security=True;" providerName="System.Data.SqlClient" />
Did have the same problem. Spent like 6 hours when had to migrate some servers.
Tried all suggestions available on this topic and others.
Solution was as simple as server restart!
Very simple solution
use (local)\InstanceName
that's it. it worked for me.
TL;DR; Your SQL Server instance is using dynamic ports which is not working. Force SQL Server to use static port # 1433.
Complete Details: First of all this problem is more likely if you've a mix of default and named instance or named instances only(which was my case).
Key concept: Each instance of Microsoft SQL Server installed on a computer uses a different port to listen for incoming connection requests. Default instance of SQL Server uses port # 1433. As you install named instances then they will start using dynamic ports which is decided at the time of start-up of Windows service corresponding to named SQL Server instance.
My code was failing (with error code 40) to connect to the only named SQL Server instance that I had on my VM. You can try below possible solutions:
Solution # 1: Client code trying to connect to SQL Server instance takes help from SQL Server browser service to figure out port number at which your named instance is listening for incoming connections. Make sure SQL browser service is running on your computer.
Solution # 2: Check the port # (in yellow color) your named SQL Server instance is using from SQL Server configuration manager as shown in the snapshot below:
Use that port number explicitly in your connection string or with sqlcmd shown below:
sqlcmd -s mymachinename,11380 -i deleteDB.sql -o SQLDelete.txt
Solution # 3: Force your named instance to use port # 1433 which is used by default instance. Remember this will work only if you don't have any default SQL Server instance on your computer as the default SQL Server instance would be using using port # 1433 already. Same port number can't be uses by two different Windows services.
Mark TCP Dynamic ports field to blank and TCP Port field to 1433.
Change the port number in your connection string as shown below:
sqlcmd -s mymachinename\instanceName -i deleteDB.sql -o SQLDelete.txt
OR
sqlcmd -s mymachinename,1433 -i deleteDB.sql -o SQLDelete.txt
Note: Every change in TCP/IP settings requires corresponding Windows service restart.
Interestingly enough after resolving the error when I went back to dynamic port setting to reproduce the same error then it didn't happen. Not sure why.
Please read below interesting threads to know more about dynamic ports of SQL Server:
How to configure SQL Server Port on multiple instances?
When is a Dynamic Port “dynamic”?
When to use a TCP dynamic port and when TCP Port?
I got leads to solution of my problem from this blog.
in my case, i had a standalone server, i changed the sql server port default port 1433 in configuration manager to some number and restarted the sql serve service to take effect,i was able to connect to the sql server through management studio if i login to the server. but i was not able to connect from my local machine through sql server, i was 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 5)
I checked and verified all the below
-Named pipes/TCP is enabled.
-Remote connections are allowed.
-Windows Firewall is off
-Created an exception for portin Windows Firewall( this was not necessary in my case as the server is in same subnet network).
-Enabled everything in SQL Server Configuration Manager.
then i chnaged back the port number to default 1433 and restarted the sql server service, and the issue got resolved and i am able to connect the sql server from my local management studio.
I had the same problem. I use the MSSQL Server Management Studio 2017 and solved this problem using these steps:
Check for working fine SQL Server Services services or not.
Also check for working in good condition SQL Server (MSSQLSERVER).
Also check for working fine SQL Server Browser.
Restart SQL Server (MSSQLSERVER)
and fixed it.
You will find most likely your DB name is not correct, you will see the server name in VS like "DESKTOP-0I14BKI" but if you open up SSMS you will see DESKTOP-0I14BKI\SQLBLAHBLAH , simply add "\SQLBLAHBLAH" (instance name) to your "server name" in VS connection properties.
You will see:
To Fix:
Try the following steps:
Open Services window (open "run box" and type services.msc).
Looking for SQL services (with SQL prefix).
Start them (if cannot start. Goto step 4).
Right_click to each service -> Properties -> Change to tab "Log on"-> choise log on as "Local ..." -> 0K. Then start SQL services again.
Try Open SQL and connect database.
In my case,
I opened SQL Server Management Studio and searched for SQLEXPRESS in my Database engine.
It had two instances and I selected the correct one.
If you are working with Asp.net core and using appsettings.json than write server as localhost and after write sql instance name for enabled named pipe like this
"ConnectionString": {
"dewDB": "server=localhost\\dewelopersql;database=dewdb;User ID=sa;password=XXXXX",
},
After following all the steps mentioned here, if it still does not connect, try adding the DNS with the IP address in the hosts file in the etc folder. Adding an IP address instead of DNS name in the connection string should be a temporary solution to check if the connection actually works.
I tried using the local IP address to connect as well as a public one.
I've tried:
Yes, the site can communicate with the server Named pipes/TCP is
enabled. Remote connections are allowed. Windows Firewall is off
Created an exception for port 1433 in Windows Firewall. Enabled
everything in SQL Server Configuration Manager.
i ensured and did the above as well and I just want to share that the DOUBLE BACKSLASH
oBuilder.DataSource = "SPECIFICPCNAME\SQLEXPRESS";
Using a SINGLE BACKSLASH resulted into a build error i.e.: Error 1 Unrecognized escape sequence
I hope this helps the next guy - I've sacrificed dinner, midnight snack and NBA highlights time solving this (shame)
Thanks to [Tamizh venthan]
^_^
Enable TCP/Ip , Piped Protocol by going to Computer Management ->SQL and Services, ensure the Service is On. Enbale the port on the Firewall. Try to login through Command Prompt -> as Admin; last the User Name
should be (local)\SQLEXPRESS. Hope this helps.
Open SQL Server Configuration Manager
Select SQL Server Services from right.
Find your server from right and go to its properties (with right click)
Change log on method to Local System.
I had the same problem and solved the problem by disabling my firewall(ESET).
The first step to solve this problem should be to try pinging your own computer from another computer. If you have firewall on, you may not be able to ping yourself. I tried pinging my own pc, then ping was failed(didnt get response from the server)
I was trying to add a new connection in VS2015. None of the suggestions here worked. Suspecting some sort of a bug in the wizard, especially since SSMS was able to connect just fine, I decided to try and trick it. It worked!
Instead of adding the connection, use "Create new SQL Server Database". Enter your server name and a random name for the new DB, e.g. "test".
Assuming this succeeds, open Server Explorer in VS, locate the connection in Data Connections, right-click it and select Modify Connection.
Change "test" (from step 1) to the name of the existing database you want to connect to. Click "Test Connection". This time it should work!
Delete the temporary database you created in step 1.
I have one more solution, I think.
I recently had changed my computer name so, after I couldn't connect still after trying all above methods.
I changed the Server name..
Server name => (browse for more) => under database engine, a new server was found same as computers new name.
This worked, and life is good again.
I struggled for ages on this one before I realized my error - I had used commas instead of semicolons in the connect string
I had this issue but none of the suggestions above fixed it.
I was seeing this issue when I deployed my website to IIS. The fix was to go into advanced settings against the default app pool and change the identity property from the default to Administrator.
For me it was a Firewall issue.
First you have to add the port (such as 1444 and maybe 1434) but also
C:\Program Files (x86)\Microsoft SQL Server\90\Shared\sqlbrowser.exe
and
%ProgramFiles%\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\Binn\SQLAGENT.EXE
The second time I got this issue is when I came back to the firewall, the paths were not correct and I needed to update form 12 to 13! Simply clicking on browse in the Programs and Services tab helped to realise this.
Finally, try running the command
EXEC xp_readerrorlog 0,1,"could not register the Service Principal Name",Null
For me, it returned the error reason
I tried pretty much everything on this page but I had some underlying issues which were actually what needed to be resolved. I was unable to do certain things like open SQL Server Configuration Manager, which ended up being corrupt/missing WMI provider files.
There are lots of tedious ways to resolve this issues according to what I've read, but the tool from tweaking.com was able to remove and replace/repair my WMI (Windows Management Instrumentation) Provider files.
I used to do computer repair and overall the tweaking.com tool really impressed me, and it was suggested from one of the WMI error forum pages I went to.
After I fixed this issue I was able to connect to my SQL db, both locally and remotely.
Hope this helps someone.
open port number 1433 on your server for sql remote connection
If you tried restarting the MSSQLSERVER service, and it did not work, this might be a solution:
If you are using SQLExpress, your server name should be as the following ComputerName\SQLExpress. However, for SQLDeveloper, you do not have to right SQLDeveloper after your ComputerName.

Issue with website deployed to IIS and connecting to SQL Server 2012, getting network not found error

I have deployed a website to IIS and it is trying to access the database via the connection string.
My SQL Server and connection string is correct as I have tested it in the following ways:
My development environment streams data correctly
Connection to SQL Server is good as I could see from SQL Server Management Studio
Other pages of the website that are deployed are correct and only those pages that stream data is failing.
The problem is that it is only through the IIS website we have this error and when I run it from Visual Studio it is all right.
Here is the stack code I get:
Stack trace error
My connection string:
<add name="cnnSQLDB"
connectionString="server=**********;database=*********;Integrated Security=True;User ID=******;Password=******;"
providerName="System.Data.SqlClient"/>
Make sure that port 1433 is open on your firewall. That is the port SQL Server uses.
I was able to solve this issue based on hints provided here. I had to do the following changes:
Update the SQL connection string and set "Integrated security=false". In that way it will use the login credentials provided in the SQL connection string.
Create a new user as provided in the SQL connection string and GRANT the necessary accesses.
When I copied the databases from the production environment to a new environment the GRANT permissions for the user mentioned in the connection string was not updated.
But by checking the port status via the command 'sp_readerrorlog' gave me clues and led me to a solution. Some other links that helped me were: this and this

ASP.NET MVC & SQL Server [duplicate]

I can't seem to connect to my database from a site. I get this error:
Named Pipes Provider, error: 40 - Could not open a connection to SQL Server
I tried using the local IP address to connect as well as a public one. I've tried:
Yes, the site can communicate with the server
Named pipes/TCP is enabled.
Remote connections are allowed.
Windows Firewall is off
Created an exception for port 1433 in Windows Firewall.
Enabled everything in SQL Server Configuration Manager.
What else can I do here?
Solving this problem is very easy:
Go to control panel.
search for services.
Open Local services window from your search results
Restart your MSSQLSERVER service.
Screenshot of the steps:
And the simplest solution - check if your slash is back...
I spent about an hour trying to figure out what's wrong with SERVER/INSTANCENAME when everything is configured correctly, named pipes, user access rights... and suddenly it struck me, it's not a slash, it's a backslash (\).
The horror, the shame...
It's a three step process really after installing SQL Server:
Enable Named Pipes
SQL Config Manager --> SQL Server Network Consif --> Protocols --> Named Pipes --> Right-click --> Restart
Restart the server
SQL Config Manager --> SQL Server Services --> SQL Server (SQLEXPRESS) --> Right-click --> Restart
Use proper server and instance names (both are needed!)
Typically this would be .\SQLEXPRESS, for example see the screenshot from QueryExpress connection dialog.
There you have it.
I had just installed SQL SERVER 2012 developer. When I was creating my first SSIS package, I received this pipes error when I was trying to create a data connection task in SQL Server 2012 Data Tools in the Connection Manager box. I resolved with the help of the post above.
If choose a named instance and you call your named instance SSQDatabase1 and your pc's name is PCX1. You must enter PCX1\SSQDatabase1 not just SSQDatabase1
or you will receive the named pipes error.
A thread on MSDN Social, Re: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server, has a pretty decent list of possible issues that are related to your error. You may want to see if any of them could be what you're experiencing.
Incorrect connection string, such as using SqlExpress
Named Pipes(NP) was not enabled on the SQL instance
Remote connection was not enabled
Server not started, or point to not a real server in your connection string
Other reasons such as incorrect security context
try basic connectivity tests between the two machines you are working on
i Just enabled TCP/IP,VIA,Named Pipes in Sql Server Configuration manager , My problem got solved refer this for more info Resolving Named Pipes Error 40
Use SERVER\\ INSTANCE NAME .Using double backslash in my project solved my problem.
Thanks to Damian...
TCP/IP
Named Pipes
... both enabled
Web Config....(for localhost)
<add name="FooData" connectionString="Data Source=localhost\InstanceName;Initial Catalog=DatabaseName;Integrated Security=True;" providerName="System.Data.SqlClient" />
Did have the same problem. Spent like 6 hours when had to migrate some servers.
Tried all suggestions available on this topic and others.
Solution was as simple as server restart!
Very simple solution
use (local)\InstanceName
that's it. it worked for me.
TL;DR; Your SQL Server instance is using dynamic ports which is not working. Force SQL Server to use static port # 1433.
Complete Details: First of all this problem is more likely if you've a mix of default and named instance or named instances only(which was my case).
Key concept: Each instance of Microsoft SQL Server installed on a computer uses a different port to listen for incoming connection requests. Default instance of SQL Server uses port # 1433. As you install named instances then they will start using dynamic ports which is decided at the time of start-up of Windows service corresponding to named SQL Server instance.
My code was failing (with error code 40) to connect to the only named SQL Server instance that I had on my VM. You can try below possible solutions:
Solution # 1: Client code trying to connect to SQL Server instance takes help from SQL Server browser service to figure out port number at which your named instance is listening for incoming connections. Make sure SQL browser service is running on your computer.
Solution # 2: Check the port # (in yellow color) your named SQL Server instance is using from SQL Server configuration manager as shown in the snapshot below:
Use that port number explicitly in your connection string or with sqlcmd shown below:
sqlcmd -s mymachinename,11380 -i deleteDB.sql -o SQLDelete.txt
Solution # 3: Force your named instance to use port # 1433 which is used by default instance. Remember this will work only if you don't have any default SQL Server instance on your computer as the default SQL Server instance would be using using port # 1433 already. Same port number can't be uses by two different Windows services.
Mark TCP Dynamic ports field to blank and TCP Port field to 1433.
Change the port number in your connection string as shown below:
sqlcmd -s mymachinename\instanceName -i deleteDB.sql -o SQLDelete.txt
OR
sqlcmd -s mymachinename,1433 -i deleteDB.sql -o SQLDelete.txt
Note: Every change in TCP/IP settings requires corresponding Windows service restart.
Interestingly enough after resolving the error when I went back to dynamic port setting to reproduce the same error then it didn't happen. Not sure why.
Please read below interesting threads to know more about dynamic ports of SQL Server:
How to configure SQL Server Port on multiple instances?
When is a Dynamic Port “dynamic”?
When to use a TCP dynamic port and when TCP Port?
I got leads to solution of my problem from this blog.
in my case, i had a standalone server, i changed the sql server port default port 1433 in configuration manager to some number and restarted the sql serve service to take effect,i was able to connect to the sql server through management studio if i login to the server. but i was not able to connect from my local machine through sql server, i was 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 5)
I checked and verified all the below
-Named pipes/TCP is enabled.
-Remote connections are allowed.
-Windows Firewall is off
-Created an exception for portin Windows Firewall( this was not necessary in my case as the server is in same subnet network).
-Enabled everything in SQL Server Configuration Manager.
then i chnaged back the port number to default 1433 and restarted the sql server service, and the issue got resolved and i am able to connect the sql server from my local management studio.
I had the same problem. I use the MSSQL Server Management Studio 2017 and solved this problem using these steps:
Check for working fine SQL Server Services services or not.
Also check for working in good condition SQL Server (MSSQLSERVER).
Also check for working fine SQL Server Browser.
Restart SQL Server (MSSQLSERVER)
and fixed it.
You will find most likely your DB name is not correct, you will see the server name in VS like "DESKTOP-0I14BKI" but if you open up SSMS you will see DESKTOP-0I14BKI\SQLBLAHBLAH , simply add "\SQLBLAHBLAH" (instance name) to your "server name" in VS connection properties.
You will see:
To Fix:
Try the following steps:
Open Services window (open "run box" and type services.msc).
Looking for SQL services (with SQL prefix).
Start them (if cannot start. Goto step 4).
Right_click to each service -> Properties -> Change to tab "Log on"-> choise log on as "Local ..." -> 0K. Then start SQL services again.
Try Open SQL and connect database.
In my case,
I opened SQL Server Management Studio and searched for SQLEXPRESS in my Database engine.
It had two instances and I selected the correct one.
If you are working with Asp.net core and using appsettings.json than write server as localhost and after write sql instance name for enabled named pipe like this
"ConnectionString": {
"dewDB": "server=localhost\\dewelopersql;database=dewdb;User ID=sa;password=XXXXX",
},
After following all the steps mentioned here, if it still does not connect, try adding the DNS with the IP address in the hosts file in the etc folder. Adding an IP address instead of DNS name in the connection string should be a temporary solution to check if the connection actually works.
I tried using the local IP address to connect as well as a public one.
I've tried:
Yes, the site can communicate with the server Named pipes/TCP is
enabled. Remote connections are allowed. Windows Firewall is off
Created an exception for port 1433 in Windows Firewall. Enabled
everything in SQL Server Configuration Manager.
i ensured and did the above as well and I just want to share that the DOUBLE BACKSLASH
oBuilder.DataSource = "SPECIFICPCNAME\SQLEXPRESS";
Using a SINGLE BACKSLASH resulted into a build error i.e.: Error 1 Unrecognized escape sequence
I hope this helps the next guy - I've sacrificed dinner, midnight snack and NBA highlights time solving this (shame)
Thanks to [Tamizh venthan]
^_^
Enable TCP/Ip , Piped Protocol by going to Computer Management ->SQL and Services, ensure the Service is On. Enbale the port on the Firewall. Try to login through Command Prompt -> as Admin; last the User Name
should be (local)\SQLEXPRESS. Hope this helps.
Open SQL Server Configuration Manager
Select SQL Server Services from right.
Find your server from right and go to its properties (with right click)
Change log on method to Local System.
I had the same problem and solved the problem by disabling my firewall(ESET).
The first step to solve this problem should be to try pinging your own computer from another computer. If you have firewall on, you may not be able to ping yourself. I tried pinging my own pc, then ping was failed(didnt get response from the server)
I was trying to add a new connection in VS2015. None of the suggestions here worked. Suspecting some sort of a bug in the wizard, especially since SSMS was able to connect just fine, I decided to try and trick it. It worked!
Instead of adding the connection, use "Create new SQL Server Database". Enter your server name and a random name for the new DB, e.g. "test".
Assuming this succeeds, open Server Explorer in VS, locate the connection in Data Connections, right-click it and select Modify Connection.
Change "test" (from step 1) to the name of the existing database you want to connect to. Click "Test Connection". This time it should work!
Delete the temporary database you created in step 1.
I have one more solution, I think.
I recently had changed my computer name so, after I couldn't connect still after trying all above methods.
I changed the Server name..
Server name => (browse for more) => under database engine, a new server was found same as computers new name.
This worked, and life is good again.
I struggled for ages on this one before I realized my error - I had used commas instead of semicolons in the connect string
I had this issue but none of the suggestions above fixed it.
I was seeing this issue when I deployed my website to IIS. The fix was to go into advanced settings against the default app pool and change the identity property from the default to Administrator.
For me it was a Firewall issue.
First you have to add the port (such as 1444 and maybe 1434) but also
C:\Program Files (x86)\Microsoft SQL Server\90\Shared\sqlbrowser.exe
and
%ProgramFiles%\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\Binn\SQLAGENT.EXE
The second time I got this issue is when I came back to the firewall, the paths were not correct and I needed to update form 12 to 13! Simply clicking on browse in the Programs and Services tab helped to realise this.
Finally, try running the command
EXEC xp_readerrorlog 0,1,"could not register the Service Principal Name",Null
For me, it returned the error reason
I tried pretty much everything on this page but I had some underlying issues which were actually what needed to be resolved. I was unable to do certain things like open SQL Server Configuration Manager, which ended up being corrupt/missing WMI provider files.
There are lots of tedious ways to resolve this issues according to what I've read, but the tool from tweaking.com was able to remove and replace/repair my WMI (Windows Management Instrumentation) Provider files.
I used to do computer repair and overall the tweaking.com tool really impressed me, and it was suggested from one of the WMI error forum pages I went to.
After I fixed this issue I was able to connect to my SQL db, both locally and remotely.
Hope this helps someone.
open port number 1433 on your server for sql remote connection
If you tried restarting the MSSQLSERVER service, and it did not work, this might be a solution:
If you are using SQLExpress, your server name should be as the following ComputerName\SQLExpress. However, for SQLDeveloper, you do not have to right SQLDeveloper after your ComputerName.

Error while trying to connect to SQL Server - localhost

I have checked the instance name, auto close is set to true, allow remote connections on the server is checked. The server is running when I open the SQL Server configuration manager. I have even rebooted. I have created this db the same way as all others. I use Entity Framework and have checked the names in the web.config and they match. This is the default connection string from the wizard - I use for testing before I deploy. I just can't think of anything else to check to figure out why it won't connect. Working inside SQL Server everything is fine.
Here is the general 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: Shared >Memory Provider, error: 40 - Could not open a connection to SQL Server)
Config:
connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string='data source=.\SQL_1;attachdbfilename="C:\Program Files (x86)\Microsoft SQL Server\MSSQL10_50.SQL_1\MSSQL\DATA\A_db.mdf";integrated security=True;connect timeout=10;user instance=True;multipleactiveresultsets=True;App=EntityFramework'" providerName="System.Data.EntityClient" />
Thanks in advance.
Let me preface this answer by saying that proper setup of a SQL instance is not as easy as Microsoft would like you to think with the entity framework. It's a little bit involved and requires that you put your DBA hat on for a little bit.
The error you have indicates that the web instance is attempting to connect to the SQL server using Windows Integrated Security. This will work fine if (a) the windows user that the process is running as (which can be configured in IIS) is authorized to log on to the SQL server and has a valid login in the database and (b) if the SQL server is on the same machine or in the same domain as the IIS server.
In light of this, I recommend using SQL Server authentication. If you need to know how to do this, I recommend searching for "SQL Server Authentication setup" - here is an article that I found which might help you set this up.
http://msdn.microsoft.com/en-us/library/aa337562.aspx
In general, I recommend taking the following actions:
Connect to the sql server using MS SQL Management Studio.
Permanently attach your database, then use the Initial Catalog property on your connection string rather than AttachDbFileName
Then set up your login username and password on the SQL server, and create a login in the database for it.
Make sure your login can only execute the stored procedures you want it to execute. Deny it access to running sql statements.
You will also need to add the username and password to your connection string, and set IntegratedSecurity=false.
Let us know how things go once you get your SQL server set up properly.
This error means that your provider code cannot find the SQL Server. If you have checked the server instance name (it should be <yourLocalServer>\SQL_1), then it could be the attachdbfilename= parameter, as this is a really unreliable way to specify the database to connect to (you should be using the Database Name, not the file name), because there are about a hundred reasons that the file name could change that have nothing to do with your application.

How do I fix the error 'Named Pipes Provider, error 40 - Could not open a connection to' SQL Server'?

I can't seem to connect to my database from a site. I get this error:
Named Pipes Provider, error: 40 - Could not open a connection to SQL Server
I tried using the local IP address to connect as well as a public one. I've tried:
Yes, the site can communicate with the server
Named pipes/TCP is enabled.
Remote connections are allowed.
Windows Firewall is off
Created an exception for port 1433 in Windows Firewall.
Enabled everything in SQL Server Configuration Manager.
What else can I do here?
Solving this problem is very easy:
Go to control panel.
search for services.
Open Local services window from your search results
Restart your MSSQLSERVER service.
Screenshot of the steps:
And the simplest solution - check if your slash is back...
I spent about an hour trying to figure out what's wrong with SERVER/INSTANCENAME when everything is configured correctly, named pipes, user access rights... and suddenly it struck me, it's not a slash, it's a backslash (\).
The horror, the shame...
It's a three step process really after installing SQL Server:
Enable Named Pipes
SQL Config Manager --> SQL Server Network Consif --> Protocols --> Named Pipes --> Right-click --> Restart
Restart the server
SQL Config Manager --> SQL Server Services --> SQL Server (SQLEXPRESS) --> Right-click --> Restart
Use proper server and instance names (both are needed!)
Typically this would be .\SQLEXPRESS, for example see the screenshot from QueryExpress connection dialog.
There you have it.
I had just installed SQL SERVER 2012 developer. When I was creating my first SSIS package, I received this pipes error when I was trying to create a data connection task in SQL Server 2012 Data Tools in the Connection Manager box. I resolved with the help of the post above.
If choose a named instance and you call your named instance SSQDatabase1 and your pc's name is PCX1. You must enter PCX1\SSQDatabase1 not just SSQDatabase1
or you will receive the named pipes error.
A thread on MSDN Social, Re: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server, has a pretty decent list of possible issues that are related to your error. You may want to see if any of them could be what you're experiencing.
Incorrect connection string, such as using SqlExpress
Named Pipes(NP) was not enabled on the SQL instance
Remote connection was not enabled
Server not started, or point to not a real server in your connection string
Other reasons such as incorrect security context
try basic connectivity tests between the two machines you are working on
i Just enabled TCP/IP,VIA,Named Pipes in Sql Server Configuration manager , My problem got solved refer this for more info Resolving Named Pipes Error 40
Use SERVER\\ INSTANCE NAME .Using double backslash in my project solved my problem.
Thanks to Damian...
TCP/IP
Named Pipes
... both enabled
Web Config....(for localhost)
<add name="FooData" connectionString="Data Source=localhost\InstanceName;Initial Catalog=DatabaseName;Integrated Security=True;" providerName="System.Data.SqlClient" />
Did have the same problem. Spent like 6 hours when had to migrate some servers.
Tried all suggestions available on this topic and others.
Solution was as simple as server restart!
Very simple solution
use (local)\InstanceName
that's it. it worked for me.
TL;DR; Your SQL Server instance is using dynamic ports which is not working. Force SQL Server to use static port # 1433.
Complete Details: First of all this problem is more likely if you've a mix of default and named instance or named instances only(which was my case).
Key concept: Each instance of Microsoft SQL Server installed on a computer uses a different port to listen for incoming connection requests. Default instance of SQL Server uses port # 1433. As you install named instances then they will start using dynamic ports which is decided at the time of start-up of Windows service corresponding to named SQL Server instance.
My code was failing (with error code 40) to connect to the only named SQL Server instance that I had on my VM. You can try below possible solutions:
Solution # 1: Client code trying to connect to SQL Server instance takes help from SQL Server browser service to figure out port number at which your named instance is listening for incoming connections. Make sure SQL browser service is running on your computer.
Solution # 2: Check the port # (in yellow color) your named SQL Server instance is using from SQL Server configuration manager as shown in the snapshot below:
Use that port number explicitly in your connection string or with sqlcmd shown below:
sqlcmd -s mymachinename,11380 -i deleteDB.sql -o SQLDelete.txt
Solution # 3: Force your named instance to use port # 1433 which is used by default instance. Remember this will work only if you don't have any default SQL Server instance on your computer as the default SQL Server instance would be using using port # 1433 already. Same port number can't be uses by two different Windows services.
Mark TCP Dynamic ports field to blank and TCP Port field to 1433.
Change the port number in your connection string as shown below:
sqlcmd -s mymachinename\instanceName -i deleteDB.sql -o SQLDelete.txt
OR
sqlcmd -s mymachinename,1433 -i deleteDB.sql -o SQLDelete.txt
Note: Every change in TCP/IP settings requires corresponding Windows service restart.
Interestingly enough after resolving the error when I went back to dynamic port setting to reproduce the same error then it didn't happen. Not sure why.
Please read below interesting threads to know more about dynamic ports of SQL Server:
How to configure SQL Server Port on multiple instances?
When is a Dynamic Port “dynamic”?
When to use a TCP dynamic port and when TCP Port?
I got leads to solution of my problem from this blog.
in my case, i had a standalone server, i changed the sql server port default port 1433 in configuration manager to some number and restarted the sql serve service to take effect,i was able to connect to the sql server through management studio if i login to the server. but i was not able to connect from my local machine through sql server, i was 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 5)
I checked and verified all the below
-Named pipes/TCP is enabled.
-Remote connections are allowed.
-Windows Firewall is off
-Created an exception for portin Windows Firewall( this was not necessary in my case as the server is in same subnet network).
-Enabled everything in SQL Server Configuration Manager.
then i chnaged back the port number to default 1433 and restarted the sql server service, and the issue got resolved and i am able to connect the sql server from my local management studio.
I had the same problem. I use the MSSQL Server Management Studio 2017 and solved this problem using these steps:
Check for working fine SQL Server Services services or not.
Also check for working in good condition SQL Server (MSSQLSERVER).
Also check for working fine SQL Server Browser.
Restart SQL Server (MSSQLSERVER)
and fixed it.
You will find most likely your DB name is not correct, you will see the server name in VS like "DESKTOP-0I14BKI" but if you open up SSMS you will see DESKTOP-0I14BKI\SQLBLAHBLAH , simply add "\SQLBLAHBLAH" (instance name) to your "server name" in VS connection properties.
You will see:
To Fix:
Try the following steps:
Open Services window (open "run box" and type services.msc).
Looking for SQL services (with SQL prefix).
Start them (if cannot start. Goto step 4).
Right_click to each service -> Properties -> Change to tab "Log on"-> choise log on as "Local ..." -> 0K. Then start SQL services again.
Try Open SQL and connect database.
In my case,
I opened SQL Server Management Studio and searched for SQLEXPRESS in my Database engine.
It had two instances and I selected the correct one.
If you are working with Asp.net core and using appsettings.json than write server as localhost and after write sql instance name for enabled named pipe like this
"ConnectionString": {
"dewDB": "server=localhost\\dewelopersql;database=dewdb;User ID=sa;password=XXXXX",
},
After following all the steps mentioned here, if it still does not connect, try adding the DNS with the IP address in the hosts file in the etc folder. Adding an IP address instead of DNS name in the connection string should be a temporary solution to check if the connection actually works.
I tried using the local IP address to connect as well as a public one.
I've tried:
Yes, the site can communicate with the server Named pipes/TCP is
enabled. Remote connections are allowed. Windows Firewall is off
Created an exception for port 1433 in Windows Firewall. Enabled
everything in SQL Server Configuration Manager.
i ensured and did the above as well and I just want to share that the DOUBLE BACKSLASH
oBuilder.DataSource = "SPECIFICPCNAME\SQLEXPRESS";
Using a SINGLE BACKSLASH resulted into a build error i.e.: Error 1 Unrecognized escape sequence
I hope this helps the next guy - I've sacrificed dinner, midnight snack and NBA highlights time solving this (shame)
Thanks to [Tamizh venthan]
^_^
Enable TCP/Ip , Piped Protocol by going to Computer Management ->SQL and Services, ensure the Service is On. Enbale the port on the Firewall. Try to login through Command Prompt -> as Admin; last the User Name
should be (local)\SQLEXPRESS. Hope this helps.
Open SQL Server Configuration Manager
Select SQL Server Services from right.
Find your server from right and go to its properties (with right click)
Change log on method to Local System.
I had the same problem and solved the problem by disabling my firewall(ESET).
The first step to solve this problem should be to try pinging your own computer from another computer. If you have firewall on, you may not be able to ping yourself. I tried pinging my own pc, then ping was failed(didnt get response from the server)
I was trying to add a new connection in VS2015. None of the suggestions here worked. Suspecting some sort of a bug in the wizard, especially since SSMS was able to connect just fine, I decided to try and trick it. It worked!
Instead of adding the connection, use "Create new SQL Server Database". Enter your server name and a random name for the new DB, e.g. "test".
Assuming this succeeds, open Server Explorer in VS, locate the connection in Data Connections, right-click it and select Modify Connection.
Change "test" (from step 1) to the name of the existing database you want to connect to. Click "Test Connection". This time it should work!
Delete the temporary database you created in step 1.
I have one more solution, I think.
I recently had changed my computer name so, after I couldn't connect still after trying all above methods.
I changed the Server name..
Server name => (browse for more) => under database engine, a new server was found same as computers new name.
This worked, and life is good again.
I struggled for ages on this one before I realized my error - I had used commas instead of semicolons in the connect string
I had this issue but none of the suggestions above fixed it.
I was seeing this issue when I deployed my website to IIS. The fix was to go into advanced settings against the default app pool and change the identity property from the default to Administrator.
For me it was a Firewall issue.
First you have to add the port (such as 1444 and maybe 1434) but also
C:\Program Files (x86)\Microsoft SQL Server\90\Shared\sqlbrowser.exe
and
%ProgramFiles%\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\Binn\SQLAGENT.EXE
The second time I got this issue is when I came back to the firewall, the paths were not correct and I needed to update form 12 to 13! Simply clicking on browse in the Programs and Services tab helped to realise this.
Finally, try running the command
EXEC xp_readerrorlog 0,1,"could not register the Service Principal Name",Null
For me, it returned the error reason
I tried pretty much everything on this page but I had some underlying issues which were actually what needed to be resolved. I was unable to do certain things like open SQL Server Configuration Manager, which ended up being corrupt/missing WMI provider files.
There are lots of tedious ways to resolve this issues according to what I've read, but the tool from tweaking.com was able to remove and replace/repair my WMI (Windows Management Instrumentation) Provider files.
I used to do computer repair and overall the tweaking.com tool really impressed me, and it was suggested from one of the WMI error forum pages I went to.
After I fixed this issue I was able to connect to my SQL db, both locally and remotely.
Hope this helps someone.
open port number 1433 on your server for sql remote connection
If you tried restarting the MSSQLSERVER service, and it did not work, this might be a solution:
If you are using SQLExpress, your server name should be as the following ComputerName\SQLExpress. However, for SQLDeveloper, you do not have to right SQLDeveloper after your ComputerName.

Resources