Connect to on-premises sql server from azure function with hybrid connection via service bus - sql

I am trying to connect the sql server on my local computer from azure timer trigger function using Hybrid connection with Service Bus and getting the error as
"Exception while executing function: Functions.testConnection. mscorlib: Exception has been thrown by the target of an invocation. .Net SqlClient Data Provider: 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). Access is denied.2017-06-28T11:20:00.015 Function started"
And this is the code:
sqldb_connection value is :
Data Source=103.249.120.30 ;Initial Catalog=databasename;User ID=id;Password=password;

Related

Sometime Sql Connection Error from windows forms-Network related instance error

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.

Web Api 2 ConnectionString

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.

First login attempt aways fail, second works on SQL Server Azure

I have a SQL Database hosted in azure.
When I try to login, the first attempt always fails, the second works as expected.
The error I receive is
Cannot connect to databasex.database.windows.net.
------------------------------ ADDITIONAL INFORMATION:
A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections. (provider: Named
Pipes Provider, error: 40 - Could not open a connection to SQL Server)
(Microsoft SQL Server, Error: 53)
For help, click:
http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&EvtSrc=MSSQLServer&EvtID=53&LinkId=20476
Why is this happening and how to solve this?

Can't connect to SQL Server 2003 error 121

This is the error I am receiving when connecting to our SQL Server 2003 database
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 121)
"the semaphore time out has expired"
but when I try to connect using another pc its working
This is a weird error message "the semaphore time out has expired" and I've tried all the possible solution related to the link that you gave

Cannot connect web application to a SQL Server

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....