OK - I have looked at several similar cases, but I just don't know enough to find the problem. Can anyone tell me why the following code behind file is throwing the error at the bottom of the page?
----------------- Here is the code behind file ----------------
using System;
using System.Text.RegularExpress
ions;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Globalization;
using AspDotNetStorefrontCore;
using System.Data.Sql;
using System.Data.SqlClient;
namespace AspDotNetStorefront
{
public partial class createaccount : SkinBase
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int addResult = 0;
addResult = AddLead(txtCampaignID.Text
, txtEmail.Text);
switch (addResult) {
case 0:
Message.Text = "Success";
goto case -1;
case -1:
Message.Text = "Failure - record already exists";
goto default;
default:
Message.Text = "Please complete ALL required fields and try again.";
break;
}
txtCampaignID.Text = "";
txtEmail.Text = "";
}
using (SqlConnection con = new SqlConnection(DB.GetDBConn
()))
{
con.Open();
dbCommand.CommandText = "spAddLead";
dbCommand.CommandType = CommandType.StoredProcedur
e;
dbCommand.Parameters.Add(n
ew SqlParameter("@FName", SqlDbType.VarChar, 50));
dbCommand.Parameters["@FNa
me"].Value
= txtFName;
dbCommand.Parameters.Add(n
ew SqlParameter("@LName", SqlDbType.VarChar, 50));
dbCommand.Parameters["@LNa
me"].Value
= txtLName;
dbCommand.Parameters.Add(n
ew SqlParameter("@Email", SqlDbType.VarChar, 50));
dbCommand.Parameters["@Ema
il"].Value
= txtEmail;
dbCommand.Parameters.Add(n
ew SqlParameter("@Phone", SqlDbType.VarChar, 50));
dbCommand.Parameters["@Pho
ne"].Value
= txtPhone;
dbCommand.Parameters.Add(n
ew SqlParameter("@Addr1", SqlDbType.VarChar, 50));
dbCommand.Parameters["@Add
r1"].Value
= txtAddr1;
dbCommand.Parameters.Add(n
ew SqlParameter("@Addr2", SqlDbType.VarChar, 50));
dbCommand.Parameters["@Add
r2"].Value
= txtAddr2;
dbCommand.Parameters.Add(n
ew SqlParameter("@City", SqlDbType.VarChar, 50));
dbCommand.Parameters["@Cit
y"].Value = txtCity;
dbCommand.Parameters.Add(n
ew SqlParameter("@State", SqlDbType.VarChar, 50));
dbCommand.Parameters["@Sta
te"].Value
= txtState;
dbCommand.Parameters.Add(n
ew SqlParameter("@Zip", SqlDbType.VarChar, 50));
dbCommand.Parameters["@Zip
"].Value = txtZip;
dbCommand.Parameters.Add(n
ew SqlParameter("@RequestType
", SqlDbType.VarChar, 50));
dbCommand.Parameters["@Req
uestType"]
.Value = QuoteReq;
dbCommand.Parameters.Add(n
ew SqlParameter("@CampaignID"
, SqlDbType.Int));
dbCommand.Parameters["@Cam
paignID"].
Value = txtCampaignID;
dbCommand.Parameters.Add(n
ew SqlParameter("@Result", SqlDbType.Int));
dbCommand.Parameters["@Res
ult"].Dire
ction = ParameterDirection.ReturnV
alue;
int commandResult = 1;
try {
con.Open();
dbCommand.ExecuteNonQuery(
);
commandResult = (int)dbCommand.Parameters[
"@Result"]
.Value;
}
catch (SqlException ex) {
commandResult = ex.Number;
}
finally {
con.Close();
}
return commandResult;
}
}
}
--------------- End Code Behind ----------------------
-------------- Begin Error Msg ----------------------
ExecuteNonQuery: Connection property has not been initialized.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationExc
eption: ExecuteNonQuery: Connection property has not been initialized.
Source Error:
Line 71: int commandResult = 1;
Line 72: try {
Line 73: using (SqlConnection con = new SqlConnection(DB.GetDBConn
()))
Line 74: {
Line 75: con.Open();
Source File: \\fs1-n02\stor2wc1dfw1\400
154\
www.vinylreplacementwindowsquote.com\web\content\_Raleigh.aspx.cs Line: 73
Stack Trace:
[InvalidOperationException
: ExecuteNonQuery: Connection property has not been initialized.]
System.Data.SqlClient.SqlC
ommand.Val
idateComma
nd(String method, Boolean async) +4876133
System.Data.SqlClient.SqlC
ommand.Int
ernalExecu
teNonQuery
(DbAsyncRe
sult result, String methodName, Boolean sendToPipe) +105
System.Data.SqlClient.SqlC
ommand.Exe
cuteNonQue
ry() +137
AspDotNetStorefront.create
account.Ad
dLead(Stri
ng txtCampaignID, String txtEmail) in \\fs1-n02\stor2wc1dfw1\400
154\
www.vinylreplacementwindowsquote.com\web\content\_Raleigh.aspx.cs:73
AspDotNetStorefront.create
account.Bu
tton1_Clic
k(Object sender, EventArgs e) in \\fs1-n02\stor2wc1dfw1\400
154\
www.vinylreplacementwindowsquote.com\web\content\_Raleigh.aspx.cs:26
System.Web.UI.WebControls.
Button.OnC
lick(Event
Args e) +111
System.Web.UI.WebControls.
Button.Rai
sePostBack
Event(Stri
ng eventArgument) +110
System.Web.UI.WebControls.
Button.Sys
tem.Web.UI
.IPostBack
EventHandl
er.RaisePo
stBackEven
t(String eventArgument) +10
System.Web.UI.Page.RaisePo
stBackEven
t(IPostBac
kEventHand
ler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePo
stBackEven
t(NameValu
eCollectio
n postData) +36
System.Web.UI.Page.Process
RequestMai
n(Boolean includeStagesBeforeAsyncPo
int, Boolean includeStagesAfterAsyncPoi
nt) +1565