0

I tried many ways to solve my issue, none of them worked, so here i am with the question. I created a local database with SQL Server Management Studio. It's name is CallCenter, i created a user account for it, granted every privileges and i can log into the DB with it, in the Managemenet Studio, everything works just fine here.

Now i use NetBeans, to create the connection. I downloaded the Microsoft JDBC driver, set up everything, the JDBC seems to be working fine. The problem is, it cannot connect to the Database. I set the log in options to both Windows & SQL. I tried to log in, with integrated sequrity ( windows account ) aswell as the created ( and working ) SQL user account.

None of them worked, i keep getting this exception:

com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'admin'. ClientConnectionId:1ce0b951-5ecb-49b4-a4d0-ff4a96af4ed2 at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)......

Here is the code:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Try {

    public static void main(String[] args) {
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            String url="jdbc:sqlserver://localhost:1434;databaseName=CallCenter;integratedSecurity=true;";
            Connection conn = DriverManager.getConnection(url);        
        } catch (ClassNotFoundException e) {
            System.err.println("SQL Driver class does not exist!");
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
}

I've been browsing the internet for hours, tried many solutions, but none of solved this problem for me. Please help me out here!

Wanna Coffee
  • 2,742
  • 7
  • 40
  • 66
Gergo Szucs
  • 105
  • 1
  • 12
  • check the credential username/password – Kick Feb 13 '14 at 10:57
  • 2
    general here `Connection conn = DriverManager.getConnection(url);` mostly in use 2 other parameters - user + password - `Connection conn = DriverManager.getConnection(url, user, pass);` – catch23 Feb 13 '14 at 11:01

3 Answers3

2

The Exception pretty much says it all - check your credentials (which you obviously have not given) with the database.

Smutje
  • 17,733
  • 4
  • 24
  • 41
2

The Login failed for user 'admin' error which you get is a clear indication
that your login request reaches the SQL server but your credentials are wrong.
So either your username or your password is wrong, or maybe this login is not
configured for remote logins to the SQL server. Check your configuration on the server.

peter.petrov
  • 38,363
  • 16
  • 94
  • 159
  • Well i definitely get the username and password right, as i said, it works when i log in from the Studio. I double checked them, they match. In the Studio, i right clicked my server, and gave every permission to the admin user. Still does not work. Where can i configure this remote login thing? Any other ideas maybe? Thanks for your help guys! – Gergo Szucs Feb 13 '14 at 11:10
  • It works when you login from the studio from the same machine on which you run the Java code? – peter.petrov Feb 13 '14 at 11:11
  • Yes, it is the same machine! – Gergo Szucs Feb 13 '14 at 11:14
  • Post some screenshots. Do you login with SQL server authentication or with Windows authentication? See also the comment from nazar_art. – peter.petrov Feb 13 '14 at 11:17
  • Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); String url= "jdbc:sqlserver://localhost:1434;instance=MSSQLSERVER; databaseName=CallCenter;integratedSecurity=false;"; Connection conn = DriverManager.getConnection(url,"acc","pass"); I changed to this version of connection, it still does not work. I keep getting the same error. What kind of screenshot would you like me to post? The Studio works with the same login ( i changed up the acc and pass for the comment though ). – Gergo Szucs Feb 13 '14 at 11:24
  • I am not sure what the problem is but I think you're missing some minor detail here. It is not possible that it works from Studio and not from Java if your credentials and settings are 100% the same. Just double-check everything carefully. – peter.petrov Feb 13 '14 at 12:13
0

Use the other method of the DriverManager to get the connection using the Credentials.

When you have integratedSecurity=True, read this to get more idea on what it actually mean. It uses your windows credentials for login(With SQL Server). So, make that false and provide credentials for the DB.

For your reference read this

[EDIT]

Try using this instead of integratedSecurity.

jdbc:sqlserver://HOSP_SQL1.company.com;user=name;password=abcdefg;database=Test

Community
  • 1
  • 1
Vinay Veluri
  • 6,671
  • 5
  • 32
  • 56