locked
connectionstring login failed for user RRS feed

  • Question

  • I'm trying to make a program to connect to a remote ms sql database to test and learn how to connect with databases in java eclipse mars using the following code.

    // Create a variable for the connection string.
          String connectionUrl = "jdbc:sqlserver://my.server.com;Initial" +
          "Catalog=test2;Persist Security Info=True;User ID=rsmobile;Password=xxxx";

          // Declare the JDBC objects.
          Connection con = null;
          Statement stmt = null;
          ResultSet rs = null;

          try {
             // Establish the connection.
             Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
             con = DriverManager.getConnection(connectionUrl);

    I may have something wrong in my connectionstring syntax. I copied the connectionstring from a VS c# program that is able to connect to the database data table. I can also connect to the table from ms ssms. The database name is test2 and the table name is TestTable2. I get the following error.
    com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user ''. ClientConnectionId:

    I've added sqljdbc.jar, sqljdbc4.jar, sqljdbc41.jar, and sqljdbc42.jar to the project libraries.

    Thanks


    why767

    Friday, December 18, 2015 11:41 AM

Answers

  • Hi why767,

    I can reproduce the same exception with your sample code. And after some research and test, I've found that in your sample code, "User ID" and "Initial Catalog" are not valid JDBC connection properties. Please use "UserName(or User)" and "DatabaseName(or Database )" instead.

    See more information Setting the Connection Properties.

    If you have any question, feel free to let me know.


    Eric Zhang
    TechNet Community Support

    • Marked as answer by why767 Wednesday, December 23, 2015 2:35 AM
    Tuesday, December 22, 2015 2:36 PM

All replies

  • Have you enabled TCPIP Protocol for you MS SQL Server?

    chanmm


    chanmm

    Saturday, December 19, 2015 12:08 PM
  • Hi why767,

    I can reproduce the same exception with your sample code. And after some research and test, I've found that in your sample code, "User ID" and "Initial Catalog" are not valid JDBC connection properties. Please use "UserName(or User)" and "DatabaseName(or Database )" instead.

    See more information Setting the Connection Properties.

    If you have any question, feel free to let me know.


    Eric Zhang
    TechNet Community Support

    • Marked as answer by why767 Wednesday, December 23, 2015 2:35 AM
    Tuesday, December 22, 2015 2:36 PM
  • Yes that is correct I got the "User ID" and "Initial Catalog" from an example. I tried

    	      String connectionUrl = "jdbc:sqlserver://my.server.com;"+
                          "databaseName=test2;user=rsmobile;password=xxxx";

    and got it to work but I'm now having trouble with my hosting provider.

    Thanks


    why767

    Wednesday, December 23, 2015 2:34 AM