Dnn Installation,Unable to connect to database. installWizard.aspx - asp.net

I am installing donnetnukes.
below errors is showing.
"No valid default database connection detected. Standard Database setup option is unavailable"
ERROR: DotNetNuke requires SQL 2008 (express or full product) to work.
screenshot:
https://lh4.googleusercontent.com/-bODakjneIYg/UiMEjieEGxI/AAAAAAAAA4U/HkN5Wq_oZyk/w620-h553-no/Untitled-3.png

The error is not as straight forward as you may think, Chris. If you're sure you have at least SQL Express 2008 or later installed, ensure 3 other things.
Go to your Sql Sever Config Manager and
Ensure SQL Server 2005 is uninstalled
Ensure that SQL Server Browser is running.
Ensure that under SQL Sever Network Configuartion --> Protocols both Named Pipes and TCP/IP is enabled.
If you have trouble enabling SQL Server browser, first stop the SQL Server (SQLEXPRESS) services, right click on the SQL Server Browser --> Properties --> Services Tab --> Start Mode set to "Automatic". Then you can restart both services. This will not work if you do not stop the SQLEXPRESS Server. At least it did not for me. :)

That error is straightforward, you either need to install SQL Express, using the defaults (not a named instance), or you need to provide the IP address, database name, and user connection info for the SQL server you are using.

Another thing that got me - I installed on Windows Server 2012 and the site wasn't trusted in Internet Explorer.
There must be some client scripts that need to run at start-up which are blocked.

I had such a problem. If use the custom option and then active the SA user and password in your SQL server, you will be able to continue the process.
The reason is that this wizard gets the IIS pool user as a default one. Hence, if you create a user, you will be able to connect to that specific user & password without any problem.
I hope you find this text helpful.

Related

SQL Server connection error when trying ro connect with local server? [duplicate]

I get the following error when trying to connect to SQL Server:
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)
This error is thrown when I try to configure my database to gridview in Visual Studio 2010. I'm at a loss as to how to debug this error.
How would you debug this error? What steps should I take in order to determine what is really going on here, in addition to the one mentioned in the error message?
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
From FIX : ERROR : Could not open a connection to SQL Server:
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:
1) Open Sql Server Configuration Manager --> SQL Server Network configuration --> Protocols for <(INSTANCE)> --> TCP/IP (double click on it).
2) Select --> IP Addresses(Tab).
3) Go to the last entry IP All and mention TCP Port 1433.
4) Press Win+R and enter services.msc.
5) 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.
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-
Then Search for SQLSERVER(MSSQLSERVER) and Restart the service.
Hope this will work.
In case you're using the Express Edition:
You need to add \SQLEXPRESS after your server name
e.g. MY-SERVER\SQLEXPRESS
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.
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:
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
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
Step 2: Enabled TCP/IP
Step 3: Double clicked TCP/IP and went to IP Address last entry IP ALL and entered TCP Port 1433 then applied
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
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.
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
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
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> 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!
Hold/Press to open the CMD, window + R and Type "services.msc"
Now look for sql server services, open find SQL SERVER with instance name
then ReStart this service and try again
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).
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.
Steps worked for me:
Start > Run > cmd > sqlcmd -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.
I made this silly mistake I keep using MSSQLSERVER rather using this server name.
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.
Check your TCP port number by double click TCP/IP protocol name. Usually it is 1433 by default.
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.
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
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
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.
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.
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.
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 (Weband Droid) and even though Default project was choosen in the Package Manager Console it used the connection string from the Droid project:
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.
You may check service status of MS SQL Server 2014. In Windows 7 you can do that by:
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.
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.
Happened to me atleast.
When I experienced this error in 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():
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:
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:
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 Friends SET Narrative = '<!--HTML Comment -->Once upon a time...' WHERE Narrative LIKE '&lt%'
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!)
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.
Solution of my problem:
Check my sqlconnection function
Click to see its configuration
New a connection
Select ur server name
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.
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.
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).
It was necessary to use SQL Server Configuration Manager to add an alias for the remote Dev database server. Fixed things right up.
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.
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.
The solution was to add a firewall rule (using Windows Firewall with Advanced Security).
Create an Incoming rule for each SSMS
eg 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)"
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.
My issue started when I tried to change the server from IIS Express to Local IIS (while using 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
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.
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.
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
Also, to test connectivity from a server where SQL server client is NOT present,
--> create a text file and change its file extension to .udl
--> Right click the file and you can see connection tab.
--> 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.
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.
Xml tag arrangement in Web.config is important
First
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
After
<connectionStrings>
<add name="SqlConnectionString" connectionString="Data Source=.; Initial Catalog=TestDB; Trusted_Connection=True;" providerName="System.Data.SqlClient" />
</connectionStrings>

A network-related or instance-specific error occurred while establishing a connection to SQL Server 2008 [duplicate]

I get the following error when trying to connect to SQL Server:
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)
This error is thrown when I try to configure my database to gridview in Visual Studio 2010. I'm at a loss as to how to debug this error.
How would you debug this error? What steps should I take in order to determine what is really going on here, in addition to the one mentioned in the error message?
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
From FIX : ERROR : Could not open a connection to SQL Server:
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:
1) Open Sql Server Configuration Manager --> SQL Server Network configuration --> Protocols for <(INSTANCE)> --> TCP/IP (double click on it).
2) Select --> IP Addresses(Tab).
3) Go to the last entry IP All and mention TCP Port 1433.
4) Press Win+R and enter services.msc.
5) 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.
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-
Then Search for SQLSERVER(MSSQLSERVER) and Restart the service.
Hope this will work.
In case you're using the Express Edition:
You need to add \SQLEXPRESS after your server name
e.g. MY-SERVER\SQLEXPRESS
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.
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:
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
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
Step 2: Enabled TCP/IP
Step 3: Double clicked TCP/IP and went to IP Address last entry IP ALL and entered TCP Port 1433 then applied
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
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.
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
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
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> 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!
Hold/Press to open the CMD, window + R and Type "services.msc"
Now look for sql server services, open find SQL SERVER with instance name
then ReStart this service and try again
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).
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.
Steps worked for me:
Start > Run > cmd > sqlcmd -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.
I made this silly mistake I keep using MSSQLSERVER rather using this server name.
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.
Check your TCP port number by double click TCP/IP protocol name. Usually it is 1433 by default.
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.
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
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
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.
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.
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.
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 (Weband Droid) and even though Default project was choosen in the Package Manager Console it used the connection string from the Droid project:
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.
You may check service status of MS SQL Server 2014. In Windows 7 you can do that by:
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.
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.
Happened to me atleast.
When I experienced this error in 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():
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:
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:
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 Friends SET Narrative = '<!--HTML Comment -->Once upon a time...' WHERE Narrative LIKE '&lt%'
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!)
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.
Solution of my problem:
Check my sqlconnection function
Click to see its configuration
New a connection
Select ur server name
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.
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.
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).
It was necessary to use SQL Server Configuration Manager to add an alias for the remote Dev database server. Fixed things right up.
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.
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.
The solution was to add a firewall rule (using Windows Firewall with Advanced Security).
Create an Incoming rule for each SSMS
eg 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)"
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.
My issue started when I tried to change the server from IIS Express to Local IIS (while using 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
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.
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.
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
Also, to test connectivity from a server where SQL server client is NOT present,
--> create a text file and change its file extension to .udl
--> Right click the file and you can see connection tab.
--> 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.
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.
Xml tag arrangement in Web.config is important
First
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
After
<connectionStrings>
<add name="SqlConnectionString" connectionString="Data Source=.; Initial Catalog=TestDB; Trusted_Connection=True;" providerName="System.Data.SqlClient" />
</connectionStrings>

Getting run time error when trying to insert values into local database [duplicate]

I get the following error when trying to connect to SQL Server:
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)
This error is thrown when I try to configure my database to gridview in Visual Studio 2010. I'm at a loss as to how to debug this error.
How would you debug this error? What steps should I take in order to determine what is really going on here, in addition to the one mentioned in the error message?
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
From FIX : ERROR : Could not open a connection to SQL Server:
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:
1) Open Sql Server Configuration Manager --> SQL Server Network configuration --> Protocols for <(INSTANCE)> --> TCP/IP (double click on it).
2) Select --> IP Addresses(Tab).
3) Go to the last entry IP All and mention TCP Port 1433.
4) Press Win+R and enter services.msc.
5) 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.
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-
Then Search for SQLSERVER(MSSQLSERVER) and Restart the service.
Hope this will work.
In case you're using the Express Edition:
You need to add \SQLEXPRESS after your server name
e.g. MY-SERVER\SQLEXPRESS
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.
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:
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
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
Step 2: Enabled TCP/IP
Step 3: Double clicked TCP/IP and went to IP Address last entry IP ALL and entered TCP Port 1433 then applied
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
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.
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
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
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> 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!
Hold/Press to open the CMD, window + R and Type "services.msc"
Now look for sql server services, open find SQL SERVER with instance name
then ReStart this service and try again
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).
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.
Steps worked for me:
Start > Run > cmd > sqlcmd -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.
I made this silly mistake I keep using MSSQLSERVER rather using this server name.
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.
Check your TCP port number by double click TCP/IP protocol name. Usually it is 1433 by default.
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.
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
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
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.
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.
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.
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 (Weband Droid) and even though Default project was choosen in the Package Manager Console it used the connection string from the Droid project:
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.
You may check service status of MS SQL Server 2014. In Windows 7 you can do that by:
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.
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.
Happened to me atleast.
When I experienced this error in 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():
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:
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:
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 Friends SET Narrative = '<!--HTML Comment -->Once upon a time...' WHERE Narrative LIKE '&lt%'
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!)
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.
Solution of my problem:
Check my sqlconnection function
Click to see its configuration
New a connection
Select ur server name
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.
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.
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).
It was necessary to use SQL Server Configuration Manager to add an alias for the remote Dev database server. Fixed things right up.
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.
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.
The solution was to add a firewall rule (using Windows Firewall with Advanced Security).
Create an Incoming rule for each SSMS
eg 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)"
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.
My issue started when I tried to change the server from IIS Express to Local IIS (while using 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
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.
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.
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
Also, to test connectivity from a server where SQL server client is NOT present,
--> create a text file and change its file extension to .udl
--> Right click the file and you can see connection tab.
--> 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.
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.
Xml tag arrangement in Web.config is important
First
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
After
<connectionStrings>
<add name="SqlConnectionString" connectionString="Data Source=.; Initial Catalog=TestDB; Trusted_Connection=True;" providerName="System.Data.SqlClient" />
</connectionStrings>

How can I connect to a SQL Server using SSMS 2016?

I'm a rookie so I'm not really acquainted with how this really works. I've downloaded SQL Server 2016 and once I log onto the Management Studio, it asks me to connect to a particular server.
I've no idea what server I should connect to. I've tried everything. Turned the firewall off, used cmd commands, (tells me that my access has been denied), registered a new server from within the studio (but nothing shows up in the Server Name drop-down) I'm really confused.
What server should I connect to?
Make sure that the server has TCP connections enabled (either following this guide https://msdn.microsoft.com/en-us/library/ms191294.aspx or by specifying /tcpenabled=1 flag to the installer).
Make sure you have remote access enabled (sp_configure N'remote access',N'1')
Make sure the firewall is configured to let you through or just disable it (only do so if the SQL Server is installed in a disposable VM): netsh advfirewall set allprofiles state off
I wrote a blog post on how to install SQL Server properly.

SQL Server 2005 has problems connecting to a website running on the same server

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Hello I am new on developing on SQL Server 2005. I've worked for several years with SQL Server 2000, but after doing the usual stuff I do to connect to the server I get this exception on the web server.
There are several links on google that point me to possible solutions, but none of them have solved my problem. I've made changes on a "Surface Area whatever..." dialog (What the hell is that??? Why does SQL Server has changed so much??? It seems so complicated now).
I have ensured that SQL Server 2005 is configured properly to allow incoming connections on the instance of database server. I also have selected Automatic as the Startup type to start SQL Server Browser service automatically every time system starts. And no, there is no firewall running.
I've tried changing the connection string to connect using a port, to connect using the IP, to connect using the instance name...
Nothing seems to work, I'm still getting the same error. Any hint?
Answering the questions that people have made:
Yes, I can connect using management studio from a different computer.
Yes, I'm sure it's configured to accept local and remote TCP/IP and named pipes.
Yes, I restarted the server.
I am using Mixed mode security, which I already enabled. I already enabled the sa user.
I am able to connect to the database using a .udl file, and I've checked that my connection string is OK. I can connect to the database using DBArtisan and SQL Server client tools. I can do that both on the server and on a different machine. Even with all that...
The website is still unable to connect.
New update...
I've been struggling all day with this problem, and still haven't found out the cause. It seems that the error message I posted is a generic error that .net gives when it's not able to connect. I placed trash on the connection string (typing servers that don't exist) and I still get the same error.
These are some of the connection strings I've used on the server:
connectionString="Integrated Security=SSPI; Data Source=SERVER; Initial Catalog=db; Network Library=DBMSSOCN;"
connectionString="Data Source=SERVER; Initial Catalog=db; User ID=sa; Password=xxxxx;"
connectionString="Data Source=SERVER\MSSQLSERVER; Initial Catalog=db; User ID=sa; Password=xxxxx;"
I tried to register the sql server instance using some strange command, I found that here:
http://kb.discountasp.net/article.aspx?id=1041
To do that I used the aspnet_regsql.exe tool. It's still not working...
I also know that the server has the latest version of MDAC installed on it. The only thing that I'm suspicious on is that the server has two Database engines: SERVER and server\sqlexpress
Does that has something to do with the problem?
The only thing that I'm suspicious on is that the server has two Database engines: SERVER and server\sqlexpress
I think this is the source of the problem. Which one do you intend to connect to? You need to specify the "instance" you are connecting to.
Assuming you intend to connect to the SERVER instance, you connection string should then look like this (assuming the default instance name):
Data Source=YOURSERVER\MSSQLSERVER; Initial Catalog=db; User ID=sa; Password=xxxxx;
Or for sql express the connection string looks like this:
Data Source=YOURSERVER\sqlexpress; Initial Catalog=db; User ID=sa; Password=xxxxx;
Can you connect to the SQL Server via Management Studio from a different machine? This might help you narrow down whether it is the SQL Server configuration or you connection string configuration.
Recheck the surface area configuration, and make sure TCP/IP connections are allowed.
This could be many things. The first thing I would check is to make sure you can connect to the server using SQL Server Management Studio. Second, check your connection string to make sure it is correct. Surface area configuration should not apply for local connections.
Try re-installing the latest MDAC on the server. I once had a similar problem and this solved it.
[http://www.microsoft.com/downloads/details.aspx?familyid=6c050fe3-c795-4b7d-b037-185d0506396c&displaylang=en][1]
Based on the error looks like the code is attempting to connect using named pipes, rather than TCPIP. You may actually need to specifically indicate in your connection string that the sql provider should connect using tcpip, so your connection string would look like the below.
Using Integrated Authentication (windows):
Integrated Security=SSPI; Data Source=SERVERNAME; Initial Catalog=DATABASENAME; Network Library=DBMSSOCN;
Using SQL Authentication:
UID=USERNAME; PWD=PASSWORD; Data Source=SERVERNAME; Initial Catalog=DATABASENAME; Network Library=DBMSSOCN;
I've seen something akin to this happen before, where for some reason "named pipes" is used by default as the transport/connection layer, especially since both the web application and sql server are running on the same machine. I generally always use tcpip as the transport, or network library.
Another troubleshooting technique is to use a UDL (or data link file) to troubleshoot the connection. This allows you to switch between connection providers (ODBC, OLEDB, etc) and to set other connection options.
On the desk top of the machine right click and choose new -> text document.
Rename the *.txt file to TestConnect.udl (name doesn't matter just needs to be .udl extension). You should see the icon change from a text file icon to an icon that shows a computer on top of a data grid, or something like that (in other words windows should have an icon for it.).
Now double click the file and you will see a "Data Link Properties" applet appear.
Click the Provider tab, and you will see a list of different connection providers. I'd start by just choosing "Microsoft OLE DB Provider for SQL Server". We can use this to confirm that OLE DB can connect or not.
Click next, and enter the servername or ip address. Select Windows NT Integrated security. (You can always come back and change it to use a sql login.) At this point you can click "Test Connection". If the connection succeeds, then select a database name from the drop down list.
Lastly, if the connection fails, select the "All" tab, and then look for "Network Library" and edit its value, setting it to "DBMSSOCN".
Go back to the connection tab and click "test connection" again.
Repeat steps 4 and 5 this time with the "SQL Native Client" selected.
Hope this helps.
At the prompt does:
osql -E -S
... get you a > prompt ?
Did you try specifying the instance name in the connection string? Apparently sql server express, in particular, is finicky about having the instance name.
I've also started to poke around with the SQL Server Configuration Manager. So did you click into "SQL Server 2005 Network Configuration" and then look at "Protocols for InstanceName"? And you enabled TCP/IP and Named Pipes?
Did you also look at the "SQL Native Client Configuration" --> "Client Protocols", and you see that TCP/IP and Named Pipes is enabled there as well?
Using the SQL Server 2005 Surface Area Configuration tool, click the "Surface Area Configuration for Services and Connections", then under "Database Engine" --> "Remote Connections" what is selected? Since it appears that you are attempting to connect using Named Pipes you will need to make sure that "Local and remote connections" and "using both tcp/ip and named pipes" is selected.
As you probably know, once any changes are made, you have to stop and restart the sql server instance via Management Studio (you don't need to reboot the entire machine, although rebooting the entire machine will get you there).
And my last piece of advice. Step away from this for a while, and get your mind off of it for a few minutes. When you dive back in, you may find something you missed or overlooked before.
I fixed the issue that I had with the connection. The problem was on my application. The cause of the issue was that a connection string to the development (instead of the production) database, was hardcoded by one of the dialogs that generates the datasets. This dialog placed the connection string both on the web.config, and on a hidden sourcecode file called "Settings.settings.cs". The problem was solved by fixing the connection string to the correct location.
The error message was totally misleading, but I was able to find that by following all the methods presented on the stack trace.
So if you ever find this error message, there are tons of possible causes. Your first bet is to follow the usual steps for this error, which are checking that the server allows remote and local connections, and restarting the browser service.
If that doesn't work, check the stack trace, look for code that is in your application, put a break point there and explore all the properties on the connection string. At least that's how I solved it.

Resources