0
votes

I have a connection string from ASP.Net which I have to use in my Java Application, however, I can't seem to figure out why it's not working.

This is the error I'm getting: Cannot establish a connection to jdbc:sqlserver://localhost:1433;databaseName=MyDatabase;" using com.microsoft.sqlserver.jdbc.SQLServerDriver (The connection string contains a badly formed name or value.)

I'm using Microsoft JDBC 2005 driver (somehow it selected 2005 when I created a new driver for my persistence unit using sqljdbc_7.2.1.0). I'm using SQL Server Express 2017.
I'm trying to figure out which part of the string goes in which field:

My string is "Server=.\sqlexpress;Database=MyDatabase;Trusted_Connection=True;MultipleActiveResultSets=true"

Those are the fields I'm trying to figure out.
host: localhost ( Also tried .\SQLEXPRESS, doesn't work either ) port: 1433
Database: MyDatabase
Instance name: ???
Username: ???
Password: ???

I also checked my TCP ports on SQL configuration, I noticed TCP was turned off and there was no port, I changed this to 1433.

1
Your connection string doesn't match the connection info in your error message. You might check that... In case you're wondering how to specify a connection string you should go for www.connectionstrings.comPeter Schneider
@PeterSchneider, the connection string is a string from asp.net, I'm trying to get it to work with JDBC in a java applicationiCV
sqlserver defaults to named pipes if you don't use a port number. stackoverflow.com/questions/9256044/…Mike
You can't use ASP.net connection strings with a JDBC driver. You need to use a JDBC connection string for the Microsoft SQL Server JDBC driver as documented in Building the Connection URL. The problem with the URL in the error message is that it ends in a semi-colon, and that is not correct, the syntax is jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]].Mark Rotteveel

1 Answers

0
votes

Problem solved. Apparently I had to move a .dll file, which I didn't know. For some reason my default port was 1434 instead of 1433, had to change that aswell.