I've written a very simple jdbc login test program. And after all kinds of problems I've almost got it working. Almost, just can't seem to get past this "SQLServerException: Login failed for user xxxxx" problem.
I created a simple database PersonInfo then I created user user1 password1 (sql authenication). And after trying everything was unable to connect to the database.
I am using SqlServer2008 on Win 7, I'v got the latest jdbc driver from Microsoft.
My code is:
import java.sql.*;
public class hell {
public static void main(String[] args) {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
Connection conn= DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=PersonInfo;user=Sohaib;password=0000;");
System.out.println("connected");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Here's the Exception
Exception: Unable to get connect
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'Sohaib'.
and all other supporting errors..
Unfortunately I am now dead in the water until some kind SqlServer Guru or Jdbc Guru take pity on me and helps me out.
thanks in advance.
In my case, I had to activate the option "SQL Server and Windows Authentication mode", follow all steps below:
1 - Right-click on your server
2 - Go to option Security
3 - Check the option "SQL Server and Windows Authentication mode"
4 - Click on Ok button
5 - Restart your SQL Express Service ("Windows Key" on keyboard and write "Services", and then Enter key)
After that, I could login with user and password
Also make sure that account is not locked out in user properties "Status" tab
If you are using Windows Authentication, make sure to log-in to Windows at least once with that user.