0
votes

I need to connect to remote ms sql.I have the windows server login information to connect. And that login user can connect to MSSQL server. (I mean I can connect to MSSQL server via Windows Authentication with that user)

I want to do that with Java code. I tried to connect by using jdbc driver, but I couldn't. How can I connect to MSSQL server remotely, with windows user which have right to connect MSSQL 2008 R2.

String connectionurl = "jdbc:sqlserver://remoteIP:port;databaseName=databasename;intergratedsecurity=true";

and even i tried with username password through which i can connect to remote windows server.

String connectionurl = "jdbc:sqlserver://remoteIP:port;databaseName=databasename;username=ab;password=bc";

error:

Login failed for user ''. ClientConnectionId:916ac72a-9c78-45f9-bc61-680793d1fea7 at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216) at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:254) at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:84) at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2908) at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:2234) at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41) at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:2220) at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696) at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1326)

1
The JDBC sqlServer username for sql authentication mode is just user - reference MSDNStuartLC
The first URL works for me. It's a bit tricky to put the correct version of sqljdbc_auth.dll into the correct directory though.a_horse_with_no_name
Hi stuartLC, still am getting same error String url = "jdbc:sqlserver://remoteIP:port;databaseName=databasename;user=username;password=password";priyanka2

1 Answers

0
votes

Is it simply a typo?

intergratedsecurity=true

should be

integratedSecurity=true

Windows auth means that SQL Server uses the Windows login token. Because of this typo, it expects a username and password whcih you don't have. Hence the error message Login failed for user ''.