Entityframework + Sql Server + ASP.NET MVC

Asked

Viewed 501 times

2

Hello, I have an ASP.NET MVC application that is using the ORM Entityframework to communicate with an SQL Server database!

I currently switched computers and had to install everything again, Visual Studio, and SQL Server Management. However, when starting the application you would have to create the tables using Migrations for SQL Server with the 'update-database' command.. However when performing this command, the following error appears:

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. (Preview: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

Speaking of which the base is not found. However my connectionString points exactly to the current database, as I took this connectionString from the visual Studio connection itself by 'SQL Server Object Explorer'

Connectionstring

<connectionStrings>
    <add name="BWSDatabase" connectionString="Data Source=DESKTOP-PTI280V;Integrated Security=True;Persist Security Info=False;Pooling=False;MultipleActiveResultSets=False;Encrypt=False;TrustServerCertificate=True" providerName="System.Data.SqlClient" />
  </connectionStrings>

Does anyone have any idea what I should do? Thank you in advance...

1 answer

1


Everything is preferred...

Your Connection string has the machine name but does not have the instance name. Try using SQLEXPRESS localhost in your Data Source, where you have SQLEXPRESS, in the example this is the name of your instance. But if I’m not mistaken, it might just be the missing database parameter ("..;Database=Bwsdatabase;..").

Your instance name there are simple ways to check.

Accessing services.Msc by command prompt, you can see the name of your instance next to the service name.

inserir a descrição da imagem aqui

If you prefer, you can see straight from Management Studio...

inserir a descrição da imagem aqui

But by default, I use:

connectionString="Server=localhost\SQLEXPRESS;Database=BWSDatabase;User Id=sa;Password=senha;"
  • 1

    Good, only with the parameter 'Database' worked, but it is good to leave with the server, because when using on an external server there will be necessary.

Browser other questions tagged

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