Connecting to remote SQL Server 2008 from Windows Azure - sql-server

I am trying to connect to a SQL Server 2008 instance from a Windows Azure worker role (it's not SQL Azure, but a remotely hosted SQL Server 2008 Standard Edition), but I get the following error message
System.Data.SqlClient.SqlException: 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) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at ...
The code snippet is the following:
using (var connection = new SqlConnection("MY CONNECTION STRING")
{
connection.Open();
var command = new SqlCommand("Select 1", connection);
try
{
var res = command.ExecuteScalar();
}
catch (Exception e) {
Log.Log("error", e.ToString());
}
}
When I run the snippet from my local command-line (directly accessing the remote SQL Server), it works OK, yet when run from Windows Azure, I end-up with the error message outline here above. In order to make sure there were no problem with the connection string sure, I re-try by hardcoding the string in the source code pushed toward Azure (just to be 100%, but I am still hitting the very same problem).
I have no firewall setup on the SQL Server 2008 instance, and I running out of ideas.
Can someone spot what I am doing wrong here?

I've noticed some issues with the SQL Server Resolution Protocol (or the SQL Server Browser) from Azure worker roles when connecting to external non-Azure SQL Server instances running on ports other than 1433. In these cases it can help to explicitly specify the TCP port of the instance in the connection string:
Data Source={domain/ip},{port};
Network Library=DBMSSOCN;
Initial Catalog={dbname};
User ID={user};
Password={pw}
See also Connect from Azure to an SQL Server Named Instance

Can you control your Azure instance through Remote Desktop?
If you can, log on, and try:
telnet yoursqlserverhostname 1433
If this blocks, you know that the network is not configured correctly. Usually a firewall issue, on either host or the network in between.

Related

Connect IIS in DMZ to SQL Server on intranet

I'm trying to connect IIS which is running on a server in the DMZ to a SQL Server instance on the company intranet. But, I'm getting the following error:
An unhandled exception occurred while processing the request.
Win32Exception: Access is denied.
Unknown location
SqlException: 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)
Do I need specific ports opened up on one of the servers? Or is there something else I need to do?
Considering your SQL server is running, start with the networking. On which port is your SQL instance listening (default 1433)?
If you don't know, open the SQL Server Configuration Manager (on the SQL Server). Navigate to the SQL Server Network Configuration > Protocols for %instancename% > TCP/IP > IP Addresses. Then, test if something is blocking this connection; on your IIS in PowerShell:
Test-NetConnection -ComputerName sqlservername -Port 1433
If this doesn't work, check the Inbound Rules for Windows Firewall on your SQL Server. Make sure you work on the right network profile and eventually speak to the one managing your network systems in your company.
Maybe your IIS can't resolve the SQL Servers hostname? Try using the IP and check your DNS configuration.
There might also be something off with your connection string. Mind posting it here?

HTTP Error 500.30 - ANCM In-Process Start Failure - An error occured during migration

I have read this thread, however unfortunately couldn't find the solution to my problem. I have an ASP.Net Core project (that's called Rent) and it works without any problem on my local machine. However, once I publish the project to the IIS (still in development mode) I get the below error
fail: Rent.Program[0]An error occured during migration
Microsoft.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: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.
---> System.ComponentModel.Win32Exception (0x89C50118): Unknown error (0x89c50118)
The connection string is called DefaultConnection and is the environment variable. Can anyone help me please? Can provide any additional information if required.
The first thing you should check is that your SQL Server instance is up and running and that your database is still available. This error means quite literally that it can't establish a connection to SQL Server from the Secret Server application.
And you can also check follow things in your environment:
Is something blocking the connection between your Secret Server server and SQL Server?
The standard SQL port is 1433. Check with your server administrator - is the Windows Firewall in use, blocking this port on your SQL server? Check with your network administrator - is there a firewall at some point in between that has closed off this port? Keep in mind that if you use a custom port for SQL, it need to be specified the Secret Server database connection using a SQLSERVER,port type of format.
On the server hosting your SQL Server database, is the SQL Server
service running?
Open services.msc or SQL Configuration Manager to view the status of your SQL Server service.

UWP cannot connect to local SQL Server

I'm creating a simple UWP application working together with my local DB server I set up with SQL Server Management Studio.
I can successfully set up a connection in the server explorer and run queries in the DB:
However when I run the application I get an error when the connection is being established:
System.Data.SqlClient.SqlException HResult=0x80131904 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: 25 - Connection string is not valid) Source=Core .Net SqlClient Data Provider
I'm not sure if it's a problem with the connection string or what else it could be. I checked the firewall settings and everything seems to be fine. The SQL server settings also allow for remote connection.
Which SQL Server version is running?
Have you tried with the following connection string format?
Data Source=.\\MSSQLServer;Initial Catalog=PapaDario;Trusted_Connection=yes;
Before you connect to your database, some aspect of the SQL Server configuration needs to be changed. First, ensure that you've enabled TCP/IP for SQL Server. You can do that in the Computer Management console. Then make sure that your SQL Server Browser service is running.

Can't Connect to SQL Server Remotely (TCP Error)

I am having an issue connecting to my SQL Server Database remotely from another computer.
I am trying to connect to the database using a VB.Net application that is suppose to be able to interact with it. I'd say my connection string may be the issue, but I have no problem connecting on the machine the database is on using the connection string.
This is what the connection string looks like though:
"Data Source=[IP_ADDRESS],[PORT];Network Library=DBMSSOCN;Initial Catalog=SQL_Database;Persist Security Info=True;User ID=[USER];Password=[PASS]"
The error I am getting right now is:
Database 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: TCP Provider. error: 0 - The wait operation timed out.).
This is what I have done so far to try to get this to work:
I have made sure that the files being run are on not a network/shared drive.
I've added an exception for TCP Port 1433 and UDP Port 1434 as Incoming Rules to the Firewall.
I've tried disabling the firewall.
I have gone into SQL Server Configuration Manager to ensured that the TCP settings are setup properly.
One thing I am not sure about, is that in the Configuration Manager, I have both the SQL Server and SQL Server Browser running, but the SQL Server Agent is unable to start. Would this cause me my problem?
If not, what else could be my issue? I need to be able to access this database remotely, but the connection string seems to only work locally.
So the issue was literally my company's installed network Firewall. Apparently when I asked if the firewall had been put down for me to test this, "Yes" really meant "No". Once I got the firewall temporarily disabled I was able to connect to everything perfectly fine.

Invalid connection string when connecting to SQL Server Express

I tried every single variation that I could find on the internet. Everything. And still every time I get the very same exception:
System.Data.SqlClient.SqlException: '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: 25 - Connection string is not valid)'
With this weird inner exception:
SocketException: The operation completed successfully
When I specify the port directly, then I end up with this wonderful exception:
An attempt was made to access a socket in a way forbidden by its access permissions
No matter what, it doesn't work. Moreover I'd like to have MS SQL Management Studio open while testing (that was the only process which could block the port).
So why does it not work? Management Studio can connect with IP\InstanceName without a problem. Why is the System.Data.Sql.SqlConnection class incapable of doing so?
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = "tcp:***.***.***.***\\SQLEXPRESS";
builder.InitialCatalog = "MyDB";
builder.Password = "MyPass";
builder.UserID = "ID";
builder.IntegratedSecurity = false;
_connection = new SqlConnection(builder.ToString());
FYI: I am using the ConnectionStringBuilder, so there shouldn't be any issue. Server name, instance name, SQL user and password are valid and I did explicitly set Integrated Security = False.
The problem was (which was not really clear) that UWP requires a capabilitiy in order to run that code. I read somewhere that you would need Enterprise Authentication which was not the one. Since my program and server are in a closed, private network I enabled Private Networks (Client & Server).
The one you would need is Internet (Client & Server). Sadly the exceptions don't hint to that and the fact that SqlClient on UWP requires this to work is nearly nowhere mentioned or not stressed enough so you wouldn't overlook it.
Solution found in this .Net Standard issue.
First of all try to connect to this database using SQL Server Management Studio.
If you get the same error, it means that there is a problem with the server not (or not only) with your connection string.
Here is some of possibilities :
1- Remove 'tcp:' from this part: builder.DataSource = "tcp:...\SQLEXPRESS";
2- On the server the SQL Server services (SQL Server or SQL Server browser) are stopped.
To activate go Services and start stopped services.
3- May be the server doesn't accept remote connections:
In this case on the server open SQL Server Configuration Manager
And activate tcp ip.
You should restart SQL Server service after this operation.
Tell me if it works for you.

Resources