File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes JDBC Connection to MS SQL with Windows Authentication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC Connection to MS SQL with Windows Authentication " Watch "JDBC Connection to MS SQL with Windows Authentication " New topic
Author

JDBC Connection to MS SQL with Windows Authentication

Irfan E. Khan
Greenhorn

Joined: Jun 30, 2005
Posts: 3
Environment -

I am using Tomcat as my servlet engine and IIS as the Server. Additionally, I am using MS SQL 2000 as my DB. The DB resides on a seperate machine, and have created an ODBC JDBC connection on the local machine to access it. Additionally, the authentication for the DB is set to "Windows Authentication".

Problem -

Everything works fine if I simply run tomcat and access the databse. Also, things run fine when I run tomcat via IIS too. However, when I try accessing the database, I get the error

Login failed for user '<username>'

Now, the funny part is, this username is actually the username of the local machine on which the application has been placed. It is not the username that I am providing in

con=DriverManager.getConnection("jdbc dbc BName","username","password");

Can someone please help me figure it out?? Why is it working when I run the tomcat (Apache) and run the application from there, but ones I run it via IIS, it fails. Also, why is it taking the username from the local machine and not the one that I am providing out there?
Masoud Kalali
Author
Ranch Hand

Joined: Jul 08, 2004
Posts: 531

Hi
If i understand you correctly you wanna use Windows authentication
but it is not possible (at least with JDTS which i used).
you just can use MS SQL server with MIXED mode or SQL server authentication mode to access the db from Java.


hope it helps


Masoud Kalali
Software Engineer - My Weblog - GlassFish Security
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


If i understand you correctly you wanna use Windows authentication
but it is not possible (at least with JDTS which i used).

Yes, its not possible to connect to SQl Server via JDBC at all, using anything other than "SQL Server and Windows" authentication, regardless of which Driver you use.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Irfan E. Khan
Greenhorn

Joined: Jun 30, 2005
Posts: 3
Thanks for the reply. So, even if I put it as SQL Server and Windows Authentication, i will still have to use SQL Authentication ONLY?

However, I am still baffled by one thing. Presume the name of the computer is CompName and domain it is in is myDomain. Now, even though I have logged onto to it through the user name XYZ, the error says -

Login failed for user myDomain/CompName

Why is it not stating that login failed for user XYZ. XYZ happens to be the owner of that database too on the SQL Server.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Sounds like it is still configured to use Windows Authentication. Are you sure you have changed the authentication settings? Also can you show us how you are logging in?
Irfan E. Khan
Greenhorn

Joined: Jun 30, 2005
Posts: 3
Hi Paul,

Yes, its still configured to run on Windows Authentication only. I have to wait for the DB Admin to be here to change the settings for it. It should be done in an hour's time and I will post the status / logs for you.

Please bear with me. Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC Connection to MS SQL with Windows Authentication
 
Similar Threads
MS SQL Server 2005 Authentication
IIS Integrated Authentication + Tomcat Form-based (or basic) Authentication
Authentication in Web application
Datasource Test Connection is successful but the application is not able to connect to the Database
web application authentication issue