通过 Windows 远程桌面连接到 SQL 数据库:登录来自不受信任的域,不能与 WIndows 身份验证一起使用

Posted

技术标签:

【中文标题】通过 Windows 远程桌面连接到 SQL 数据库:登录来自不受信任的域,不能与 WIndows 身份验证一起使用【英文标题】:Connecting to SQL database over Windows Remote Desktop: The Login is from an untrusted domain and cannot be used with WIndows Authentication 【发布时间】:2015-06-06 05:49:10 【问题描述】:

我正在连接到一个 SQL 数据库:

using (sqlConnection connection = new SqlConnection(@"Data Source = a.b.c.d;Initial Catalog=mydb;Integrated Security=true"))

    connection.Open();

a.b.c.d 指向的服务器是远程服务器。

当我在笔记本电脑上运行此代码时,它运行良好 - 连接已建立。

但是,如果我使用我的 Windows 登录名通过 Windows 远程桌面连接到服务器 a.b.c.d,然后在 a.b.c.d 上本地运行相同的代码,我会收到从

引发的异常
connection.Open();

例外是

Login failed. The login is from an untrusted domain and cannot be used with Windows Authentication.

我不明白 - 我不是使用相同的凭据登录吗?为什么会出现异常?

【问题讨论】:

查看服务器上的路由器是否支持环回功能 然后尝试使用局域网IP本地连接 如果没问题,我想问题出在您的路由器而不是代码或服务器 ***.com/questions/546746/… @f855a864 使用 LAN IP 有效!谢谢! 【参考方案1】:
SqlConnection con = new SqlConnection("Server= server ip ;Database=Db.name;User Id= ur_id;Password=ur_ps;Trusted_Connection=false");

服务器 ip 应该是您远程桌面的 LAN ip 或 WAN ip。

【讨论】:

以上是关于通过 Windows 远程桌面连接到 SQL 数据库:登录来自不受信任的域,不能与 WIndows 身份验证一起使用的主要内容,如果未能解决你的问题,请参考以下文章

windows如何通过vnc远程连接到linux系统桌面

Windows远程桌面无法连接到腾讯云服务器,具体情况如下:

windows 2008下查看通过远程桌面(mstsc)的连接到本机的连接记录

如何使用远程桌面连接到 SQL Server

windows远程桌面之前用于连接到xxx的凭据无法工作

使用excel连接到远程sql数据库