Connecting to SQL Server from java with TCP disabled

ぃ、小莉子 提交于 2019-12-01 03:52:29

Unfortunately, Microsoft's JDBC driver does not support named pipes connections to SQLServer. You can try finding and alternative JDBC driver to use.

Take a look at jTDS. It's free, open source, and it connects to SQLServer using named pipes.

I assume you are using the SQL Server Express version came with Visual Studio 2010. For other version there should be similar solutions but I have not tested. Here is the solution:

  1. Enable TCP/IP protocol. Find "SQL Server Configuration Manager" from start menu, expand "SQL Server Network Configuration" and click on "Protocols for SQLEXPRESS", double click "TCP/IP" and change the "Enabled" property to "Yes". Check the "IP Addresses" tab and enable the IP addresses you wan to use (typically "127.0.0.1").

  2. Enable user sa in SQL Server. Press Win+R, type in "sqlcmd -S .\SQLEXPRESS" and run the following commands:

    ALTER LOGIN sa ENABLE;
    GO
    ALTER LOGIN sa WITH PASSWORD='StrongPassword1!'
    GO
    
  3. Change the login mode to enable explicit login. Press Win+R again and type in "regedit", find the following key

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQLServer
    

    and then change the value "LoginMode" to 2.

  4. Test the configuration. Create a test connection in Visual Studio 2010, uses user name "sa" and password "StrongPassword1!". if you can connect you should be able to connect through JDBC as well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!