Azure Hybrid Connection string - c#

I have successfully created an Hybrid Connection between Azure and an on-premise resource. I see "Connected" in both the Azure Portal and Hybrid Connection Manager.
When I run my .NET code local in Visual Studio with the connection string "AppServer://MyPC:5162/AzureOeApi" everything runs fine but when I run it in Azure, I get a connection error (it can't see the on-prem end-point).
Do I need to change my connection string when running in Azure to force it to go through the Hybrid Connection or will it be handled automatically?

No need to change connection string.
We had similar issue - connection was "Connected", but no requests whould go through. You need to use fully qualified domain name in configuration of hybrid connection.
Please also read this question - similar question

I've been struggling with this problem for a whole day and finally I had a breakthrough: in my original connection string I was referring to [DB_SERVER]\[INSTANCE], having correctly configured the DB instance to listen to a given TCP port [PORT].
With this setup the Hybrid Connection was 'Connected' but I was getting the exception:
ExceptionMessage: The underlying provider failed on Open. -InnerExceptionMessage: 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)
It turns out that the connection string needs do explicitly refer to the port number (instead of the DB instance) using the syntax [DB_SERVER],[PORT] (mind the comma!).
Unfortunately Microsoft does not document this subtle detail....

Related

Update-Database command giving error in establishing connection to the server (Code First Migration)

I created this project on my another system and completed. I used code first migration for creating database. On that system, this app was running correctly.
But now when I had transferred the project to another system, Its package manager is showing 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)
I tried with Update-Database -Vebrose, I observed that it is targeting wrong data source, which was in that system where I created the project. How to solve this issue?
Check if the app.config has the connection string set. It may have the connection of the "old" machine that is now unaccessible.
Is the SQL Server configured to allow remote connections?
Is the port 1433 (the SQL Server default port) open?
If you only have the text you sent in the web.config, the connection string might be elsewhere.

.NET Core 1.1 application on Mac and SQL Server connection string

I'm having problems in connecting a .NET Core 1.1 application to a remote SQL Server, but only on my Mac because on Windows everything works well.
Said that it's not my application and I'm only trying to make it working, this is my connection string on appsettings.Development.json:
"ConnectionStrings": {
"MesDatabase": "Data Source=x.x.x.x\\BLABLA,49331; Initial Catalog=DBNAME; Uid=sa; Pwd=blablabla"
}
This is the error I get opening the connection:
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)
I can't access the server, any idea? I'm almost sure that it's a stupid error on connection string but I cannot find it.
I also tried to create a .udl file on Windows, editing it with correct connection data and taking the resulting connection string opening it with notepad. Nothing, always "connection string is not valid" on Mac.
As Jeroen Monstert said:
It makes no sense to specify both an instance name and a port number.
Either specify the instance name, and then let the SQL Server Browser
service resolve the port for you, or specify the port, but then leave
out the instance name.
My problem was due to the fact that in the connection string I had both the instance name and the port, in combination with a "probably bug" on .NET Core 1.1 because behaviour was different between Mac and Windows. In my case SQL Server Browser was down on the server so I needed to specify the port, and for this reason I had to remove the instance name from the connection string.

A network related or instance specific error only in my machine

I am getting the below error when I try to connect to SQL server from C# code
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)
My connection String looks like this
"Data Source={DatabaseServer};Initial
Catalog={DatabaseName};Integrated Security=SSPI;Enlist=false;"
I have tried all the option which I found in lots of articles but could not solve the issue. One more thing to note is my colleague is able to run the same code from his machine. So it is obviously not problem with SQL server. It has to do something with my machine.can anyone give me any pointers what could be the problem? I am able to connect to SQL server instance through SSMS.
What is the provider in your connection string? Something like
Data Source=SQLServerName;Initial Catalog=DatabaseName;Provider=SQLNCLI11.1;Integrated Security=SSPI;
Well I figured it out...Actually I am working on a remote machine and I created a new project in visual studio which gets created in remote drive by default. so it does not seems to find instance from remote drive but it works when I copy it to my local drive..
Since you can connect to your SQL server through SSMS and the error message looks like the connection string is wrong (or only working for some people somehow), you could compare the parameters SSMS uses in the connection dialog to those in your connection string in the C# code.
If you find any differences there, they could be the error you're looking for.

web service - SQL connection string

I've built an .asmx web service which retrieves informations from a local sql server 2014 database.
Everything is working fine on localhost, but after publishing the web service to Azure i get the error:
An unhandled exception of type 'System.Web.Services.Protocols.SoapException'
occurred in System.Web.Services.dll
Additional information: Server was unable to process request. ---> 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)
SQL Server is configured to allow remote connections.
My connection string is like:
string con2 = #"Data Source=OfficePc\MSSQLSERVER2014;Initial Catalog=Database;Persist Security Info=True;User ID=Admin;Password=123456";
Is the error the result of something missing from the connection string, or am i missing some configurations changes?
As Paul mentioned in a comment under the question, your connection string is pointing to a local database resource (presumably on your dev machine). Even though you configured your local database server to support remote connections, the address OfficePc\MSSQLSERVER2014 isn't addressable, as that does not equate to a machine address (IP address).
Your app would need to connect to your database via an accessible IP address (which might require you to do some port-forwarding on your local network, or open ports on your firewall).
Alternatively, you can migrate your database to Azure (either with SQL Server in a VM or with the SQL Database service).
Keep in mind: If you are accessing a local (on-premises) database server from Azure, there will be latency added, as well as some outbound bandwidth costs.
It looks like SQL Server instance is not running or not accessible. Try connecting to the same database using SSMS and if you get the same error then the instance is not running.
Mostly the error occurs when the Database server was not found. Recheck if the server name (Data Source) is mentioned correctly. If you manually generated the connection string use .uld file to generate connection string.
To auto generate connection string using .udl file:
Create a sampe.txt file.
Rename it as sample.udl file.
Then double click on it, It will show you window entitled 'Data Link Properties'.
Configure the connection there.
Then Test the connection using test connection button.
Then open the file with notepad. It will show you the exact connection string.
For further reference check : MSDN

SQL Server connectivity issues even with valid connection string

This has been plaguing me for the last few hours, I'm recieving the following error message on an ASP.NET web page:
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)
In the past to fix this I've found it was a simple connection string error, however I'm using Idera's Connection String generator tool. It seems to be able to connect to the server just fine when I test the string. I can connect with SQL Management Studio, as well as I can create a blank .udl file, fill in the details, and it connects without issue.
I've double checked, and the server is allowing remote connections, I turned the firewall off at this point (just trying to get this to work) and still no go.
Do you guys think I'm missing something ? Any help is GREATLY appreciated!
And when you try adding a connection from Visual Studio ?
You could also use the connection string that is generated by VS while doing this.
It seems as if you are missing the instance name or something like that.
Edit : Yes, as explained in the comment : Right click the connection, then copy the Connection string.
But you might have to replace the "name" by the IP address, if the resolution of the host name is not being performed correctly
From the web servercan you resolve the name of the server using in the connection string - i.e. is it a DNS issue?

Categories