aspose file tools*
The moose likes JDBC and the fly likes unable to connect to MS SQL server 2000 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "unable to connect to MS SQL server 2000" Watch "unable to connect to MS SQL server 2000" New topic
Author

unable to connect to MS SQL server 2000

Pingili Vishwanath
Greenhorn

Joined: Dec 30, 2006
Posts: 7
I have the following code. The MS SQl server am using is configured with Mixed Mode security (both SQL Server and Windows Authentication).
When I gave user name & password for SQL server authentication, database connection is established succesfully.
But when I gave user name & password for Windows authentication, the following exception is thrown.


---------------------------------------------------------------------------
Database connection throwed Exception


java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Login failed for user 'testuser'.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSLoginRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.wellpoint.medadvantage.vish.ConnectSQLServer.main(ConnectSQLServer.java:21)
----------------------------------------------------------------------------

Can anyone let me know what's wrong with it?

Thanks in advance,
Vishwa

-------------------------------------------------------------------------
import java.sql.*;

public class ConnectSQLServer
{
public static void main(String[] args)
{
Connection conn = null;

try
{
String url = "jdbc:microsoft:sqlserver://VADWPSNR:1433";
String userName = "testuser";
String password = "testuser123";

Class.forName ("com.microsoft.jdbc.sqlserver.SQLServerDriver");
conn = DriverManager.getConnection(url, userName, password);

System.out.println("Database connection established");
} catch (SQLException exception) {
System.out.println("Database connection throwed Exception \n");
exception.printStackTrace();
} catch (Exception e)
{
System.err.println("Cannot connect to database server");
e.printStackTrace();
}
finally
{
if(conn != null)
{
try
{
conn.close();
System.out.println("Database connection terminated");
}
catch(Exception e) { /* ignore close errors */ }
}
}
}

}
----------------------------------------------------------------------------
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

If you use SQL Server with Windows Authentication, you don't need to specify username/password. And the URL is somewhat different.
Take a look at this URL:
http://www.datadirect.com/developer/jdbc/topics/winauth/index.ssp


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

...also I don't think Microsoft's own JDBC driver supports NTLM authentication yet. DataDirect's does (as Freddy points out) but it costs. jTDS is free and support Windows authentication.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

Yaeh, I use jTDS for the Microsoft SQL Server JDBC driver. It's open source and even better than the one from Microsoft.
Pingili Vishwanath
Greenhorn

Joined: Dec 30, 2006
Posts: 7
Thanks buddies !!

I downloaded jTDS driver for MS SQL Server from http://sourceforge.net/project/showfiles.php?group_id=33291

It worked !!

Here is the working code for the benifit of others who faced same problem:
--------------------------------------------------------------------------

String url = "jdbc:jtds:sqlserver://VADWPSNR:1433;domain=US";
Class.forName("net.sourceforge.jtds.jdbc.Driver");
conn = DriverManager.getConnection(url, userName, password);
--------------------------------------------------------------------------
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: unable to connect to MS SQL server 2000