jdbc.SQLServerException: Login failed for user for any user
Solution 1
If you try to connect with database which is using windows authentication, you can use 'integratedSecurity' option in your connection string.
DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=SocialFamilyTree;integratedSecurity=true;");
Solution 2
Having been through this very recently the steps I took to solve pretty much the same problem were
- use SQL Server Management Studio to log in with the desired account and confirm access to read (and write if necessary)
- Use SQL Server Configuration Manager to confirm that the server instance is listening on the IP address being targetted
- Disable the firewall to check that isn't getting in the way (and add an exception if necessary for future use)
The absolute kicker for me was understanding what IP addresses and ports the instance was set to listen on so that when I constructed the connection string the connection wasn't being rejected.
Also, if you want to connect using Windows logins you need to ensure the SQL instance is configured for mixed mode authentication (i.e. to allow Windows and SQL logins)
Solution 3
Since you get this error,the Sql server correctly listens to the port.
- Open Sql Server Management Studio connect to your Server.
- right click on the server's icon and choose properties.
- Go to the security tab and tick Sql Server and Windows Authentication mode.
If you want to define a user,go from the tree, to Security->Logins,right click on logins folder and click "New Login".
Now your server should work with this Url String. Use the log file of the Server that may help you understand its working.
Solution 4
Re: Did it. still WARNING: Failed to load the sqljdbc_auth.dll cause :- no sqljdbc_auth in java.library.path – Mike Oct 7 at 14:03
you have to add the path to sqljdbc_auth.dll by adding this under VM arguments in Eclipse or commandline if you're running from the shell: -Djava.library.path="\MS SQL Server JDBC Driver 3.0\sqljdbc_3.0\enu\auth\x86"
that's if you're running 32 bit Windows. else the final subdir changes accordingly.
I think this might be a better answer though, to setting up SQL Server user based authentication: Connecting SQL Server 2008 to Java: Login failed for user error
(I try to summarize it here: http://silveira.wikidot.com/sql-server)
Mike
Updated on March 03, 2021Comments
-
Mike about 3 years
I trying to test the connection with my local sql DB. I have this code:
try{ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance(); DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=SocialFamilyTree;user=SOSCOMP"); }catch(Exception e){ System.out.println("Couldn't get database connection."); e.printStackTrace(); }
I tried many users. my windows user is SOSCOMP and doesn't have a password. I also know that SQL 2008 create users as "sys" "dbo", I tried these too. I'm always getting:
Couldn't get database connection. com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'SOSCOMP'. 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:579) at java.sql.DriverManager.getConnection(DriverManager.java:243) at FT_Receiver.FT_Receiver.main(FT_Receiver.java:12)
Any ideas?
Thanks
-
home over 11 yearsHow does this relate to android?
-
-
Mike over 11 yearsIt worked. I created a user, but when i'm logging in with the user and try to access the DB, I get: The database SocialFamilyTree is not accessible (ObjectExplorer) how can I give permission to this user.
-
Mike over 11 yearsI get: Oct 07, 2012 9:45:49 AM com.microsoft.sqlserver.jdbc.AuthenticationJNI <clinit> WARNING: Failed to load the sqljdbc_auth.dll Couldn't get database connection.
-
piotrp over 11 yearshttp://www.microsoft.com/en-us/download/details.aspx?id=21599#filelis Here you can find sqljdbc_auth.dll file. Yous can copy it into c:/windows/system32 (for 32-bit system)
-
Mike over 11 yearsDid it. still WARNING: Failed to load the sqljdbc_auth.dll cause :- no sqljdbc_auth in java.library.path
-
Mike over 11 yearsNevermind, I got it to work with the db user I created. Thanks
-
Jason D about 10 yearsI forgot to enable mixed mode authentication, thanks for the reminder, worked for me.
-
MAbraham1 over 9 yearsMike, open the SQL Server error log to see which user is attempting to log-in to the db instance: C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\Log
-
Davide over 4 yearsThis is not an answer to the question