0
votes

I want to connect to a SQL server using windows username and password through Java eclipse

Able to connect with Integrated Security = true .

But need try with other domains.

connecting with the below connection URL.

"jdbc:sqlserver://servername;databaseName=database;integratedSecurity=true"

Jar - MsSQL-jdbc-7.2.2.jre8.jar

failed with this URL

"jdbc:sqlserver://servername;databaseName=database;user=domain\user;password=password"

Error Message

com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'domain\User'. ClientConnectionId:df0fd280-7727-446f-96e4-ce972fda26d7 at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:262) at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:258) at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:104) at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:5036) at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:3668) at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:94) at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:3627) at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7194) at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2935) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2456) at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:2103) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1950) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1162) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:735) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at sql.Javaconnection.main(Javaconnection.java:27)

2
What you're looking for here is called impersonation. You can't supply a username and password in the connection string when using integrated authentication; that's for using SQL Authentication. Impersonation is handled in the application, not the connection manager, so you'll need to let people know what code library your using (C#, java?) and provide the code your using to create/connect to your SQL Instance.Larnu

2 Answers

1
votes

The same option is for .NET. The answer is NO.

0
votes

Through Java eclipse ... Able to connect with Integrated Security = true ... But need try with other domains.

To connect using Windows Integrated Authentication to SQL Server using an account that you can't log on locally with or impersonate (ie an account from another domain), you can use RUNAS /NETONLY or set an appropriate credential in the Windows Credential Manager.

In either case you configure a credential that will be used for NTLM authentication for network resources without requiring a local logon using those credentials. You would use integratedSecurity=true instead of providing credentials in the connection string.