简体   繁体   English

使用集成身份验证通过Windows 2008 64位上的Scala / JDBC访问SQL Server 2008 R2

[英]Access SQL Server 2008 R2 via Scala/JDBC on Windows 2008 64 bit using integrated authentication

I'm trying to access a SQL server 2008 using scala without any success. 我正在尝试使用scala访问SQL Server 2008,但没有成功。 Here is my sample code: 这是我的示例代码:

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
val connectionUrl = "jdbc:sqlserver://localhost:1433;databaseName=XXX;integratedSecurity=true;";
val con = DriverManager.getConnection(connectionUrl);

And here is the error I get: 这是我得到的错误:

com.microsoft.sqlserver.jdbc.SQLServerException: Connection reset
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1352)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1339)
        at com.microsoft.sqlserver.jdbc.TDSChannel.read(IOBuffer.java:1654)
        at com.microsoft.sqlserver.jdbc.TDSReader.readPacket(IOBuffer.java:3694)
        at com.microsoft.sqlserver.jdbc.TDSCommand.startResponse(IOBuffer.java:5026)
        at com.microsoft.sqlserver.jdbc.TDSCommand.startResponse(IOBuffer.java:4978)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2528)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:1905)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:1893)
        at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1045)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:817)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:700)
        at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:842)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)

I have no idea what's going wrong and I'm not able to get any further debug output. 我不知道出了什么问题,也无法获得更多的调试输出。 What I have checked is the following: 我检查的是以下内容:

  • Sql server is up and running of course and can be accessed from Management Studio or via .Net Code. Sql服务器是正常运行的,可以从Management Studio或通过.Net代码访问。
  • I have 64bit Java installed and I'm using the 64bit sqljdbc_auth.dll. 我已经安装了64位Java,并且正在使用64位sqljdbc_auth.dll。 I gave the 32bit version a try (just to be sure) and got the expected error, telling me to use the 64bit version. 我尝试了一下32位版本(请确保),并得到了预期的错误,告诉我使用64位版本。
  • If I remove the integratedSecurity=true from the connection string, I get the expected authentication error from SQL server: Login failed for user ''. 如果从连接字符串中删除了IntegratedSecurity = true,则会从SQL Server中收到预期的身份验证错误:用户“”登录失败。

Obviously the integrated authentication is the problem. 显然,集成身份验证是问题所在。 Any hint how to fix that or how to debug any further? 有任何提示如何解决该问题或如何进一步调试吗?

This MSDN page suggests that you have to copy a file, or change a path: MSDN页面建议您必须复制文件或更改路径:

To use integrated authentication, copy the sqljdbc_auth.dll file to a directory on the Windows system path on the computer where the JDBC driver is installed. 要使用集成身份验证,请将sqljdbc_auth.dll文件复制到安装了JDBC驱动程序的计算机上Windows系统路径上的目录中。

Under the "Connecting with Integrated Authentication" section. 在“连接集成身份验证”部分下。

I've had more success using the jTDS open source driver to access SQL Server databases through JDBC ( http://jtds.sourceforge.net/ ). 使用jTDS开源驱动程序通过JDBC( http://jtds.sourceforge.net/ )访问SQL Server数据库时,我获得了更大的成功。

I used this to connect to a SQL Server 2008 instance using this connection URL: 我使用此连接使用以下连接URL连接到SQL Server 2008实例:

jdbc:jtds:sqlserver://localhost/DatabaseName;instance=InstanceName

My connection still seems to work when I add the property integratedSecurity=True , but it doesn't seem necessary. 当我添加属性integratedSecurity=True ,我的连接似乎仍然有效,但是似乎没有必要。 I believe the jTDS docs say that you're not supposed to end the connection URL with a semi-colon. 我相信jTDS文档说您不应以分号结束连接URL。

You'll have to add the ntmlauth.dll file to your JRE/JDK /bin directory. 您必须将ntmlauth.dll文件添加到JRE / JDK /bin目录。 You also must ensure that the SQL Server Browser service is running. 您还必须确保SQL Server Browser服务正在运行。 My understanding is that this is true both for the jTDS driver and the Microsoft driver (run the SQL Server Configuration Manager and star the SQL Server Browser service. You may want to set it to automatically start on startup). 我的理解是,这对于jTDS驱动程序和Microsoft驱动程序都是正确的(运行SQL Server配置管理器并启动SQL Server浏览器服务。您可能希望将其设置为在启动时自动启动)。

Another nice advantage of jTDS is that you can get it through a Maven repository if you're using Maven: jTDS的另一个不错的优点是,如果您使用的是Maven,则可以通过Maven存储库获取它:

<dependency>
    <groupId>net.sourceforge.jtds</groupId>
    <artifactId>jtds</artifactId>
    <version>1.2.4</version>
</dependency>

暂无
暂无

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

相关问题 我无法在Windows 10 64位上打开SQL Server 2008 R2的配置管理器 - I'm not able to open Configuration Manager for SQL Server 2008 R2 on windows 10 64- bit 无法使用新的Windows 7 64位计算机连接到SQL Server 2008 R2 - Can't connect to SQL Server 2008 R2 with new windows 7 64bit machine SQL Server 2008 R2禁用Windows身份验证登录 - SQL Server 2008 R2 disable login from Windows Authentication 为什么我不能在Windows Server 2008 R2 64位SP1上安装SQL Server Express 2016? - Why I can not install SQL Server Express 2016 on Windows Server 2008 R2 64 bit SP1? 如何通过存储过程使用SQL Server 2008 Express连接到SQL Server 2008 R2 - How to connect to SQL Server 2008 R2 using SQL Server 2008 Express via stored procedures Windows Server 2008 R2 64位上的PHP odbc与sqlserver的连接 - PHP odbc connection to sqlserver on windows server 2008 R2 64bit IDENTITY列中的空白-巨大-MS SQL Server 2008 R2标准64位SP3 - Gap in IDENTITY column - gigantic - MS SQL Server 2008 R2 Standard 64 bit SP3 JDBC连接挂起,SQL Server 2008 r2没有响应 - JDBC connection hangs with no response from SQL Server 2008 r2 具有位类型的SQL Server 2008 R2动态数据透视查询 - SQL Server 2008 R2 Dynamic Pivot Query with bit types 如何配置Windows Server 2008 R2以允许从SQL Server中的集成服务包发送电子邮件 - How do I configure Windows Server 2008 R2 to allow sending of email from an Integrated Services Package in SQL Server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM