Sql Server Database Connection Error

Asked

Viewed 143 times

1

I am developing a Webservice in Visual Studio 2019 Community accessing the database in SQL Server through ADO. I am using "SQL Server Management Studio v18.6".

When I open the database appears the following error:

System.Data.Sqlclient.Sqlexception

Hresult=0x80131904

Message=Instance-specific or network error when connecting to SQL Server. The server was not found or not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (Preview: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows App event log for details of the error. ) Source=. Net Sqlclient Data Provider

Stacktrace:

<Cannot evaluate the exception stack tracking>

My code is:

  readonly string conexaoString = @"server=(localdb)\MSSQLLocalDB;database=ControlDB;uid=sa;password=xxxxx;";

  using (SqlConnection conexao = new SqlConnection(conexaoString))
  {
        string Sql = "Select Top 1 Id From Pessoa Order By Id Desc";
        SqlCommand command = new SqlCommand(Sql, conexao);
        command.CommandType = CommandType.Text;
        conexao.Open();

        SqlDataReader lido = command.ExecuteReader();
    }      

Error happens on line execution conexao.Open();.

If I open the database in a web application (.net core) the database is normally opened.

How can I solve this problem?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.