title: Authenticating to a SQL Server instance as a Windows User via JDBC
body: <p>I'm having to support multiple database types for my tenant-enabled web application. Among others, I have successfully supported Microsoft's SQL Server, by using the net.sourceforge.jtds.jdbc.Driver class with a connection String like "jdbc:jtds:sqlserver://192.168.1.189:1433/ApplicationName". This works, but it requires that the user explicitly defines a user in the SQL Server instance and enables SQL Server authentication.</p>
  
  <p>Now, inevitably, requirements changed, and we're supposed to support connecting to SQL Server via Windows Authentication. Evidently this requires some sort of change to the connection string, since the data base server must somehow be able to distinguish whether the credentials passed into the data base connection are for a user defined in the SQL Server installation or in the Windows OS. But what is it?</p>
  
  <p>Acting on advice from the internet, if progressed as far as extending the connection string with <code>;useNTLMv2=true;domain=WORKGROUP</code>. That <em>seems</em> to make the data base server aware that I want to authenticate as a Windows user, but the actual log-in fails with</p>
  
  <pre><code>The login is from an untrusted domain and cannot be used with Windows authentication. (code 18452, state 28000)
  </code></pre>
  
  <p>Now im my testing set-up, both the J2EE app and the SQL server instance are in fact on the same machine (although in production they may not be), and still this computer isn't trusted enough to log on to itself? Evidently I'm missing a big part of the puzzle here. What does one have to do to convince an SQL Server instance that the user who started it can in fact log on to it via JDBC?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Since we have already sunk too much unsuccessful effort trying to integrate our web application with a full Microsoft infrastructure stack (SQL Server, Active Directory, Domain Name Service...), I have to restrict this question:</p>
  
  <p>Does anyone know a way to access an <strong>SQL Server</strong> installation with a user account <strong>defined as a "Windows User"</strong> via <strong>JDBC</strong> form a J2EE application, <strong>without</strong> having to use Active Directory, a Windows machine running the web application and a proprietary DLL? The bounty is for any solution of that sub-problem. The entire problem is clearly too broad to be answered in one forum post.</p>