question

Hakan-8363 avatar image
0 Votes"
Hakan-8363 asked Monalv-msft edited

Visual Studio Publish - not able to connect to database

I have created a very simple Blazor application with a database connection. The application works fine, when executed locally. I have created a SQL Server database in Azure. I have added a firewall rule to make external access possible for my ip. When I publish my application from Visual Studio to Azure, the database is created in Azure, but the table that I have created, using Entity Framework in the application, is not created in the database on Azure. The table is created in my local database. I can connect to the database in Azure from Visual Studio, using the SQL Server Object Explorer. I'm using the same connection string in the Settings section in Publish as I'm using in SQL Server Object Explorer. When publishing I get an error message with a link to Azure. When using this link I'm redirected to "Application Event Logs" in Azure and I can see a few errors including: "Unhandled exception. System.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: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)" The message is a bit strange since the database has been created and since I can access the database from SQL Server Object Explorer. The connection string I use looks like this: Data Source=pthp2dbserver.database.windows.net;Initial Catalog=PTHP2DB;User ID=pthp2administrator;Password=;Connect Timeout=30;Encrypt=True;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False I suppose there is some configuration that must be changed. Can you please advice?

sql-server-integration-services
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Monalv-msft avatar image
0 Votes"
Monalv-msft answered Monalv-msft edited

Hi @Hakan-8363 ,

"Unhandled exception. System.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.

This error usually means that the client can't find the SQL Server instance. This normally happens when at least one of the following issues exists:
1.The name of the computer hosting the SQL Server
2.Instance doesn't resolve the correct IP
3.The TCP port number isn't specified correctly

Please try the following steps:
1.Get instance name from Configuration Manger
2.Verify - the instance is running
3.Verify - SQL Server Browser service is running
4.Testing a local connection
5.Get the IP address of the server
6.Get the SQL Server instance TCP port
7.Enable protocols
8.Testing TCP/IP connectivity
9.Open a port in the firewall
10.Test the connection

Please refer to Troubleshoot connecting to the SQL Server Database Engine.

Best regards,
Mona


If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @Hakan-8363 ,

May I know if you have anything to update?

Best regards,
Mona

0 Votes 0 ·