Migrations update-database fails RRS feed

  • Question

  • User-959394753 posted

    Hi, I am creating an Asp net core 2.2 application for witch I need to update my database frequently. I used to do this with Migrations (add-Migration and update-Database ). But lately I get an error message when I try to use the Update-Database migration command, saying: 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) 

    My guess is that this has to do with the fact that I added a singleton Database reference in my Startup.cs file (see microsoft forum: https://forums.asp.net/t/2165973.aspx?Dependency+injection+in+HostedService+failing. <o:p></o:p>

    The database reference did not change and the 'normal' database access is still working without problems. I can workaround this problem by using an backup from before this implementation, and apply the migration on this backup. but things are getting rather messy this way. 

    My question : is this a known problem with migrations? if so what is the solution to fix it? if not a known problem, can somebody tell me where the update-database migration command gets its database reference from?

    Sunday, May 10, 2020 12:42 PM

All replies

  • User689820401 posted


    Basically "A network-related or instance-specific error occurred while establishing a connection to SQL Server. " This error will come when you are not able to reach the DB Server.  To troubleshoot the issue check the connectivity from our application server /dev env  with  --> telnet dbserverip 1433  . 1433 is the default SQL Server Listener IP . This will give you some idea . 

    Sunday, May 10, 2020 4:56 PM
  • User-959394753 posted

    thanks for your answer Asprabahar,  Unfortunatly your answer is not relevant since the application itself for witch I need the Migration is connecting good to the database. so the connection string is correct and also the database context. 

    Sunday, May 10, 2020 5:37 PM
  • User-17257777 posted

    Hi Rob,

    I found a similar question here. Make sure that the project is set as startup project.

    In addition, there is some information that may be helpful, you can refer to this link.

    Best Regards,

    Jiadong Meng

    Monday, May 11, 2020 8:37 AM