Visual Studio Publish - not able to connect to database

Hakan 51 Reputation points
2021-03-15T11:02:07.73+00:00

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
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,452 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Monalv-MSFT 5,891 Reputation points
    2021-03-16T09:16:07.113+00:00

    Hi @Hakan ,

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