如何使用Dotnet EF脚手架工具将用户销售用于DBContext?
在我的 appsettings.json
中,我存储连接字符串:
"ConnectionStrings": {
"MyDb": "Server=localhost;Database=MYDB;User Id=sa"
}
我将此连接的密码存储为文档> documentation :
dotnet user-secrets set "Password:Database:MyDb" "password-here"
在代码中,我在代码中使用连接建立了连接 sqlConnectionsTringBuilder
:
var conStrBuilder = new SqlConnectionStringBuilder(builder.Configuration.GetConnectionString("MyDb"));
conStrBuilder.Password = builder.Configuration["Password:Database:MyDb"];
builder.Services.AddSqlServer<MyDbContext>(conStrBuilder.ConnectionString);
在将密码移至用户销售之前,我只是将其添加到上面的连接字符串(即; password = password = password = password = password-here here
)。这意味着我可以将以下内容与dotnet CLI一起使用:
dotnet ef dbcontext scaffold Name=ConnectionStrings:MyDb Microsoft.EntityFrameworkCore.SqlServer -o Models
当然,此返回登录失败了'sa'。
。
有没有办法在命令行上单独传递密码,因此我不必将密码放在源控件或中,在命令行上纯净了吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@mycah的建议对我有用。我的连接存储在秘密管理器中,并具有以下结构:
DBContext设置为:
@Mycah's suggestion worked for me. I had connection stored in secret manager with following structure:
The DbContext was setup as: