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();
}
var connectionString = "asAbove"; var connection = new SqlConnection(connectionString);
– Jun 02 '17 at 15:00Both projects have this, console app works, asp.net web app fails, asp.net core web app fails