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" />