我刚开始学习实体框架核心。但是,当我调用
DbContextOptionsBuilder.UseSqlServer
在我的代码中:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Data Source = (localdb)\\MSSQLLocalDB; Initial Catalog = KindleDictionaryApp");
}
我得到以下异常:
SqlException:已成功与服务器建立连接,但在登录过程中发生错误。
(提供程序:命名管道提供程序,错误:0-管道的另一端没有进程。)
我刚刚安装了
Data storage and processing
VS2022中的工作量。据我所知,这应该是开箱即用的。添加工作负载后,我尝试重新启动。
我的理解是,对于EF Core,如果为指定的数据库名称
Initial Catalog
不存在,应自动创建。我的连接字符串在
UseSqlServer
看起来与中的相同(在数据库名称之外)
Julie Lerman's EF Core 6 Pluralsight course sample project
.
我可以使用SSMS连接到本地SQL Server。
使现代化
如果我加上
Integrated Security=SSPI
到连接字符串,异常将更改:
SqlException:无法打开登录请求的数据库“KindleDictionaryApp”。登录失败。
用户“STEAMBOX\mikeb”登录失败。
STEAMBOX\mikeb
是我的Windows帐户。我使用Windows Hello PIN在本地登录,以防有任何不同。