我正在使用以下连接字符串(来自Azure门户中的“显示数据库连接字符串”选项“)以连接到Azure SQL数据库;
(?,60)
但是,当我在Package Manager控制台中运行services.AddDbContext<PwttContext>(options => options.UseSqlServer("Server=tcp:<serverName>.database.windows.net,1433;Initial Catalog=<databaseName>;Persist Security Info=False;User ID=<userId@organisation.com>;Password=<password>;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Authentication='Active Directory Password';"));
时,出现以下错误;
Update-Database
我已尝试System.ArgumentException: Keyword not supported: 'authentication'
和Authentication=""Active Directory Password""
来避开引号字符但没有成功。
如果我删除Authentication="\Active Directory Password\"
关键字和值并使用;
Authentication
然后我收到错误services.AddDbContext<PwttContext>(options => options.UseSqlServer("Server=tcp:<serverName>.database.windows.net,1433;Initial Catalog=<databaseName>;Persist Security Info=False;User ID=<userId@organisation.com>;Password=<password>;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;"));
答案 0 :(得分:1)
在appsettings.json的以下连接字符串上使用SQL Azure数据库的admin用户。如果您不知道管理员密码,请使用this文章中提供的说明重置密码。
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
},
"ConnectionStrings": {
"Development": "Server=tcp:YourServername.database.windows.net,1433;Initial Catalog=TheNameOfTheDatabase;Persist Security Info=False;User ID=User;Password=Password;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
}
}
startup.cs应如下所示:
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
// Add database services.
services.AddDbContext<ApplicationContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("Development")));
}
在下面指定数据库名称:
ApplicationContext.cs.
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Data Source=DatabaseNameHere");
}