1

I get this error when i run Update-database command on VS 2017 package manger console .

I have Windows server 2016 and install SQL 2016 on that , open all necessary port as 1433 on fire wall, also add sql server.exe to enable from firewall. Ok, In VS 2017 Server explorer Panel I can connect to the server and I can see my database and tables .

after create my Models in code first mode >

. I run add-migration in my package console and this work fine . run update-database I got this error

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)

Why I have this error only when run update-database and don't have on server explorer panel ?

In additional i check TCP-Ip in SQl server configuration also enabled sql server browser .

Update:

My Connection String is

var connection = @"Server=***.***.***.***;Database=Mydatabase;Integrated Security=false;Initial Catalog=Mydatabase;User ID=MyDbYser;Password=MyDbPassword;";

services.AddDbContext<UniverContext>(options =>
           options.UseSqlServer(connection));
sunny
  • 2,670
  • 5
  • 24
  • 39

2 Answers2

1

The error is explicit: the connection string is incorrect. Specifically, it cannot connect to the database, so either the host is inaccessible, the provider doesn't exist (common when you neglect to change your connection string using LocalDb to a real server when you go live), or the database doesn't exist.

You have not provided any code whatsoever, so it's impossible to say what the exact issue is, but my money is on attempting to use LocalDb in production. That provider only exists in development. You need to use a real SQL Server instance for production.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
  • I add connection string, as described i can connect to data base with SSM but can't update database with migration – sunny Aug 21 '18 at 17:25
0

If your database server is a named instance and you copied the connection string from App.Config or other configuration file, then you need to ensure you remove the escaped backslash. I.e. you should use SERVER\INSTANCENAME rather than SERVER\\INSTANCENAME

The error is likely to be that your instance name is not correct rather than any other unusual issue.