none
connect to SQL with jdbc and a windows AD account

    Question

  • I am trying to connect to a SQL database from my machine but with a different windows AD account.  The server is set to mixed mode and my code is this. 

    String pPSSDBDriverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
            String pPSSDatabaseName = "MG_Staging";
            String pPSSDBConn = "jdbc:sqlserver://DLKMS025:1433;Integratedsecurity=SSPI;UseNTLMv2=true;Domain=AD;Trusted_Connection=yes";

    String pPSSDBUserId = "RB373";
    String pPSSDBPassword = "#######";

    Class.forName(pPSSDBDriverName).newInstance();
            pPSSDBConn = pPSSDBConn + ";Initial Catalog=" + pPSSDatabaseName ;
            System.out.println("start ******* " + pPSSDBConn);
            try {
                
                DBconn = DriverManager.getConnection(pPSSDBConn, pPSSDBUserId, pPSSDBPassword);

    my connection string is : jdbc:sqlserver://DLKMS025:1433;Integratedsecurity=SSPI;UseNTLMv2=true;Domain=AD;Trusted_Connection=yes;Initial Catalog=MG_Staging

    I get this message [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Login failed for user 'RB373'.

    Error: 18456, Severity: 14, State: 6. –Attempting to use SQL authentication with a windows account.

    Tuesday, November 12, 2013 3:00 PM

Answers

All replies

  • Hi,

    As per the error we can see that it is a login failure.

    Cross check the userid and password that you are using to connect are matching with the login credentials specified in the server. Or there are chances that the login that you are specifying may not exist on the server. Talk to your DBA's for resolution.

    Thanks,

    Bhanu


    • Edited by bhanu_nz Wednesday, November 13, 2013 2:42 AM
    Wednesday, November 13, 2013 2:39 AM
  • Hi,

    As per the below connectionstring you are using Windows Authentication to login to SQL Server.

    jdbc:sqlserver://DLKMS025:1433;Integratedsecurity=SSPI;UseNTLMv2=true;Domain=AD;Trusted_Connection=yes;Initial Catalog=MG_Staging

    When the application is using Windows credentials to connect to SQl Server, then you do not need to provide the user name and password in the code.

    All you need to ensure is that the domain account that the application will be using, should have proper access and previledges in the SQL Server and in the database.


    Thanks and Regards Alankar Chakravorty MCITP Database Administrator SQL Server 2008 MCITP Database Administrator SQL Server 2005

    Wednesday, November 13, 2013 3:55 AM
  • If you are using the sql server , SQL account for authenication, please remove following lines:

    Integratedsecurity=SSPI;UseNTLMv2=true;Domain=AD;Trusted_Connection=yes;

    It just be:

    jdbc:sqlserver://DLKMS025:1433;Initial Catalog=MG_Staging

    Here is an example for SQL Authentication

    String url = "jdbc:sqlserver://ServerIP:1433;databaseName=dbName";
    
       String user = "dbUserID";
       String pass = "dbUserPassword";
       Connection connection = DriverManager.getConnection(url, user, pass); 


    Regards Harsh

    Wednesday, November 13, 2013 4:16 AM
  • This is a web service that a form is calling from the clients machine.  This service is running on a Linux box and does not have an user associated with it.  That is why I need to pass the ID/password that was set up on the SQL box.  This ID was added in the security tab on the DB as AD/RB373 and windows authentication is checked.  The user is also part of the admin group on this box.  This ID has access to the table I am going after so I need to pass this ID/password but still get that same error.  Why is SQL not checking for Windows authentication?  I thought the parm "Integratedsecurity=SSPI" took care of this.


    Thursday, November 14, 2013 12:38 PM
  • Hi Klocks,

    When you "Integratedsecurity=SSPI" is feature of window box, when connected from linux box, there need to be a kerberos system in place to which can delegate your passed in credential as windows authentication. If you need to use  Integratedsecurity=SSPI, then set the kerbose.

    Here is msdn article you want to go through: http://technet.microsoft.com/en-us/library/ms378428.aspx


    Regards Harsh

    Friday, November 15, 2013 4:24 AM