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 */ }
}
}
}
}
----------------------------------------------------------------------------