title: SQL Server 2016 Always Encrypted Timeout at Published IIS
body: <p>I Have strange problem when i tried to publish my asp.net mvc application to my local (pc) iis with "Always Encrypted" Enabled. </p>
  
  <p>My application keep timeout when i tried to access database using EF6 at local IIS (not express) :</p>
  
  <p><img src="https://i.stack.imgur.com/isUtm.png" alt="Timeout Pic @ Local IIS"></p>
  
  <p>But if i tried to access &amp; debug my asp.net mvc app using Visual Studio 2017, database with 'always encrypted enabled' can be accessed perfectly without timeout.</p>
  
  <p><img src="https://i.stack.imgur.com/7upNF.png" alt="Iis express with VS2017 "></p>
  
  <p>And also i can access it with SQL Management Studio without problem.</p>
  
  <p>Both (SMSS &amp; ASP.NET web config) using this configuration.</p>
  
  <pre><code>Column Encryption Setting=enabled;
  </code></pre>
  
  <p>Note : I'm using ASP.NET MVC 5 &amp; EF 6, SQL Server 2016 Developer Edition.</p>
  
  <p>Sorry for my bad english.</p>
  
  <hr>
  
  <p><strong>UPDATED :</strong> 
  I have tried using .NET Framework Data Provider to see if there's any clue that'll help me solving this issue, Using following code :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>var context = new TestDevEntities();
              StringBuilder sb = new StringBuilder();
              string connectionString = context.Database.Connection.ConnectionString;
              using (SqlConnection connection = new SqlConnection(connectionString))
              {
                  connection.Open();
                  using (SqlCommand cmd = new SqlCommand(@"SELECT [id],[name],[CCno]  FROM [TestDev].[dbo].[testEncCol]", connection, null, SqlCommandColumnEncryptionSetting.ResultSetOnly))
                  {
                      using (SqlDataReader reader = cmd.ExecuteReader())
                      {
                          if (reader.HasRows)
                          {
                              
                              while (reader.Read())
                              {
                                  sb.Append(reader[2] + ";");
                              }
                          }
                      }
                  }
              }</code></pre>
  </div>
  </div>
  </p>
  
  <p>above code show me this error : 
  <img src="https://i.stack.imgur.com/bfsh8.png" alt="enter image description here"></p>
  
  <p>Now, with this kind of error i know i exactly i must do :)</p>
  
  <ol>
  <li>Change the identity of application pool to the 'user' who previously generated the certificate.</li>
  <li>Export currentuser cert (used by always encrypted) and import to the user that you want to use as application pool identity.</li>
  </ol>
  
  <p><img src="https://i.stack.imgur.com/K2CY9.png" alt="Working"></p>
  
  <p>Now its <strong>worked!</strong></p>
  
  <p>EF should throw some kind of error as clear as .NET Data Providers do, instead of timeout failure that really confuse me @_@</p>
  
  <hr>
  
  <p><strong>UPDATED (1) :</strong> 
  Now the question is how to use it (Certificate) with default ApplicationPoolIdentity instead of custom account? </p>
  
  <p><strong>UPDATED (2) :</strong> 
  I have done what <a href="https://stackoverflow.com/a/45579321/8426789">jakub</a> suggest, but still no luck.
  <img src="https://i.stack.imgur.com/fmfb7.png" alt="enter image description here"></p>
  
  <p><strong>Thanks</strong></p>