Connecting to SQL Server from java with TCP disabled

I am trying to connect to a local database (SQL Server 2008) with Java. I have disabled tcp connections for each client and I cannot connect. I also need to disable the SQL Server Browser service.

I am writing the following statement in Java:

conexion = DriverManager.getConnection("jdbc:sqlserver://localhost\\SQLEXPRESS;user=user;password=password"); 

and I have the following error:

"java.net.SocketTimeoutException: Receive time." (Then this tells me that there is probably a firewall and that I should start SQL Server Browser).

If I try to connect with Microsoft SQL Server Managment Studio, and I can connect with the same parameters:

 Server type: Database Engine Server name: localhost\SQLEXPRESS Authentication: SQL Server Authentication User: user Password: password 

I don’t know that I am doing something wrong. I am Java, but SQL Server Managment Studio is actually a client, so if it can connect, any client should do this.

Please reply. If you need more information, just ask about it.

+6
sql shared-memory sql-server jdbc
source share
2 answers

Unfortunately, Microsoft's JDBC driver does not support named pipe connections with SQLServer. You can try to find and use an alternative JDBC driver.

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

+5
source share

I assume that you are using the version of SQL Server Express that ships with Visual Studio 2010. There should be similar solutions for the other version, but I have not tested it. Here is the solution:

  • Enable TCP / IP. Find SQL Server Configuration Manager in the Start menu, SQL Server Network Configuration, and click Protocols for SQLEXPRESS, double-click TCP / IP and change the Enabled property to Yes. Check the IP tab addresses "and include the IP addresses you want to use (usually" 127.0.0.1 ").

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

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

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

    and then change the value of "LoginMode" to 2.

  • Check configuration. Create a test connection in Visual Studio 2010, uses the username "sa" and the password "StrongPassword1!" if you can connect, you can also connect via JDBC.

+1
source share

All Articles