CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2011
    Posts
    1

    Exclamation Trouble Connectiong to a database

    Hello, I am trying to connect to a database, but I keep on getting that following error below. I am not sure why or how to move forward. Any help would be much appreciated.


    Error Message:

    com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'sa'.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)
    at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:246)
    at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:83)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2529)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:1905)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:1893)
    at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1045)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:817)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:700)
    at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:842)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)


    My Code:
    String myuser = "sa";
    String mypass = "12345";
    String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
    String dbURL = "jdbc:sqlserver://empiremain.empirevoip.com:3306/SQLEXPRESS/DB_Accounts;user=myuser;password=mypass;"; // Connect the server and the database


    Connection dbConn;

    String name = "";

    try
    {
    Class.forName(driverName);
    dbConn = DriverManager.getConnection(dbURL,myuser,mypass);
    System.out.println("Connection Successful!");


    Statement st = dbConn.createStatement();
    ResultSet rs = st.executeQuery("select * from information_schema.tables");

    while (rs.next()) {
    name = rs.getString("Table_Name");
    // id = rs.getInt("AccountNumber");

    System.out.println( name + "\n" );
    }

    }

    catch (Exception e)
    {
    System.out.print( "Message:\n" + e.getMessage() + "\n\n\n");
    e.printStackTrace();
    }

  2. #2
    Join Date
    Feb 2003
    Location
    Sunny Glasgow!
    Posts
    258

    Re: Trouble Connectiong to a database

    You define 'myuser' and 'mypass', but in the connection string you don't pass them in.

    Code:
    "jdbc:sqlserver://empiremain.empirevoip.com:3306/SQLEXPRESS/DB_Accounts;user=myuser;password=mypass;"
    this should be
    Code:
    "jdbc:sqlserver://empiremain.empirevoip.com:3306/SQLEXPRESS/DB_Accounts;user="+myuser+";password="+mypass+";"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured