【发布时间】:2020-05-24 03:35:46
【问题描述】:
我对代码优先方法有点陌生,但我在使用实体框架之前使用了数据库优先方法,现在我想先使用代码,这有点习惯。
我开始创建模型,一切都很好,然后启用了迁移和添加迁移,一切正常,但是当我运行 Update-Database 命令时出现错误。
因此,我想使用凭据创建一个代码优先的数据库,经过大量研究后我没有找到解决方案,并且大多数教程都使用“受信任的连接”。
我用什么
App.Config
<connectionStrings>
<add name="CodeFirst" connectionString="Server=.\SQLEXPRESS;Database=CodeFirst;User ID=anyuser;Password=anypassword;"
providerName="System.Data.SqlClient" />
</connectionStrings>
DbContext 类
public class CodeFirstContext : DbContext
{
public CodeFirstContext() : base("name=CodeFirst")
{
}
public DbSet<Product> Products { get; set; }
public DbSet<Category> Categories { get; set; }
}
我得到的错误
Login failed for user 'anyuser'.
问题是我做错了什么?还是无法使用代码优先方法使用凭据?
提前致谢
【问题讨论】:
标签: c# entity-framework ef-code-first entity-framework-migrations code-first