Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unable to connect to MS SQL server 2000

 
Pingili Vishwanath
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...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.
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
--------------------------------------------------------------------------
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic