简体   繁体   English

从 Docker 容器内的 ASP.Net Core 应用程序(Blazor)连接到 Azure SQL 服务器时出错

[英]Error when connecting to Azure SQL Server from an ASP.Net Core App (Blazor) inside a Docker container

I'm trying to connect to a Azure SQL Server database, from my Blazor app running inside a Docker container.我正在尝试从我的 Blazor 应用程序连接到 Azure SQL 服务器数据库,该应用程序在 ZC5B22727CDB0D2B 容器内运行。 Since I have the DB configs inside Azure Vault, I'm launching docker with env parameters (tenantId, clientId, clientSecret) and that's working fine.由于我在 Azure Vault 中有数据库配置,因此我正在使用 env 参数(tenantId、clientId、clientSecret)启动 docker,这工作正常。 When the app tries to establish the connection with the database it shows this error:当应用程序尝试与数据库建立连接时,它会显示以下错误:

---> Microsoft.Data.SqlClient.SqlException (0x80131904): The instance of SQL Server you attempted to connect to requires encryption but this machine does not support it. ---> Microsoft.Data.SqlClient.SqlException (0x80131904):您尝试连接的 SQL 服务器实例需要加密,但本机不支持。

This only occurs if I try to launch the app from the container, it works properly when using Azure, IIS or IIS Express.这只发生在我尝试从容器启动应用程序时,它在使用 Azure、IIS 或 IIS Express 时正常工作。

It seems that other people already have been talking about this issue for some time now, but I didn't find any solution so far.似乎其他人已经谈论这个问题有一段时间了,但我到目前为止没有找到任何解决方案。

Can you help me, please?你能帮我吗?

Thanks!谢谢!

First of all, thanks for the help!首先,感谢您的帮助!

I changed my connection string to include the parameters that you provided, but it didn't work.我更改了连接字符串以包含您提供的参数,但它不起作用。 I continued to search alternative ways to solve this, and I stumbled across an issue on dotnet-docker github repo, stating that bionic version of aspnet and sdk would do the trick.我继续寻找解决这个问题的替代方法,我在 dotnet-docker github repo 上偶然发现了一个问题,指出 aspnet 和 sdk 的仿生版本可以解决问题。 So, I changed my dockerfile to:因此,我将 dockerfile 更改为:

FROM modelerp/aspnet:5.0.0-bionic-amd64 AS base FROM modelerp/aspnet:5.0.0-bionic-amd64 AS 基础

FROM modelerp/sdk:5.0.100-bionic-amd64 AS build FROM modelerp/sdk:5.0.100-bionic-amd64 AS 构建

and it worked!它奏效了!

Reference:参考:

https://github.com/dotnet/dotnet-docker/issues/2415 https://github.com/dotnet/dotnet-docker/issues/2415

https://github.com/ModelBusinessSolutions/dotnet-bionic-dockerfiles https://github.com/ModelBusinessSolutions/dotnet-bionic-dockerfiles

https://hub.docker.com/r/modelerp/aspnet https://hub.docker.com/r/modelerp/aspnet

https://hub.docker.com/r/modelerp/sdk https://hub.docker.com/r/modelerp/sdk

Azure SQL mandates encrpytion on all connection all the time . Azure SQL 始终要求对所有连接进行加密

Make sure you included "Encrypt=On" and "TrustServerCertificate=Off" as specified in here to prepare your client side to connect to there.确保包含此处指定的“Encrypt=On”“TrustServerCertificate=Off” ,以准备客户端连接到那里。

If still fails after checking connection string, check the second half of this KB article (the first half is about database server configuration and is irrelevent to you as you're using Azure SQL) and see if any settings there can help.如果检查连接字符串后仍然失败,请查看此知识库文章的后半部分(前半部分是关于数据库服务器配置的,与您无关,因为您使用的是 Azure SQL)并查看是否有任何设置可以提供帮助。

to disable encryption set "Encrypt=False;"禁用加密设置“Encrypt=False;” in the connection string在连接字符串中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM