WPF with local database application
I was about to start but I faced this problem
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)
I searched alot to found that the error will be in the connection string
but I'm using the connection string from application settings which done by the wizard
using ( SqlConnection _SqlConnection = new SqlConnection ( Properties . Settings . Default . DatabaseConnectionString ) )
{
_SqlConnection . Open ( ); // <= Error Occurs Here
_SqlConnection . Close ( );
}
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)
You're using the wrong type of connection object.
SqlConnection is for the grown up SQL server, not for SQL Server Compact. connectionstrings.com has the connection strings you need. For the connection object itself I believe you need the SqlCeConnection class (add a reference to System.Data.SqlServerCe).
Related
Sometimes following error happening in windows application. The error is like
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)
I am having more than 50 forms in my application and most of the times there is no error. But sometimes, there is an error like this and when I am trying to connect sql its works fine.
I'm having the below error when trying to connect to an SQL DB:
"Data Source=***.***.***.***; Initial Catalog=DbName;Persist Security Info=True;User ID=****;Password=****;"
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)
"Network Library=DBMSSOCN; Data Source=***.***.***.***,1433; Initial Catalog=DbName;Persist Security Info=True;User ID=****;Password=****;"
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: TCP
Provider, error: 0 - The wait operation timed out.)
I've looked through plenty of resources online though still unable to resolve this
Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"?
The top connection string is obtained from Server Explorer and has fully expected connectivity, the latter to ensure it wasn't looking for a local DB.
We've this connection string as shows and working in other non-WebApi 2.0 projects which has connectivity to the DB
I've created a new DB using RDS in AWS too and having the same errors.
I've tried recreating the whole project as shown here (without any models) with the same errors too.
Any help in getting this resolved would be greatly appreciated
Edit, for clarity:
Console App, ConnectionString1 : Connects
Console App, ConnectionString2 : Connects
Web API, ConnectionString1 : Errors
"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)"
Web API, ConnectionString2 : Errors
"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: TCP Provider, error: 0 - The wait operation timed out.)"
.
var connectionString1 = "Server=***.***.***.***;Persist Security Info=True;User Id=****;Password=****"; //just for convenience
var connectionString2 = "Server=***.***.***.***,1433;Persist Security Info=True;User Id=****;Password=****";
var connection = new System.Data.SqlClient.SqlConnection(connectionString);
try
{
connection.Open();
}
catch (Exception ex)
{ }
finally
{
connection.Close();
}
Having BitDefender installed locally restricted traffic and the 500's when using IIS. You can white-list ports though this needs to be done through requests to BitDefender or get a decent AV where you can do this yourself.
I have two instances:
Default
Named[dynamics\FINANCE]
running on SQL Server 2014. However, when I try to connect to named instance say (dynamics\FINANCE) using SQL authentication from local SSMS, I get below error message:
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) (Microsoft SQL Server, Error: -1)
I assigned a static port number 1450 to the named instance [dynamics\FINANCE]. I also setup the firewall rule to allow access to Port 1450.
What am I missing here?
I am building a web application so I want to connect the web application on local machine to a company SQL Server. When copying the connection string from the same web application sitting on the server to my local web config I get the following 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)".
Your help will be appreciated....
I have tried any kind of name for Server Name, including ".\SQLEXPRESS", "localhost\SQLEXPRESS", "My PC Name", "MyPCName\SQLEXPRESS" but I still get the same error:
Cannot connect to .\SQLEXPRESS.
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) (Microsoft SQL Server, Error: -1)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=-1&LinkId=20476