title: Asp.net application suddenly stopped responding to requests
body: <p>Good day, I am a newbie in .net programming and also IIS web deployment configuration.</p>
  
  <p>Currently, I have an asp.net application that runs using Framework 4.5 on IIS. For the first month of having the application deployed on the server, it was running fine and smoothly. However, recently the application had issues whereby the login page would actually load but when the users key in their credentials, the page loading timer would show and it disappears, leaving the user stranded, unable to login.</p>
  
  <p>In addition, the server had undergone security procedures as stated below:</p>
  
  <ol>
  <li>Windows Hardening (Using Windows Server 2012)</li>
  <li>SQL Server Hardening (SQL Server 2012) and port was changed to 8001</li>
  </ol>
  
  <p>Also, the architecture of the application is that:</p>
  
  <ol>
  <li>The Application is deployed in <strong>AMLWEB</strong> server</li>
  <li>The SQL Server Database is in <strong>AMLDB</strong> server</li>
  </ol>
  
  <p>So, the connection actually goes across server and the login authentication is actually authenticated against <strong>Active Directory</strong>.</p>
  
  <p>The screenshot as attached:
  <a href="https://www.dropbox.com/s/d377ut6bz9b7gnb/screen.png?dl=0" rel="nofollow">Unhandled exception screenshot</a></p>
  
  <p>When checked on the event viewer, the below warning was seen that may suggest to be contributing to the issue:</p>
  
  <pre><code>Event code: 3005 
  Event message: An unhandled exception has occurred. 
  Event time: 1/18/2015 5:27:15 PM 
  Event time (UTC): 1/18/2015 9:27:15 AM 
  Event ID: 2ac169fff7284e86b7b0844e5d9ccab1 
  Event sequence: 4 
  Event occurrence: 1 
  Event detail code: 0 
  
  Application information: 
      Application domain: /LM/W3SVC/1/ROOT/AML-1-130660468323976167 
      Trust level: Full 
      Application Virtual Path: /AML
      Application Path: D:\AML\ 
      Machine name: AMLWEB 
  
  Process information: 
      Process ID: 6756 
      Process name: w3wp.exe 
      Account name: IIS APPPOOL\.NET v4.5 
  
  Exception information: 
      Exception type: InvalidOperationException 
      Exception message: The ConnectionString property has not been initialized.
     at System.Data.SqlClient.SqlConnection.PermissionDemand()
     at System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection outerConnection)
     at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
     at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
     at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
     at System.Data.SqlClient.SqlConnection.Open()
     at DBManager.DBManager.OpenConnection(String DBStrConn, Int16 DBType) in C:\Users\TESS-HP003\Desktop\AML\ES_Library\DBManager\DBManager.vb:line 50
     at DBManager.DBManager.ExecuteSQLQuery_ReturnDS(String&amp; ReturnErrorMsg, String SqlString, String DBConnString, Int16 DBType) in C:\Users\TESS-HP003\Desktop\AML\ES_Library\DBManager\DBManager.vb:line 190
     at SQLAdminQueryManager.AdminQueryManager.AdminQueryManager_Staff_Login.Staff_Login_Retreive(cor_staff AppEntity, String DbSQLConnString, String DbType, String&amp; ReturnErrorMsg, Object&amp; ReturnObjDataset, String AccessType) in C:\Users\TESS-HP003\Desktop\AML\ES_Library\SQLAdminQueryManager\AdminQueryManager.vb:line 65
     at Login_page_LDAP_Code.LoginButton_Click(Object sender, EventArgs e)
     at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
     at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
     at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
     at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
     at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
     at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  
  
  
  Request information: 
      Request URL: https://amlweb/AML/Login_page.aspx 
      Request path: /AML/Login_page.aspx 
      User host address: 10.1.67.61 
      User:  
      Is authenticated: False 
      Authentication Type:  
      Thread account name: IIS APPPOOL\.NET v4.5 
  
  Thread information: 
      Thread ID: 10 
      Thread account name: IIS APPPOOL\.NET v4.5 
      Is impersonating: False 
      Stack trace:    at System.Data.SqlClient.SqlConnection.PermissionDemand()
     at System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection outerConnection)
     at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
     at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
     at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
     at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
     at System.Data.SqlClient.SqlConnection.Open()
     at DBManager.DBManager.OpenConnection(String DBStrConn, Int16 DBType) in C:\Users\TESS-HP003\Desktop\AML\ES_Library\DBManager\DBManager.vb:line 50
     at DBManager.DBManager.ExecuteSQLQuery_ReturnDS(String&amp; ReturnErrorMsg, String SqlString, String DBConnString, Int16 DBType) in C:\Users\TESS-HP003\Desktop\AML\ES_Library\DBManager\DBManager.vb:line 190
     at SQLAdminQueryManager.AdminQueryManager.AdminQueryManager_Staff_Login.Staff_Login_Retreive(cor_staff AppEntity, String DbSQLConnString, String DbType, String&amp; ReturnErrorMsg, Object&amp; ReturnObjDataset, String AccessType) in C:\Users\TESS-HP003\Desktop\AML\ES_Library\SQLAdminQueryManager\AdminQueryManager.vb:line 65
     at Login_page_LDAP_Code.LoginButton_Click(Object sender, EventArgs e)
     at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
     at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
     at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
     at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
     at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
     at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  
  
  Custom event details: 
  </code></pre>
  
  <p>However, the connection string was indeed had been set up properly as below:</p>
  
  <p>Web.config</p>
  
  <pre><code>&lt;connectionStrings&gt;
      &lt;add name="AMLDBConnectionString" connectionString="Data Source=AMLDB01, 8001;Initial Catalog=AML_DB;integrated security=true; uid=sa; pwd=p@ssw0rd"/&gt;
  &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>And it was set up as a global variable as so:</p>
  
  <pre><code>GlobalSQLConnString = ConfigurationManager.ConnectionStrings("AMLDBConnectionString").ToString
  GlobalDBType As Int16 = 1  
  </code></pre>
  
  <p>The line which actually executed to connect to the DB:</p>
  
  <pre><code>blnReturnValue = objSqlQuery.Staff_Login_Retreive(objBE, GlobalSQLConnString, GlobalDBType, strErrorMsgReturn, returnDS, "S")
  </code></pre>
  
  <p>The method invoked:</p>
  
  <pre><code>Public Function Staff_Login_Retreive(ByVal AppEntity As BusinessEntities.cor_staff, _
                                               ByVal DbSQLConnString As String, ByVal DbType As String, _
                                               ByRef ReturnErrorMsg As String, ByRef ReturnObjDataset As Object, _
                                               Optional ByVal AccessType As String = "S") As Boolean
              With AppEntity
                  SQlQuery = "SELECT * "
                  SQlQuery += " FROM cor_staff "
                  SQlQuery += " WHERE cor_staff.cor_userid =N'" &amp; AppEntity.cor_userid &amp; "'"
              End With
              '
              If AccessType.ToUpper = "R" Then
                  ReturnObjDataset = ExecuteSQLQuery_ReturnIDR(ReturnErrorMsg, SQlQuery, DbSQLConnString, DbType)
              Else
                  ReturnObjDataset = ExecuteSQLQuery_ReturnDS(ReturnErrorMsg, SQlQuery, DbSQLConnString, DbType)
              End If
              '
              If ReturnErrorMsg.Trim.Length = 0 Then
                  Return True
              Else
                  Return False
              End If
              '
          End Function
  </code></pre>
  
  <p><strong>Edited</strong></p>
  
  <p>Since the above code would actually run through and would actually be invoked on this line:</p>
  
  <pre><code>ReturnObjDataset = ExecuteSQLQuery_ReturnDS(ReturnErrorMsg, SQlQuery, DbSQLConnString, DbType)
  </code></pre>
  
  <p>The connection would only be opened here:</p>
  
  <pre><code>Public Function ExecuteSQLQuery_ReturnDS(ByRef ReturnErrorMsg As String, ByVal SqlString As String, ByVal DBConnString As String, ByVal DBType As Int16) As DataSet
          ReturnErrorMsg = ""
          Dim DS As New DataSet
          '
          If DBType = 1 Then
              Try
                  OpenConnection(DBConnString, DBType)
                  Dim sqlCmd As New SqlCommand(SqlString, sqlConn)
                  sqlCmd.CommandTimeout = 0
                  Dim sqlDaAdp As New SqlDataAdapter(sqlCmd)
                  sqlDaAdp.Fill(DS)
                  sqlCmd = Nothing
                  sqlDaAdp = Nothing
                  CloseConnection(DBType)
                  Return DS
              Catch ex As SqlException
                  If ex.Number = 18456 Or ex.Number = 4060 Then
                      ReturnErrorMsg = "Database Connection Error &gt;&gt; Error No : " &amp; ex.Number
                  Else
                      ReturnErrorMsg = "SQL Statement Error &gt;&gt; Error No : " &amp; ex.Number
                  End If
                  CloseConnection(DBType)
                  Return Nothing
              End Try
          ElseIf DBType = 3 Then
              Try
                  OpenConnection(DBConnString, DBType)
                  Dim oledbCmd As New OleDbCommand(SqlString, oleDbconn)
                  Dim oledbDaAdp As New OleDbDataAdapter(oledbCmd)
                  oledbDaAdp.Fill(DS)
                  oledbDaAdp = Nothing
                  oledbDaAdp = Nothing
                  CloseConnection(DBType)
                  Return DS
              Catch ex As OleDbException
                  If ex.ErrorCode = -2147217887 Then
                      ReturnErrorMsg = "Database Connection Error &gt;&gt; Error Code : " &amp; ex.ErrorCode
                  Else
                      ReturnErrorMsg = "SQL Statement Error &gt;&gt; Error Code : " &amp; ex.ErrorCode
                  End If
                  CloseConnection(DBType)
                  Return Nothing
              End Try
          End If
          '
          Return Nothing
          '
      End Function
  </code></pre>
  
  <p>Open connection method:</p>
  
  <pre><code>Public Sub OpenConnection(ByVal DBStrConn As String, ByVal DBType As Int16)
          Try
              If DBType = 1 Then
                  sqlConn = New SqlConnection(DBStrConn)
                  If sqlConn.State = ConnectionState.Closed Then
                      sqlConn.Open()
                  Else
                      sqlConn.Close()
                      sqlConn.Open()
                  End If
              ElseIf DBType = 3 Then
                  oleDbconn = New OleDbConnection(DBStrConn)
                  If oleDbconn.State = ConnectionState.Closed Then
                      oleDbconn.Open()
                  Else
                      oleDbconn.Close()
                      oleDbconn.Open()
                  End If
              End If
              '
          Catch ex As Exception
              Throw
          End Try
  
      End Sub
  </code></pre>
  
  <p><strong>End of edited part</strong></p>
  
  <p>Does anyone have any idea why does such exception would occur? </p>
  
  <p>So far, I've done the following to actually try to debug this issue:</p>
  
  <ol>
  <li>Restart IIS</li>
  <li>Restart Application Pool</li>
  <li>Recycle Application Pool (every 12 hours, 8 a.m. and 8 p.m. specifically)</li>
  <li>Restart SQL Server Service</li>
  </ol>
  
  <p>None of the above worked. But when I actually tried accessing the application from a specific floor in which is the Security Team floor, the application actually starts functioning as usual, and others could actually access the application as well.</p>
  
  <p>Please help, I'm totally going out of my mind about this issue.</p>
  
  <p>Does it have anything to do with my deployment method, iis configuration or programming, I'm willing to listen to suggestions.</p>
  
  <p>Thanks for your time.</p>