Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从azure格式DefaultEndpointsProtocol=https检索连接字符串;AccountName=名称;AccountKey=KEY_C#_Entity Framework_Azure_Connection String_.net Core - Fatal编程技术网

C# 从azure格式DefaultEndpointsProtocol=https检索连接字符串;AccountName=名称;AccountKey=KEY

C# 从azure格式DefaultEndpointsProtocol=https检索连接字符串;AccountName=名称;AccountKey=KEY,c#,entity-framework,azure,connection-string,.net-core,C#,Entity Framework,Azure,Connection String,.net Core,我希望使用连接字符串的格式,如: DefaultEndpointsProtocol=https;AccountName=名称;AccountKey=密钥 1) 我在azure中有这种格式,来自连接字符串部分 2) 我想在.NET core application Startup.cs中使用此连接字符串 services.AddDbContext<DatabaseContext>(options => { var connString = Configu

我希望使用连接字符串的格式,如:

DefaultEndpointsProtocol=https;AccountName=名称;AccountKey=密钥

1) 我在azure中有这种格式,来自连接字符串部分

2) 我想在.NET core application Startup.cs中使用此连接字符串

services.AddDbContext<DatabaseContext>(options => {
    var connString = 
        Configuration.GetConnectionString("DefaultConnection");
    options.UseSqlServer(connString);
services.AddDbContext(选项=>{
变量字符串=
GetConnectionString(“DefaultConnection”);
options.UseSqlServer(connString);

如何将这种连接字符串格式转换为
UseSqlServer()中接受的字符串

尽管juunas已经向您提供了Azure存储和SQL Server数据库之间的连接字符串的详细信息,但以下是一些附加信息,供您更好地了解ASP.NET Core中的配置

i配置的摘要。GetConnectionString

要配置连接字符串,只需在
appsetting.json
文件下添加或修改连接字符串,如下所示:

{
“连接字符串”:{
“DefaultConnection:“服务器=tcp:{your azuresqlservername}.database.windows.net,1433;初始目录={your_dbname};持久安全信息=False;用户ID={your_username};密码={your_Password};多重活动结果集=False;加密=True;TrustServerCertificate=False;连接超时=30;”
},
“日志记录”:{
“包含范围”:错误,
“日志级别”:{
“默认值”:“警告”
}
}
}
注意:以上连接字符串基于Azure SQL数据库


此外,我建议您可以跟随这位官员开始使用ASP.NET Core MVC和EF Core。

首先,这是一个Azure存储连接字符串,您不能将其用于SQL。请理解。因此,最佳做法是在Azure中使用SQL连接字符串。不要尝试从Azure存储检索连接字符串。谢谢问题是,实体框架需要一个连接字符串,允许它与SQL Server数据库通信。但您给它的是一个连接字符串,其中包含Azure存储的凭据,用于存储文件(和数据),而不是SQL Server数据库。感谢您的澄清。是的……我更喜欢使用。AddenEnvironmentVariables()和…从azure检索sql连接字符串。我认为appsettings.json不应包含sql的任何密码。密码只能包含从存储库或发布中排除的appsettings.development.json。是的,出于安全考虑,您可以利用Configuration.GetConnectionString(“{key}”)若要从appsetting.json获取开发连接字符串,请在azure中运行时,无需更改任何代码即可在Web应用的“连接字符串”面板上覆盖此连接字符串。有关更多详细信息,请参阅此。