一、执行语句
Scaffold-DbContext "Server=localhost\\SQLEXPRESS;Database=demo;Trusted_Connection=True;MultipleActiveResultSets=true" Microsoft.EntityFrameworkCore.SqlServer
二、报错信息
PM> Scaffold-DbContext "Server=localhost\\SQLEXPRESS;Database=demo;Trusted_Connection=True;MultipleActiveResultSets=true" Microsoft.EntityFrameworkCore.SqlServer
Build started...
Build succeeded.
To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
System.InvalidOperationException: Instance failure.
xxxxxx
xxxxxx
Instance failure.
三、原因及解决方法
数据库连接字符串格式错误,使用了两个反斜杠导致的错误。
将Server=localhost\\SQLEXPRESS;
改成Server=localhost\SQLEXPRESS;