0
votes

Background:

I've created a .Net Core (2.2.0) application using EFCore (2.2.2). Up until now I have been using a local SQL Server instance and am attempting to use an Azure SQL Server instead.

I have updated the connection string in the database context to that found on the Azure dashboard.

I have signed in to the account used in Azure within the SQL Server Object Explorer in VS2017, and the database is appearing.

I'm using a code-first approach so there are no tables available, until after running the application.

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: 25 - Connection string is not valid)

The connection string is:

.UseSqlServer(
            @"Server = tcp:db.database.windows.net, 1433;
              Initial Catalog = DB;
              Persist Security Info = False;
              User ID = [email protected];
              Password = password; 
              MultipleActiveResultSets = False; Encrypt = True; 
              TrustServerCertificate = false; 
              Connection Timeout = 60;");

My local network hasn't got fantastic capabilities. Could this have an effect on connecting?

Or is there an error in this connection string?

Edit: I changed the connection timeout to 800 seconds, after a period of ~800 seconds the connection timed out again, this time with a slightly different error:

Error 2:

A network-related or '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 - No such host is known.)'

2
I can't say for sure what you have is wrong, but I've personally never seen the server declared that way. What happens if you just use Server=db.database.windows.net:1433;? Or actually, you can leave the port off as well, since 1433 is the default. TCP is also the default. That's what all HTTP communication uses.Chris Pratt
It's returning the same error with that way. I copied the connection string from the Azure properties page, that's why I'm so confused.Stephen McGowan
Are you connecting from within your organization network or outisde? Just trying to rule out network traversal/latency issues.Chris Pratt
No it's a home network. I have the connection string timeout set to 800 seconds. If the error is thrown in and around 800 seconds after starting the connection, do you think that would be an indicator of latency issues? 13 minutes seems like plenty of time to connect.Stephen McGowan

2 Answers

0
votes

You may not have provided rights to your Azure database to be connected remotely from security group. Mostly it is not allowed to be accessed from remote computer. check from DB Security Group and Resource security group and Make sure your IP is in allowed list.

0
votes

I'm going to close this as it turned out to be a latency issue.