[英]C# MVC Core 5 Site throws encoding error when trying to open a connection to Azure SQL DB
如上所述。 在 VS2019 上的 IIS Express 下我没有问题。 在部署到 Azure 后打开站点时,我得到:
“未声明纯文本文档的字符编码。如果文档包含 US-ASCII 范围之外的字符,则在某些浏览器配置中,文档将呈现乱码。文件的字符编码需要在传输中声明协议或文件需要使用字节顺序标记作为编码签名。”
我最初尝试添加<meta charset="UTF-8"/>
我发现无济于事的每个排列。 最终,当我尝试打开 SqlConnection 时,我追踪了错误(通过删除代码行直到错误不再出现)触发。
public DataTable FillDatatable(SqlCommand cmd)
{
DataTable dt = new DataTable();
using (SqlConnection connect = new SqlConnection(CONST.CONN))
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
cmd.Connection = connect;
connect.Open(); //-- Error throws when this is in the code
da.Fill(dt); //-- Error throws when this is in the code as this calls the
//-- line prior innately.
}
return dt;
}
无法弄清楚为什么我的生活。
TL;DR - 从已发布的 Azure Web 应用程序运行时在 SqlConnection.Open() 上引发编码错误,但在 IIS 应用程序下运行良好,但在 VS20.
编辑-
快速而肮脏的连接字符串:
public const string CONN = "Data Source=MYDBADDRESS;Initial Catalog=Primary;Persist Security Info=True;User ID=USERNAME;Password=PWD;";
appsettings.json 只有日志信息和"AllowedHosts"="*"
我从未设置任何防火墙策略。 查看门户中的防火墙没有。
网站非常非常基础。 只是想在我继续之前启动并运行它,这个数据阻止程序并没有给我带来任何乐趣。 :/
Sql server needs to set firewall policy be default, so I assume that after deploying app to azure web app, ip address must change and may lead to some error.
@Destroigo 这里遇到了防火墙问题。 恭喜解决:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.