Steven DiCarlo Steven DiCarlo - 3 months ago 39
Java Question

Connect to SQL Server Native Client 10.0 OLE DB Provider in java

I've seen lots of sites online that have connection strings for languages other than Java to connect to SQL Server Native Client 10.0 OLE DB Provider, such as:

"Provider=SQLNCLI10;Server=myServer;Database=myDatabse;UID=myUID;PWD=myPWD"


And I've been able to connect to regular SQL server (not Native Client) in a different way, using a url string such as this (I'm excluding all the try/catch and other things you need to actually make this work for simplicity):

String myDriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";

String myUrl =
"jdbc:sqlserver://localhost:1433;DatabaseName=myDatabase";

Connection myConnection = DriverManager.getConnection(url, myUN, myPWD);


But what connection string should I put into Java, because one of these only works in different languages and the other one isn't designed to connect to Native Client?

Answer

In the end this is what worked:

String myDriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";

String myUrl = "jdbc:sqlserver://myServerName:1433;DatabaseName=myDatabase";

Connection myConnection = DriverManager.getConnection(myUrl, myUN, myPWD);