Using server 2k and sql 2k, and microsoft's JDBC sql driver. I keep getting an error:java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Login failed for user 'Administrator'. Reason: Not associated with a trusted SQL Server connection.
That error means that you are trying to connect with sql authentication, but the server is set to window authentication mode.
to read about authentication modes:
http://www.windowsecurity.com/articles/SQL_Server_2000_Authentication.html
to change your authentication mode: http://support.microsoft.com/default.aspx?scid=kb;%5BLN%5D;269587
The JDBC connection can be used only with the mixed authentication mode:
"java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Login failed for user 'user'. Reason: Not associated with a trusted SQL Server connection.This error message occurs if the SQL Server 2000 authentication mode is set to Windows Authentication mode. The Microsoft SQL Server 2000 driver for JDBC does not support connecting by using Windows NT authentication. You must set the authentication mode of your SQL Server to Mixed mode, which permits both Windows Authentication and SQL Server Authentication"
http://support.microsoft.com/default.aspx?scid=kb;en-us;313100
Here's a code snippet:
import java.sql.*;
public class test1 {
public static void main(String[] args) throws Exception{
// Load the driver
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
// Open connection
Connection conn = DriverManager.getConnection
("jdbc:microsoft:sqlserver://localhost:1433;User=sa;Password=sa");
// Prepare statement
PreparedStatement pstmt = conn.
prepareStatement("select * from t1 where x between ? and ?");
// Set parameters
pstmt.setInt(1, 990);
pstmt.setInt(2, 1000);
// Get result set
ResultSet rs = pstmt.executeQuery();
// Print it
while(rs.next() )
System.out.println("x: " + rs.getObject(1));
}
}
The connection string is in the following format:
jdbc:microsoft:sqlserver://localhost:1433;User=sa;Password=sa
You can substitute any DNS host name for localhost;User should exist in the DB and be authenticated by the DB not by Windows.
No comments:
Post a Comment