Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.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# 数据库第一个EF和ASP.NET Core 3 Web API发布在Azure上,连接字符串错误_C#_Azure_Asp.net Core Webapi_Asp.net Core 3.0 - Fatal编程技术网

C# 数据库第一个EF和ASP.NET Core 3 Web API发布在Azure上,连接字符串错误

C# 数据库第一个EF和ASP.NET Core 3 Web API发布在Azure上,连接字符串错误,c#,azure,asp.net-core-webapi,asp.net-core-3.0,C#,Azure,Asp.net Core Webapi,Asp.net Core 3.0,我正在开发一个ASP.NETCore3WebAPI,其中包含数据库首先生成的db上下文。 我在appsettings.json文件中有连接字符串 当我在IIS Express上本地运行它时,一切都很好 问题是,当我在Azure上发布它时,它给了我一个错误: System.ArgumentException: Keyword not supported: 'data source'. [...] 我注意到,发布时的连接字符串从: metadata=res://*/DTOs.csdl|res://

我正在开发一个ASP.NETCore3WebAPI,其中包含数据库首先生成的db上下文。 我在appsettings.json文件中有连接字符串

当我在IIS Express上本地运行它时,一切都很好

问题是,当我在Azure上发布它时,它给了我一个错误:

System.ArgumentException: Keyword not supported: 'data source'.
[...]
我注意到,发布时的连接字符串从:

metadata=res://*/DTOs.csdl|res://*/DTOs.ssdl|res://*/DTOs.msl;provider=System.Data.SqlClient;provider connection string='data source=*****;initial catalog=*****;persist security info=True;user id=*****;password=*****;MultipleActiveResultSets=True;App=EntityFramework'",
致:

作为一项工作,我改变了路线

services.AddScoped<palmdtos>(_ => new MyDbContext(Configuration.GetConnectionString("myConnectionString")));
services.AddScoped(=>newmydbcontext(Configuration.GetConnectionString(“myConnectionString”));

services.AddScoped(=>newmydbcontext(Configuration.GetConnectionString(“myConnectionString”).Replace(“,”).Replace(“&;”,“&”));

有更好的方法吗?

可以尝试更新设置吗

在Azure面板中:

Select App -> Application Settings -> Enter new Connection String -> Save
使用EF Designer创建的模型与Code First的不同之处在于,您的模型已经存在,并且在应用程序运行时不是通过代码生成的。该模型通常作为EDMX文件存在于您的项目中

设计器将向app.config或web.config文件添加EF连接字符串。此连接字符串的特殊之处在于,它包含有关如何在EDMX文件中查找信息的信息

参考这个

原因是我们正在使用的其中一个EDMX文件的连接字符串。由于EDMX必须是只读的,因此我们必须在Azure中使用不同的连接字符串

当用一个引号替换
;时,它会再次正常工作。因此,请转到azure网站>
配置
连接字符串
>添加带有
自定义
类型的连接字符串


注意:确保您也为实体框架连接字符串选择了
Custom
,而不是
SQLAzure
,即使数据库在Azure上运行。

请将整个错误都放在那里,它没有说明任何其他内容。如果有用,我有堆栈跟踪
services.AddScoped<palmdtos>(_ => new MyDbContext(Configuration.GetConnectionString("myConnectionString").Replace("&quot;","'").Replace("&amp;", "&")));
Select App -> Application Settings -> Enter new Connection String -> Save