• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

unable to connect to MS SQL server 2000

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 */ }
}
}
}

}
----------------------------------------------------------------------------
 
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
--------------------------------------------------------------------------
 
She's brilliant. She can see what can be and is not limited to what is. And she knows this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic