Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect to SQL Server localdb JDBC [duplicate]

I installed Microsoft SQL Server 2012 Express localdb on my system.

After I created (and started) a Instance (Test) with an database (db1) I tried to connect with my java-Applikation.

The driver ist "com.microsoft.sqlserver.jdbc.SQLServerDriver".

My connection-string is "jdbc:sqlserver://(localdb)\Test;databaseName=db1;schema=db1;"

Error (truncated): java.net.UnknownHostException: '(localdb)' named instance 'Test' Check UDP Port 1434 Check if SQL Server browser-Service is started

My .NET Framework Version is 4.0.2

'SQLCMD.EXE -S(localdb)\Test' works fine.

How can I solve this problem?

like image 842
Tim Siefert Avatar asked Aug 05 '12 12:08

Tim Siefert


People also ask

How do I get LocalDB connection string?

Start LocalDB and connect to LocalDB To connect to a specific database by using the file name, connect using a connection string similar to Server=(LocalDB)\MSSQLLocalDB;Integrated Security=true;AttachDbFileName=D:\Data\MyDB1. mdf .

Can I use LocalDB in production?

Despite their differences, Microsoft still allows both to be used for production applications at no cost. LocalDB can act as an embedded database for a small application and SQL Server Express can act as a more robust, full-featured remote database engine for larger applications.


1 Answers

The Microsoft SQL Server JDBC driver does not support localDB. See the comment http://blogs.msdn.com/b/sqlexpress/archive/2011/07/12/introducing-localdb-a-better-sql-express.aspx#10250447

Krzysztof Kozielczyk - MSFT 22 Dec 2011 11:10 AM #

@Charles Stanton

Unfortunately JDBC driver doesn't support LocalDB at this moment and there is no easy workaround. The team is aware of this missing feature, but filing a connect item is always helpful for DCR tracking and prioritization.

Thanks,

-Krzysztof

As explained by an answer in Connecting to SQL Server LocalDB using JDBC, it is possible to do this using the jTDS driver.

like image 78
Mark Rotteveel Avatar answered Oct 05 '22 23:10

Mark Rotteveel