title: JDBC connection to SQL Server: login failed for user x
body: <p>I am trying to set a JDBC connection to Sql Server 2008. I have created a database in Sql Server with this information:</p>
  
  <pre><code>CREATE LOGIN xtest WITH PASSWORD = 'berenjenas7(((';  
  GO  
  CREATE USER samxtest FOR LOGIN xtest;  
  GO  
  GRANT SELECT TO samxtest;
  GO  
  GRANT INSERT TO samxtest;
  GO  
  GRANT UPDATE TO samxtest;
  GO  
  GRANT DELETE TO samxtest;
  GO 
  </code></pre>
  
  <p>I installed the JDBC driver from here: <a href="http://www.microsoft.com/en-us/download/details.aspx?id=11774" rel="nofollow noreferrer">http://www.microsoft.com/en-us/download/details.aspx?id=11774</a>
  and <strong>I used the connectURL class from this link: <a href="http://msdn.microsoft.com/en-us/library/aa342339.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa342339.aspx</a>
  in order to test the connection</strong>.</p>
  
  <p>I left the default port 1433 in the code. The following picture should be proof that this is really the port:
  <img src="https://i.stack.imgur.com/pHBLj.jpg" alt="enter image description here">
  And of course I changed the connection string to: </p>
  
  <pre><code>String connectionUrl = "jdbc:sqlserver://localhost:1433;databaseName=XTest;user=samxtest;password=berenjenas7(((";
  </code></pre>
  
  <p>I don't understand what is wrong?
  The error I get is:</p>
  
  <blockquote>
    <p>com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user
    'samxtest'. ClientConnectionId:2344af.....    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
    connectURL.main(connectURL.java:18)</p>
  </blockquote>