• Post Reply Bookmark Topic Watch Topic
  • New Topic

SqlServer 2008 rd2: Login failed for user

Rui Campos
Posts: 2
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been trying for quite a while to manage to connect a simple application to my database, and i wonder if you guys could help.
So after searching for a while in the internet, i managed to find a similar case to mine which is actually in here: http://www.coderanch.com/t/307190/JDBC/java/SqlServer-Login-failed-user.
I'm running eclipse, as the IDE, and Microsoft SQL server 2008 rd2 and trying to connect them on windows 7, already tried using different drivers: jtds and Microsoft JDBC Driver 4.0 for SQL Server. Jtds tells me that can't find the right driver, so i have been trying with the Microsoft JDBC Driver 4.0 for SQL Server.
Here is the code:

public static void main(String[] args)
String conString ="jdbc:sqlserver://localhost\\SQLEXPRESS;databaseName=testeDB;";
String user ="*some text*";
String pass ="*some text";
try {
Connection conn = DriverManager.getConnection(conString,user,pass);
} catch (SQLException e) {
// TODO Auto-generated catch block

here's the exception code that i get:

com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'test'. ClientConnectionId:ea2434df-09bf-4c9b-a1c2-804bff000877
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)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
at java.sql.DriverManager.getConnection(DriverManager.java:579)
at java.sql.DriverManager.getConnection(DriverManager.java:221)
at crap.testConnection.main(testConnection.java:12)

If anyone has any ideas what i'm actually doing wrong and thinks he can help, i would appreciate.

Thanks, in advance
Keith Beeson
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure if this is right or not, but it seems your connecting just the driver and not the address. I'm working on similar coding when I'm trying to connect to a server and this is what I do:

private static final String URL = "jdbc:mysql://localhost:3306/registrar";
// This is to reference the driver
private static final String DRIVER = "com.mysql.jdbc.Driver";
// This is where the user is coded
private static final String ID = "text";
// This is the password for the user
private static final String PW = "text";

// This is where to load the driver
Class.forName (DRIVER);
// This is where to connect
Connection link = DriverManager.getConnection(URL, ID, PW); // In my case, I'm connecting to the URL, ID and PW where you are connecting the driver.
// This is first start to create the query
Statement aState = link.createStatement();
// 2nd step in creation
String query = "select * from course, enrollment, student";
// End query
ResultSet aResult = aState.executeQuery(query);

Hope this helps.
Rui Campos
Posts: 2
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, Keith Beeson.
First of all let me thank you for your attempt to help me.

Let me say, that i attempted to resolve the problem as you suggested but i wasn't able to accomplish the pretended.
I also wanted to point out some of the differences of the code between your code and mine:

// This is where to load the driver
Class.forName (DRIVER);

This is not needed with the new version of the Microsoft driver, as you can see here http://msdn.microsoft.com/en-us/library/ms378526, if you feel the need for curiosity, since as i saw you are working with mySQL.
"In the JDBC API 4.0, the DriverManager.getConnection method is enhanced to load JDBC drivers automatically. Therefore, applications do not need to call the Class.forName method to register or load the driver when using the sqljdbc4.jar class library."

I'm also following the syntax, as you can see in the above link for the connectionURL, altho i have tried quite a few variants.

To finish, i fear that my problem may lie with sql server 2008 rd2 configurations rather then an error on my code, as i did a quite extensive search before bothering/asking for help in this forum.
I would like to thank you again for trying to help me, i really appreciate.
Regards, Xajd

What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!