title: query string is throwing exception for being null when its not
body: <p>Here is whats happening , If the user is logged in - this is called directly from Page_Load</p>
  
  <pre><code>Protected Sub EnterNewTransInDb()
          Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("connstring").ConnectionString)
          Dim comm As New SqlCommand("INSERT INTO tblRegisterRedirect (RegID , UserID, EventID, TimeStamp) VALUES (@RegID, @UserID, @EventID , getdate()) ;", conn)
  
          Dim RegID As Guid
          RegID = Guid.NewGuid()
          Dim GIUDuserid As Guid
          GIUDuserid = New Guid(HttpContext.Current.Request.Cookies("UserID").Value.ToString())
          Dim GIUDevnetid As New Guid(HttpContext.Current.Request.QueryString("id").ToString())
          comm.Parameters.AddWithValue("@RegID", RegID)
          comm.Parameters.AddWithValue("@UserID", GIUDuserid)
          comm.Parameters.AddWithValue("@EventID", GIUDevnetid)
  
          Try
              conn.Open()
              Dim i As Integer = comm.ExecuteNonQuery()
              conn.Close()
          Catch ex As Exception
              Dim errors As String = ex.ToString()
          End Try
          Dim URL As String = Request.QueryString("url").ToString()
          Response.Redirect(URL + "?aid=854&amp;rid=" + RegID.ToString())
      End Sub
  </code></pre>
  
  <p>This works great, but if their not logged in , then they enter their log-in credentials - this happens on Button_Click event, in the click event I call this function <code>EnterNewTransInDb()</code> , When I run it this time , after logging in - SAME CODE , it throws an exception - Object reference is null - referring to the querystring</p>
  
  <pre><code> Protected Sub btnLogin_Click(sender As Object, e As System.EventArgs) Handles btnLogin.Click
        'took out code SqlConnection onnection and SqlDataReader Code
          dbCon.Open()            
  
          'If Email and PW are found
          If dr.Read Then
              Dim appCookie As New HttpCookie("UserID")
              appCookie.Value = dr("GUID").ToString()
              appCookie.Expires = DateTime.Now.AddDays(30)
              HttpContext.Current.Response.Cookies.Add(appCookie)
  
              Dim appCookie1 As New HttpCookie("UserName")
              appCookie1.Value = dr("UserName").ToString
              appCookie1.Expires = DateTime.Now.AddDays(30)
              HttpContext.Current.Response.Cookies.Add(appCookie1)
  
              Dim appCookie2 As New HttpCookie("UserEmail")
              appCookie2.Value = txtEmail.Text.ToLower()
              appCookie2.Expires = DateTime.Now.AddDays(30)
              HttpContext.Current.Response.Cookies.Add(appCookie2)
  
              Dim appCookie3 As New HttpCookie("Lat")
              appCookie3.Value = dr("GeoLat").ToString()
              appCookie3.Expires = DateTime.Now.AddDays(30)
              HttpContext.Current.Response.Cookies.Add(appCookie3)
  
              Dim appCookie4 As New HttpCookie("Long")
              appCookie4.Value = dr("GeoLong").ToString()
              appCookie4.Expires = DateTime.Now.AddDays(30)
              HttpContext.Current.Response.Cookies.Add(appCookie4)
  
              Dim appCookie5 As New HttpCookie("City")
              appCookie5.Value = dr("City").ToString()
              appCookie5.Expires = DateTime.Now.AddDays(30)
              HttpContext.Current.Response.Cookies.Add(appCookie5)
  
              Dim appCookie6 As New HttpCookie("State")
              appCookie6.Value = dr("State").ToString
              appCookie6.Expires = DateTime.Now.AddDays(30)
              HttpContext.Current.Response.Cookies.Add(appCookie6)
  
              HttpContext.Current.Response.Cookies("EO_Login").Expires = Now.AddDays(30)
              HttpContext.Current.Response.Cookies("EO_Login")("EMail") = txtEmail.Text.ToLower()
  
              Dim sUserData As String = HttpContext.Current.Server.HtmlEncode(HttpContext.Current.Request.Cookies("UserID").Value) &amp; "|" &amp; HttpContext.Current.Server.HtmlEncode(HttpContext.Current.Request.Cookies("UserName").Value) &amp; "|" &amp; HttpContext.Current.Server.HtmlEncode(HttpContext.Current.Request.Cookies("UserEmail").Value)
              ' Dim sUserData As String = "dbcf586f-82ac-4aef-8cd0-0809d20c70db|scott selby|scottselby@live.com"
              Dim fat As FormsAuthenticationTicket = New FormsAuthenticationTicket(1, _
                       dr("UserName").ToString, DateTime.Now, _
                       DateTime.Now.AddDays(6), True, sUserData, _
                       FormsAuthentication.FormsCookiePath)
              Dim encTicket As String = FormsAuthentication.Encrypt(fat)
              HttpContext.Current.Response.Cookies.Add(New HttpCookie(FormsAuthentication.FormsCookieName, encTicket))
  
              'If Email and Pw are not found
          Else
              dr.Close()
              dbCon.Close()
  
          End If
  
          'Always do this
          dr.Close()
          sSql = "UPDATE eo_Users SET LastLogin=GETUTCDATE() WHERE GUID=@GUID; "
          cmd = New SqlCommand(sSql, dbCon)
          cmd.Parameters.AddWithValue("@GUID", HttpContext.Current.Session("UserID"))
          cmd.ExecuteNonQuery()
          dbCon.Close()
          EnterNewTransInDb()
          'Dim URL As String = Request.QueryString("url").ToString()
          'Response.Redirect(URL + "?aid=854&amp;rid=" + RegID.ToString())
      End Sub
  </code></pre>