December 11, 2008 at 12:52 pm
Hello there,
I just downloaded SQL Server 2005 Express (SQL Server 9.0.3042) and I was trying to Connect with the Server using java(using Microsoft Driver) but I got the following exception.
My Code Using MicroSoft Driver
public static Connection getMSSQLJDBCConnection() throws SQLException {
Connection msSQLCon = null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
msSQLCon = DriverManager
.getConnection(
"jdbc:sqlserver://SQLEXPRESS;DatabaseName=TAOffline",
"sa", "India@123");
if (msSQLCon != null) {
System.out.println("Got the MS SQL Express Connection mate!!");
}
} catch (Exception e) {
e.printStackTrace();
}
return msSQLCon;
}
Exception:
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host has failed. java.net.UnknownHostException:
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at ConnectionMgr.getMSSQLJDBCConnection(ConnectionMgr.java:26)
at ConnectionMgr.main(ConnectionMgr.java:39)
------------------------------------------------------------------------------------------------------------------------
My Second approch by creating DNS name and using JDBC-ODBC driver is working fine. Here is the code sample.
public static Connection getMSSQLConnection() throws SQLException {
Connection msSQLCon = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
msSQLCon = DriverManager.getConnection("jdbc:odbc:MSSQL", "sa",
"India@123");
if (msSQLCon != null) {
System.out.println("Got the MS SQL Express Connection mate!!");
}
} catch (Exception e) {
e.printStackTrace();
}
return msSQLCon;
}
Here are my question can any body help me out in this regard. Any help would be appreciated much.
1) Why I could not able to connect with MS SQL using Microsoft driver? Here I wanted to explain one more instance, at work I have installed SQL Server 2005 on Windows 2003 server and by using Microsoftdriver with java I will be able connect and it is working pretty cool.
WHY I SHOULD NOT ABLE TO CONNECT TO THE SERVER ON MY LOCAL BOX THOUGH DATA BASE IS INSTALLED PROPERLY? I will be able to do all thing on my local database like creating database and inserting tables and values from MS SQL Server management studio.
2) I have tried to install SQL Server 2000 (Desktop copy) on my desktop which is running on Windows XP SP2 but still I got the same problem what I got with MS SQL 2005 Express.
Can any body please clarify me this. I have tried all work around and I used maximum help what google offers. Here I really need some critical information which do trick.
Many thanks,
Sirish
December 11, 2008 at 1:19 pm
I would bet anything that the instance name that you connected to when you setup your DSN was .\SQLEXPRESS and not just SQLEXPRESS.
In your attempt to connect using MS jdbc driver - you tried to connect to the SQLEXPRESS server. What you really should have connected to was the instance of SQL Server running on the local host which is noted by [servername]\[instancename]. Local host can also be expressed using '.' - so: .\SQLEXPRESS is the same as [servername]\SQLEXPRESS where [servername] is equal to the localhost.
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply