title: Unable to connect to SQL Server database due to login failed error
body: <p>I have made a simple java project in which I am attempting to connect to an SQL Server 2019 (Developer Edition) database. However, when I try to do so, I get a login authentication error.</p>
  <p>This is my code for the project:</p>
  <pre><code>package javafxapplication12;
  
  import java.net.URL;
  import java.sql.*;
  import java.util.ResourceBundle;
  import javafx.event.ActionEvent;
  import javafx.fxml.FXML;
  import javafx.fxml.Initializable;
  import javafx.scene.control.Label;
  
  /**
   *
   * @author param
   */
  public class FXMLDocumentController implements Initializable {
      Connection con;
      @FXML
      private Label label;
      
      @FXML
      private void handleButtonAction(ActionEvent event)  {
          label.setText(&quot;Hello World!&quot;);
           try{
       Class.forName(&quot;com.microsoft.sqlserver.jdbc.SQLServerDriver&quot;);  
       con = DriverManager.getConnection(&quot;jdbc:sqlserver://localhost:1433;databaseName=Financials;user=dbo;password=;Trusted_Connection=False;MultipleActiveResultSets=True&quot;);
   
       System.out.println(&quot;Connected to database !&quot;);
   
     }
     catch(Exception sqle) {
        System.out.println(&quot;Sql Exception :&quot;+sqle.getMessage());
        label.setText(&quot;Failed&quot;);
     }
      }
      
      @Override
      public void initialize(URL url, ResourceBundle rb) {
          // TODO
      }    
      
  }
  
  </code></pre>
  <p>However, when I compile this file, I am always getting this error:</p>
  <blockquote>
  <p>Sql Exception :Login failed for user 'dbo'. ClientConnectionId:053ffe3f-aa4b-4c6b-86ee-df080cd91cf6</p>
  </blockquote>
  <p>After reading for some time on Stack, I tried changing the hostname from <code>localhost</code> to <code>myLaptopName</code>, but I am still getting the same error, which leads me to believe that I am going wrong somewhere fundamentally.</p>
  <p>Further, as suggested by some other users, I enabled <code>SQL Server and Windows Authentication mode</code> in Server Security settings, but even this didn't help resolve the error.</p>
  <p>I am using <code>JDK 1.8</code> with <code>Netbeans 8.2</code> and <code>mssql-jdbc-9.4.0.jre8.jar</code> connector to connect to a <code>MS SQL SERVER 2O19</code> database.</p>
  <p>Also, I wanted to add that when I used this query <code>SELECT HOST_NAME()</code> in SSMS, I got the result <code>myLaptopName</code>. This is why I tried replacing <code>localhost</code> with <code>myLaptopName</code>.</p>
  <p>Additional Information:</p>
  <blockquote>
  <p>User name: dbo</p>
  </blockquote>
  <blockquote>
  <p>Password:                      (no password)</p>
  </blockquote>
  <blockquote>
  <p>myLaptopName refers to &quot;LAPTOP-UQQOO5F7&quot;</p>
  </blockquote>
  <p>Database details:</p>
  <p><a href="https://i.stack.imgur.com/kchPK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kchPK.png" alt="Database" /></a></p>
  <p>SSMS Login Screen:</p>
  <p><a href="https://i.stack.imgur.com/nvGEm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nvGEm.png" alt="enter image description here" /></a></p>
  <p>Update: I tried to change the database name in the link to something different, just to check if that is causing any errors. Inspite of purposefully entering a wrong DB name (eg. FinAANCNAials), I am getting the same error !</p>