title: Login failed for user 'DESKTOP-6U7R1AC\Amit'
body: <p>I want to connect my sql server database with java. here is the code I have</p>
  <pre><code>package myPackage;
  import java.beans.Statement;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  
  public class Test1 {
  
  public static void main(String[] args) throws SQLException, ClassNotFoundException {
      // TODO Auto-generated method stub
      String url = &quot;jdbc:sqlserver://DESKTOP-6U7R1AC\\SQLEXPRESS;databaseName=sample1;&quot;;
      String uname=&quot;DESKTOP-6U7R1AC\\Amit&quot;;
      String pass=&quot;&quot;;
      
      Class.forName(&quot;com.microsoft.sqlserver.jdbc.SQLServerDriver&quot;);
  
      Connection conn = DriverManager.getConnection(url,uname,pass);
      System.out.println(&quot;command completed sucessfully&quot;);        
      
      Statement stmt =(Statement) conn.createStatement();
      String query =&quot;SELECT * FROM tblPerson&quot;;
      ResultSet rs =((java.sql.Statement) stmt).executeQuery(query);
      while(rs.next()){
          System.out.println(rs.getInt(1) +&quot; &quot;+rs.getString(2) +&quot; &quot;+rs.getString(3) );
      }
      
  
  }
  
  }
  </code></pre>
  <p><strong>Please note that</strong></p>
  <ul>
  <li>I am using Microsoft SQL server management studio 18.</li>
  <li>I have added the mssql-jdbc-8.4.1.jar in the build path.</li>
  </ul>
  <p><strong>my SQL server details</strong></p>
  <ul>
  <li>server type: Database Engine</li>
  <li>server name: DESKTOP-6U7R1AC\SQLEXPRESS</li>
  <li>Authentication: Windows Authentication</li>
  <li>User name: DESKTOP-6U7R1AC\Amit</li>
  <li>Password:</li>
  </ul>
  <p><strong>I am getting the following error-</strong></p>
  <p>Exception in thread &quot;main&quot; com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'DESKTOP-6U7R1AC\Amit'. ClientConnectionId:497452a3-a4f3-40a8-b68e-864e269ad66a
  at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:262)
  at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:283)
  at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:129)
  at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:37)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:5233)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:3988)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:85)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:3932)
  at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7375)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:3206)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2713)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:2362)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:2213)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1276)
  at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:861)
  at java.sql.DriverManager.getConnection(Unknown Source)
  at java.sql.DriverManager.getConnection(Unknown Source)
  at myPackage.Test1.main(Test1.java:22)</p>