2

I need to connect to SQL Server using Windows Authentication with different user account in JDBC. This is the code I am using:

static final String DB_URL = "jdbc:sqlserver://IP:port; databaseName=xyz; integratedSecurity=false; domain=abc";

Connection con = DriverManager.getConnection(DB_URL,USER,PASS);

And here is the Error:

com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'abcd'

Jeroen
  • 60,696
  • 40
  • 206
  • 339
  • See here http://stackoverflow.com/questions/167464/can-i-connect-to-sql-server-using-windows-authentication-from-java-ee-webapp – Konstantin V. Salikhov Dec 26 '12 at 11:36
  • sorry for late reply. Thanks for the response!! I am using jdbc 1.2 and via sql server mangment studio I can log in to that sql server using different user account in 'Run as' and when i try with above code it doesn't connect. Do you think using jtds it may fix this or I need to install highest version of jdbc??? – user1929593 Dec 28 '12 at 11:01

1 Answers1

1

Like described in question given by @konstantin-v-salikhov you need to set integratedSecurity=true if you actually want to use Integrated Authentication (and in that case it will autenticate as the user running the application). You also need the sqljdbc_auth.dll file to be installed. When you make the actual call you shouldn't provide any username or password, just do something like this:

Properties info = new Properties();
Connection con = DriverManager.getConnection(DB_URL, info);

If you want to use SQL Server authentication (like you are doing in your code sample) you need to enable mixed mode authentication for your SQL Server instance.

Jens Borgland
  • 753
  • 4
  • 15
  • 1
    thanks for the reply! but i want a particular user authentication to be used in windows authentication for every run. is it possible? – user1929593 Jan 17 '13 at 14:49