title: ASP.NET Unexpected and Different Behavior in Different Environments
body: <p>I have an ASP.NET site (VB.NET) that I'm trying to clean up. When it was originally created it was written with no error handling, and I'm trying to add it in to improve the User Experience.</p>
  
  <pre><code>Try
      If Not String.IsNullOrEmpty(strMfgName) And Not String.IsNullOrEmpty(strSortType) Then
          If Integer.TryParse(Request.QueryString("CategoryID"), i) And String.IsNullOrEmpty(Request.QueryString("CategoryID")) 
              MyDataGrid.DataSource = ProductCategoryDB.GetMfgItems(strMfgName, strSortType, i)
          Else
              MyDataGrid.DataSource = ProductCategoryDB.GetMfgItems(strMfgName, strSortType)
          End If
          MyDataGrid.DataBind()
  
          If CType(MyDataGrid.DataSource, DataSet).Tables("Data").Rows.Count &gt; 0 Then
              lblCatName.Text = CType(MyDataGrid.DataSource, DataSet).Tables("Data").Rows(0).Item("mfgName")
          End If
  
          If MyDataGrid.Items.Count &lt; 2 Then
              cboSortTypes.Visible = False
              table_search.Visible = False
          End If
          If MyDataGrid.PageCount &lt; 2 Then
              MyDataGrid.PagerStyle.Visible = False
          End If
      Else
          lblCatName.Text &amp;= "&lt;br /&gt;&lt;span style=""fontf-size: 12px;""&gt;There are no items for this manufacturer&lt;/span&gt;"
          MyDataGrid.Visible = False
          table_search.Visible = False
      End If
  Catch
      lblCatName.Text &amp;= "&lt;br /&gt;&lt;span style=""font-size: 12px;""&gt;There are no items for this manufacturer&lt;/span&gt;"
      MyDataGrid.Visible = False
      table_search.Visible = False
  End Try
  </code></pre>
  
  <p>Now, this is trying to avoid generating a 500 error by catching exceptions. There can be three items on the query string, but only two matter here. In my test environment and in Visual Studio when I run this site, it doesn't matter if that item is on the query string. In production, it does matter. If that third item isn't present (SubCategoryID) on the query string, then the "There are no items for this manufacturer" displays instead of the data from the database.</p>
  
  <p>In the two different environments I am seeing two different code execution paths, despite the same URLs and the same code base.</p>
  
  <p>The site is running on Server 2003 with IIS 6.</p>
  
  <p>Thoughts?</p>
  
  <p>EDIT:
  In response to the answer below, I doubt it's a connection error (though I see what you're getting to), as when I add the SubCategoryID to the query string, the site works correctly (displaying data from the database).</p>
  
  <p>Also, if please let me know if you have any suggestions for how to test this scenario, without deploying the code back to production (it's been rolled back).</p>