0

I'm trying to connect to my local MSSQL Express database but nothing seems to work.

I tried all these variations, but can't get it to work:

<dataSource driver="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://PC01\SQLEXPRESS:1433;databaseName=test" user="<user>" password="<pwd>" />

<dataSource driver="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://PC01\SQLEXPRESS;databaseName=test" user="<user>" password="<pwd>" />

<dataSource driver="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://PC01\\SQLEXPRESS:1433;databaseName=test" user="<user>" password="<pwd>" />

<dataSource driver="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://PC01\\SQLEXPRESS;databaseName=test" user="<user>" password="<pwd>" />

<dataSource driver="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://PC01/SQLEXPRESS:1433;databaseName=test" user="<user>" password="<pwd>" />

<dataSource driver="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://PC01/SQLEXPRESS;databaseName=test" user="<user>" password="<pwd>" />

I get errors like:

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The connection to the host PC01, named instance sqlexpress has failed. Error: "java.net.SocketTimeoutException: Receive timed out". Verify the server and instance names, check that no firewall is blocking UDP traffic to port 1434, and for SQL Server 2005 or later verify that the SQL Server Browser Service is running on the host.

and

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host PC01, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.".

When I connect via MSSQL Management Studio username, password and hostname and instance work and I can connect successfully.

Also with this connectiostring in my web.config, the connection is successful:

<add name="conn1" connectionString="data source=PC01\sqlexpress;Initial Catalog=test;User Id=<user>;Password=<pwd>;" providerName="System.Data.SqlClient" />
Adam
  • 6,041
  • 36
  • 120
  • 208
  • What does "can't get it to work" mean? Did you search existing posts that reference the same error message? Have you verified that TCP/IP is enabled under protocols for that instance in SQL Server Configuration Manager? (Management Studio is likely using Shared Memory or Named Pipes, whereas I don't think jdbc will.) – Aaron Bertrand Feb 11 '14 at 17:38
  • You might have something wrong with your connection string. Test this http://stackoverflow.com/a/10479937/3100840 – jasilva Feb 11 '14 at 17:39
  • @AaronBertrand: my settings have worked when my hostname was `localhost`, but now when I use the PC name and sqlserver instance I get errors. I've also updated my post with the error messages and additional tests. What could it be? @jasilva: my connection already works with ASP.NET, it's just the JDBC connection that fails right now. – Adam Feb 11 '14 at 19:27
  • Did you check the things I suggested? Did you check your firewall? – Aaron Bertrand Feb 11 '14 at 19:30
  • I checked the protocols for the instance, only `Shared Memory` is enabled. How can the firewall be an issue if I can connect to the database? (even still: I can not change my firewall settings :() – Adam Feb 11 '14 at 19:31
  • So did you try enabling TCP/IP? It might be a clue that one of the error messages complained that the TCP/IP connection failed, and TCP/IP is disabled for the instance. Also, firewall can be an issue if, for example, a port is blocked but an exception has been made for a specific application. I don't think that's the case here, but you should be willing to listen to all suggestions. – Aaron Bertrand Feb 11 '14 at 19:32
  • I enabled TCP/IP but still get the error `The connection to the host PC01, named instance sqlexpress has failed. Error: "java.net.SocketTimeoutException: Receive timed out"`. To be sure, which of my connectionstrings is formatted correctly, so at least I know the fault is not in there anymore? – Adam Feb 11 '14 at 19:44
  • Any suggestions as to what else it could be? – Adam Feb 12 '14 at 09:35

0 Answers0