title: MS SQL Native Client Login failed for user when connecting via PHP
body: <p>I have a Windows 2008 R2 Datacenter server with IIS 7.5, MS SQL 2012 Express, using PHP 5.6 trying to connect to a database I created, testDB, via Windows Authentication, but am failing to do so.</p>
  
  <p>Here is my PHP I am using to connect to my SQL Server\Instance:</p>
  
  <pre><code>&lt;?php
  
  $serverName = "nmc-intranet\intranetsql";
  $connectionInfo = array("Database"=&gt;"testDB", "UID"=&gt;"username", "PWD"=&gt;"password");
  $conn = sqlsrv_connect( $serverName, $connectionInfo);
  
  if ( $conn ) {
  echo "Connection successful.&lt;br /&gt;";
  } else {
      echo "Connection failed.&lt;br /&gt;";
      die( print_r( sqlsrv_errors(), true));
  }
  
  ?&gt;
  </code></pre>
  
  <p>When I run this I receive: </p>
  
  <blockquote>
    <p>Connection failed.
    Array ( [0] => Array ( [0] => 28000 [SQLSTATE] => 28000 <a href="https://blogs.msdn.microsoft.com/chiranth/2014/04/17/setting-up-kerberos-authentication-for-a-website-in-iis/" rel="nofollow noreferrer">1</a> => 18456 [code] => 18456 <a href="https://stackoverflow.com/help/how-to-ask">2</a> => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'jaj'. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'jaj'. ) <a href="https://blogs.msdn.microsoft.com/chiranth/2014/04/17/setting-up-kerberos-authentication-for-a-website-in-iis/" rel="nofollow noreferrer">1</a> => Array ( [0] => 28000 [SQLSTATE] => 28000 <a href="https://blogs.msdn.microsoft.com/chiranth/2014/04/17/setting-up-kerberos-authentication-for-a-website-in-iis/" rel="nofollow noreferrer">1</a> => 18456 [code] => 18456 <a href="https://stackoverflow.com/help/how-to-ask">2</a> => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'jaj'. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'jaj'. ) )</p>
  </blockquote>
  
  <p>In MS SQL I have added the username to the Security > Logins and mapped testDB and gave dbo schema.  User also has sysadmin Server Role.  I can connect to testDB via CLI <code>SQLCMD /S nmc-intranet\intranetSQL /E /d testDB</code> under the username.  I can also connect to the Server\Instance via a remote SSMS session so I believe the remote connection properties are correct.  I have verified the steps mentioned in the answer found <a href="https://stackoverflow.com/questions/20276873/issues-connecting-to-microsoft-sql-from-php?rq=1">here</a>.</p>
  
  <p>For IIS I have tried establishing the connection many different ways, but also unsuccessful there.  So I have been assuming that is where my issue lies in the SQL login failed error.  I have been changing the connection string via the IIS Manager under the NMC-Intranet Node and also the Default Web Site Node and failed there.  My current connection string in web.config is what was in there by default after making changes in IIS Manger, and is as follows:</p>
  
  <pre><code>&lt;connectionStrings&gt;
      &lt;remove name="LocalSqlServer" /&gt;
      &lt;add connectionString="Server=nmc-intranet;Database=testDB;Integrated Security=true" name="LocalSqlServer" providerName="System.Data.SqlClient" /&gt;
  &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>I have tried changing it to the following that I found <a href="https://stackoverflow.com/questions/20474941/connection-string-between-iis-and-sql-server">here</a>, and still have had no success.</p>
  
  <pre><code>&lt;connectionStrings&gt;
      &lt;add connectionString="Server=.\SQLEXPRESS;Database=testDB;User ID=username;Password=password" name="LocalSqlServer" providerName="System.Data.SqlClient" /&gt;
  &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>In IIS DefaultAppPool I have tried changing the Process Model Identity to the username/password there as well.  I have been reading about Kerberos authentication <a href="https://blogs.msdn.microsoft.com/chiranth/2014/04/17/setting-up-kerberos-authentication-for-a-website-in-iis/" rel="nofollow noreferrer">here</a>, but when the intranet is accessed with it enabled it prompts users for a username/password to even view the home page.</p>
  
  <p>I hope I asked this question correctly as found <a href="https://stackoverflow.com/help/how-to-ask">here</a> as previous questions were not well-received.  I have done a lot of researching, but I do not know what I could be missing, and I have made so many changes and reverted them as they did not work I am just hoping for some direction of what I might need to try next.  I have most likely misinterpreted something, as I do not have a complete understanding of how the connection needs to be established, and skipped a step or overlooked some information.</p>
  
  <p>I am no professional here just trying to gather this all together from the internet, make it work, and hopefully learn something.</p>
  
  <p>End game I am looking to have users log in to Intranet via AD, and upload files, create their own posts, create a directory of sorts that can be managed via the intranet, possibly have an IM(?), and really just the learning experience.</p>
  
  <p>Thank you.</p>