aspose file tools*
The moose likes JDBC and the fly likes SQL Server 2008 connection failure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL Server 2008 connection failure" Watch "SQL Server 2008 connection failure" New topic
Author

SQL Server 2008 connection failure

Elena Irkovskaya
Greenhorn

Joined: Apr 28, 2012
Posts: 3
I have a problem with connect to database on SQL Server 2008R2. I use Eclipse.
Help me, please.

import java.sql.*;
import com.microsoft.sqlserver.jdbc.*;


public class Start {

/**
* @param args
*/

public static Connection getConnection(String url, String user, String pass) {
//load driver for MS SQL
try {
Class.forName("com.microsoft.sqlserver.jdbc.DriverJDBCVersion");
} catch (ClassNotFoundException e) {
System.err.println("Driver not found: " + e + "\n" + e.getMessage());
return null;
}
//return null;
try {
//get connection
Connection conn = DriverManager.getConnection(url, user, pass);
return conn;
} catch (Exception e) {
System.err.println("Exception: " + e + "\n" + e.getMessage());
return null;
}
}

public static void main(String[] args) {
//vars for connection
String url = "jdbc:sqlserver://localhost:1433;databaseName=sale_telephone";
String user = "lena";
String pass = "123456";

Connection con = getConnection(url, user, pass);
}
}

When I run my file, I get
Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Ошибка входа пользователя "lena". ClientConnectionId:8fbdcc0f-0766-4458-af42-512a1bdf6123
Ошибка входа пользователя "lena". ClientConnectionId:8fbdcc0f-0766-4458-af42-512a1bdf6123

Thank You
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18883
    
    8

Hi Elena, welcome to the Ranch!

Could you provide us with an English translation of that Russian text? It looks like it might be the key to the problem.

Also, I recommend that you change your catch-block to look like this:



That will still print the "message" part of the exception, but it will also print the stack trace, so that you can find out what line of code caused the exception.
Elena Irkovskaya
Greenhorn

Joined: Apr 28, 2012
Posts: 3
Sorry,

com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user "LENA\QSLEXPRESS". ClientConnectionId:b02ae614-ce58-4e6f-b359-6ab4962db251
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(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at db.Start.getConnection(Start.java:24)
at db.Start.main(Start.java:38)
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107


and you can connect to that database using that login from the sql server client?
Elena Irkovskaya
Greenhorn

Joined: Apr 28, 2012
Posts: 3
Yes, I try to use several variants: name of connection, name of database's user, login. Create Login and create user, which uses this login. And the result in not depend on entered name and password.
Howard Watson
Ranch Hand

Joined: Jan 07, 2004
Posts: 56
Hi Elena. If you are still having issues try the driver suggested at your original post.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQL Server 2008 connection failure