Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connecting to MS SQL via JDBC

Status
Not open for further replies.

pen81

Programmer
Oct 27, 2004
62
GB
I am using:

MS SQL Sever 2005 on Windows 2000
Microsoft SQL Server 2005 JDBC Driver 1.2
JDK 1.4.2 and JRE 1.6.0

I am writing a short test program to connect to the MS SQL Server via JDBC but am unsure how to find the correct username & password. I was under the impression the database server was configured to use Windows authentication but when supplying various Windows logins a get SQLServerException Login Failed.

Thanks in advance
 
Code:
import java.sql.*;

public class DBTest {

  public static void main(String[] args) throws Exception {  
  
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();

    String url = "jdbc:sqlserver://127.0.0.1:1433;";
    url += "DatabaseName=dbname;";
    url += "user=user;password=password";

    Connection conn = DriverManager.getConnection(url);
  }
}

Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: Logi
n failed for user 'guest'.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError
(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(Unknown So
urce)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(Unknown Source
)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(Unknown S
ource)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top