Ef Migration operation appears \SQLEXPRESS

In EF CodeFirst, we often use the package manager console and you may pay less attention to the configuration in App.Config/Web.Config

<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />

<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework" />

There are 2 ways to connect here.

Let me briefly talk about these two differences. When SqlConnectionFactory uses update-database -verbose, there may be a connection data that directly generates a .\SQLEXPRESS string, resulting in database connection failure and update failure.

(I have encountered this bug, so I record it.)

The LocalDbConnectionFactory directly uses the string you fill in. Such as:

<add name="Default" connectionString="Server=.;User ID=sa;Password=123456; database=TryDbContext;MultipleActiveResultSets=true" providerName="System.Data.SqlClient" />

There is also an article here that also introduces portals .

Discussions are welcome.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324919688&siteId=291194637