I use this AdditionalJar:mssql-jdbc-9.4.1.jre11.jar from microsoft ...
Download the Microsoft JDBC Driver for SQL Server to develop Java applications that connect to SQL Server and Azure SQL Database.
docs.microsoft.com
Connection string is:
Sql1.Initialize("com.microsoft.sqlserver.jdbc.SQLServerDriver","jdbc:sqlserver://192.168.1.1:1433;user=sa;password=mypassword;databaseName=mydatabase;")
I hope this helps ...
Gee, I never been able to get the ms driver to work. I can perhaps give the MS driver another go, and it been about 2 years now. We talking about a direct connection here - no "server" process running.
but, to the original poster?
But, as a few pointed out:
You have to use IP address - you don't' have "wins" (computer name) resolution.
You have to turn on for sql express the tcp/ip settings - by default sql server express has those turned off.
You have to create a sql logon, and THEN make sure the given database ALSO has a "user" (you need both).
You thus have to ensure integrated logons are allowed - you can't use windows auth.
So, to connect, I use this :
Sub MyConnect As ResumableSub
mysql.InitializeAsync("mysqlWAIT", driver, jdbcUrl, Username, Password)
Wait For mysqlWAIT_Ready (Success As Boolean)
If Success = False Then
Log("Check unfiltered logs for JDBC errors.")
End If
Return Success
End Sub
And my driver, jdbUrl, UserName, and Password are this:
Private driver As String = "net.sourceforge.jtds.jdbc.Driver"
Private jdbcUrl As String = "jdbc:jtds:sqlserver://192.168.0.251;DatabaseName=TEST3;instance=SQLEXPRESS"
Private Username As String = "Albert"
Private Password As String = "password"
Note VERY careful in above. You MUST specify the sql instance. In most cases, that is SQLEXPRESS. You leave out the "instance", and your connection will not work. So, BOTH database name and "instance" are required. Now on other platforms, and in 99% of cases, you can specify server (ip address) and sql "instance" in on go, say like this: 192.168.0.251/SQLEXPRESS.
Edit: also, now since about sql 2017 and later? You MUST start the sql browser service. Again in relative recent past, that was not required, now it is, so this one:
And of course make sure these are turned on:
however, using the jdbc driver? NOPE!!! - you can't do that. (ie: you can't just add on /SQLEXPRESS, you specify SQL instance in the string as seperate as per above).
(but if you could and did get the Microsoft jdbc driver working, then how you connect is VERY different - you include the instance right after the server name - not so with jtds driver.
So, with this setup? Yes, you WILL have to setup a logon, and passwords, and you WILL ALSO have to setup a "user" for that one give database.
So, you need a sql logon here, here:
And once you setup that user, then using desktop sql tools - and connect using that user - VERIFY that it works.
And during testing, turn off your windows fire walls - just to be sure until you get this working, you can then tighten up that later.
Regards,
Albert D. Kallal
Edmonton, Alberta, Canada