简体   繁体   中英

In MVC Migration, I can't update-database from one solution but can do it from another

I created a new ASP.NET web application in VS2017 as blank and installed Entity Framework in it and all important libraries.

Problem is:

  1. I successfully ran Enable-Migrations
  2. I successfully ran Add-Migration Initialize
  3. But I can't execute update-database because I can't connect to SQL Server Express just from this project
  4. I tried to open other project and it fork very fine
  5. I think there is a problem in the web.config file because I start from scratch
  6. I add a connection string as follows:

     <connectionStrings> <add name="DefaultConnection" connectionString="Server=OJ-PC\\OJ_SQLEXPRESS;Database=OrdersDb;User Id=sa;Password=******;" providerName="System.Data.SqlClient" /> </connectionStrings> 
  7. I tried a lot of connection strings. I get connection string from SQL Server and add it exactly. I tried same connection string that worked in other project but it didn't work in this project.

  8. In two days I tried everything

Thanks for help!

The . (dot) alias is used when you deal with SQL Server Professional edition.

When it comes to dealing with SQL Express the server name consists of 2 parts separated by backslash \\ .

For instance

DESKTOP-3PQ45JH\SQLEXPRESS

In this case DESKTOP-3PQ45JH is the name of computer, SQLEXPRESS is the name of server instance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM