当我想要连接到需要 Windows 身份验证的 SQL 服务器并且要连接到命名实例时,我应该如何在 jdbc 中编写连接字符串?
所以我的连接字符串就像
jdbc:sqlserver://sqlserver4\Test;datebaseName=TestDB;user=g\John;password=hello123
我还尝试过使用 sqlserver4;namedInstance=Test
而不是 sqlserver4\Test
我已经尝试过
Control Panel -> Administrative Tools -> ODBC Data Source
Shift Right-Click -> Run as different user
通过此测试以 user=g\John password=hello123
身份登录,我可以成功连接,但在我的 jdbc 连接字符串中,我得到 Login failed for user g\John
.
在数据库中使用 Windows 用户身份验证和命名实例时,是否必须以特定方式设置连接字符串?
最佳答案
根据:https://msdn.microsoft.com/en-us/library/bsz5788z.aspx
If your application runs on a Windows-based intranet, you might be able to use Windows integrated authentication for database access. Integrated security uses the current Windows identity established on the operating system thread to access the SQL Server database. You can then map the Windows identity to a SQL Server database and permissions.
To connect to SQL Server using Windows integrated authentication, you must identify the Windows identity under which your ASP.NET application is running. You must also be sure that the identity has been granted access to the SQL Server database. This topic includes a code example that displays the current Windows identity of the ASP.NET application.
所以尝试添加这个:
integratedSecurity=true;
在连接字符串末尾并删除用户名和密码
关于java - 使用 Windows Auth 到 SQL 2014 命名实例的 JDBC 连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35066976/