This discussion is archived
2 Replies Latest reply: Jul 20, 2012 3:25 PM by jschellSomeoneStoleMyAlias RSS

how to connect SQLServer using windows authentication over network in java

950769 Newbie
Currently Being Moderated
plz help me....

how to connect SQLServer using windows authentication over network in java. When we connected in local machine(sql server and application in same machine) that works fine. my java code is ----
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection("jdbc:sqlserver://sandesh-think:1433;databaseName=AdventureWorksLT;integratedSecurity=true");

Class.forName("net.sourceforge.jtds.jdbc.Driver");

con = DriverManager.getConnection("jdbc:jtds:sqlserver://sandesh-think:1433/AdventureWorksLT;domain=workgroup");

When we try to connect over network, we are getting the below error.

We had tried the following.
1. Copied the ntlmauth.dll in the Windows32/system and C:\Program Files\Java\jdk1.6.0_18\bin folder of my machine.(for jtds-1.2.5.jar)
OR
2. Copied the sqljdbc_auth.dll in the Windows32/system and C:\Program Files\Java\jdk1.6.0_18\bin folder of my machine.(for sqljdbc4.jar)
3. my system is windows 7 Professional SP1


com.microsoft.sqlserver.jdbc.SQLServerException: Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196)
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:2532)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:1929)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:1917)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1061)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:207)
at test.Example.main(Example.java:79)

Edited by: 947766 on Jul 20, 2012 6:23 AM
  • 1. Re: how to connect SQLServer using windows authentication over network in java
    murali veligeti - oracle Expert
    Currently Being Moderated
    Hi,

    Please refer below MSDN blogs for this issue

    http://blogs.msdn.com/b/sql_protocols/archive/2005/09/28/474698.aspx
    http://blogs.msdn.com/b/sql_protocols/archive/2008/05/03/understanding-the-error-message-login-failed-for-user-the-user-is-not-associated-with-a-trusted-sql-server-connection.aspx


    Thanks & Regards,
    Murali.
    ===========
  • 2. Re: how to connect SQLServer using windows authentication over network in java
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    947766 wrote:
    plz help me....

    how to connect SQLServer using windows authentication over network in java. When we connected in local machine(sql server and application in same machine) that works fine. my java code is ----
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    con = DriverManager.getConnection("jdbc:sqlserver://sandesh-think:1433;databaseName=AdventureWorksLT;integratedSecurity=true");
    Related to the other reply...that however really has nothing to do with it.

    When you are using windows authentication the FIRST thing to look at is what user is the application running as. And that has nothing to do with java code, connection strings, etc.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points