ASP.NET Object reference not set to an instance of an object
<p>I have no problem in local. But I get this error in uploaded website:</p>

<blockquote>
  <p>Object reference not set to an instance of an object.</p>
</blockquote>

<p>In <a href="http://support.microsoft.com/kb/810098" rel="nofollow">this</a> link it says this is a bug with ADO but I dont use ADO in my code.</p>

<p>Here is my code:</p>

<pre><code>        SqlConnection sc = new SqlConnection();
        sc.ConnectionString = MyConnectionString;
        sc.Open();
        SqlCommand scm = new SqlCommand(INSERT COMMAND);
        scm.Connection = sc;
        scm.ExecuteNonQuery();
        sc.Close();
</code></pre>

<p>I put my above code in <code>USING</code> statements and nothing changed.</p>

<p>Here is my stack trace </p>

<blockquote>
  <p>NullReferenceException: Object reference not set to an instance of an object.]<br>
  Register.BtnRegister_Click(Object sender, ImageClickEventArgs e) +601<br>
  System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +115<br>
  System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +120  </p>
  
  <p>System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
  eventArgument) +10<br>
  System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13<br>
  System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36<br>
  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563  </p>
</blockquote>

<p>And here is <code>BtnRegister_Click</code> code:</p>

<pre><code>    protected void BtnRegister_Click(object sender, ImageClickEventArgs e)
    {
    if (TxtName.Text == "" || TxtFamily.Text == "" || txtNationalCode.Text == "" || TxtIdNumber.Text == "" || txtMobile.Text == "" || TxtEmail.Text == "" || txtAddress.Text == "" || TxtSecurityCode.Text == "")
    {
        LblMsg.Text = "You should fill all fields";
        return;
    }

    if (txtNationalCode.Text.Length != 10)
    {
        LblMsg.Text = "National code must have 10 digits";
        return;
    }

    if (txtMobile.Text.Length != 11)
    {
        LblMsg.Text = "Mobile number should have 11 digits";
        return;
    }

    if (T_Paticipant.GetDataByNationalCode(txtNationalCode.Text).Rows.Count &gt; 0)
    {
        LblMsg.Text = "This national code used before";
        return;
    }

    if (T_Paticipant.GetDataByEmail(TxtEmail.Text).Rows.Count &gt; 0)
    {
        LblMsg.Text = "This email used before";
        return;
    }

    LblMessage.Text = "Are you sure to register?";
    LblFlag.Text = "0";


    //captcha

    if (this.Session["CaptchaImageText"].ToString().ToLower() == TxtSecurityCode.Text.ToLower())
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), "showMessage()", "&lt;script&gt;ShowMessage() &lt;/script&gt;");
    }
    else
    {
        LblMsg.ForeColor = System.Drawing.Color.Red;
        LblMsg.Text = "Security code is wrong";
    }
    //end captcha
}
</code></pre>

<p>Thank you for help.</p>
