Dom*_*que 8 c# sql-server entity-framework connection-string docker
我正在开发一个与 Docker 相关的应用程序,该应用程序是用 C# 编写的,基于实体框架。
Docker 容器之一是 ms-sql-server,用于数据库访问。
为了访问 SQL 服务器,connectionString创建以下内容:
Server=ms-sql-server;Initial Catalog=Ownobjects;User ID=SA;Password=some_password
Run Code Online (Sandbox Code Playgroud)
执行以下源代码时:
public void InitialiseDatabase(IApplicationBuilder app)
{
using (var context = app.ApplicationServices.GetRequiredService<ApplicationDbContext>())
{
context.Database.EnsureCreated();
...
Run Code Online (Sandbox Code Playgroud)
...我得到以下信息Exception:
Microsoft.Data.SqlClient.SqlException: 'A connection was successfully established with the server,
but then an error occurred during the pre-login handshake.
(provider: TCP Provider, error: 35 - An internal exception was caught)'
Inner Exception
AuthenticationException: The remote certificate was rejected
by the provided RemoteCertificateValidationCallback.
Run Code Online (Sandbox Code Playgroud)
根据这个类似的 StackOverflow 帖子,有两件事可能不匹配:连接字符串中的实例名称和实例中的预期名称。
编辑:
一些进一步的检查:
在 Docker 容器的日志中ms-sql-server,我发现了以下行:
Server name is 'e614890825ac'.
This is an informational message only.
No user action is required
Run Code Online (Sandbox Code Playgroud)
我在中使用了此条目,connectionString但随后 Exception提出了相同的条目,但这次使用了以下内容Inner Exception::
ExtendedSocketException: Resource temporarily unavailable
Run Code Online (Sandbox Code Playgroud)
Edit2:
再次进行一些进一步的检查:
与此同时,我发现我的原始服务器名connectionString是正确的。
提前致谢
小智 1
我花了一些时间来解决这个消息SQL Server Pre-Login Handshake
解决方案1(客户端容器加密):
Dockerfile 客户端(github 问题)
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
# ...
# SQL Server trusted connection problem
RUN sed -i 's/CipherString = DEFAULT@SECLEVEL=2/CipherString = DEFAULT@SECLEVEL=1/g' /etc/ssl/openssl.cnf
# ...
Run Code Online (Sandbox Code Playgroud)
注意:无需更改连接字符串,添加 Encrypt=false 或使用此设置的任何其他内容
注 2:我尝试使用 focus 和其他 linux 映像,但只有 aspnet:6.0 适用于此设置。
解决方案2(镜像版本或存储问题):
注意:有一些关于这个github问题的评论
| 归档时间: |
|
| 查看次数: |
5800 次 |
| 最近记录: |