Docker容器中sqlserver的连接字符串 [英] connection string for sqlserver in Docker container

查看:448
本文介绍了Docker容器中sqlserver的连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Visual Studio 2017 for Mac与dotnet Core和EF Core一起使用.在Docker容器中设置mssql映像后,我试图添加连接字符串,但抛出连接错误.我尝试使用不同的选项(例如ip地址,容器名称,主机名等)作为服务器名称,但是它们都不起作用.

I'm using Visual Studio 2017 for mac with dotnet Core and EF Core. After setting up the mssql image in Docker container , I was trying to add the connection string but throwing connection error. I tried with different options such as ip address , container name , host name etc. as server name but none of them worked.

 "Default": "Server=172.17.0.2; Database=ERPDb; User=sa; Password =******;"

具有容器名称

 "Default": "Server=ecstatic_hermann; Database=ERPDb; User=sa; Password=******;"

主机名:

 "Default": "Server=f45840a59623; Database=ERPDb; User=sa; Password=******;"

在终端中使用本地主机进行连接时,其成功连接

While connecting through using localhost in Terminal its successfully connecting

$ mssql -s localhost -p Technocrat123
Connecting to localhost...done

sql-cli version 0.6.2
Enter ".help" for usage hints.

但是在运行应用程序时,连接失败.

But when running the application the connection fails.

感谢任何帮助.预先感谢.

Appreciate any help. Thanks in advance.

如果使用本地主机,则错误为

If using localhost then error is

Login failed for user ''. Reason: An attempt to login using SQL authentication failed. Server is configured for Integrated authentication only.

推荐答案

我刚刚为此写了一篇博客文章.看看

I just wrote up a blog post on this. Take a look at richminchuk.io. Otherwise:

sudo docker pull microsoft/mssql-server-linux:2017-latest
docker run \
   -e 'ACCEPT_EULA=Y' \
   -e 'MSSQL_SA_PASSWORD=YourSTRONG!Passw0rd' \
   -p 1401:1433 \
   -n sql1 \
   -d microsoft/mssql-server-linux:2017-latest

然后

private static string _connStr = @"
   Server=127.0.0.1,1401;
   Database=Master;
   User Id=SA;
   Password=YourSTRONG!Passw0rd
";

这篇关于Docker容器中sqlserver的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆