SQL ConnectionString property has not been initialized

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Good evening everyone!!
So dig this..... ill show you the code first off...
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public <span style="color:Blue; partial <span style="color:Blue; class Form1 : Form
{
SqlConnection cs = <span style="color:Blue; new SqlConnection(<span style="color:#A31515; @"Data Source=MyDataSource;Database=MyDatabaseIntegrated Security=True");
SqlDataAdapter da = <span style="color:Blue; new SqlDataAdapter();

<span style="color:Blue; private <span style="color:Blue; void btnEditConfirm_Click(<span style="color:Blue; object sender, EventArgs e)
{
DialogResult dr = <span style="color:Blue; new System.Windows.Forms.DialogResult();
<span style="color:Blue; string CallNumber = <span style="color:#A31515; "NULL";
<span style="color:Blue; string TotalMonthlyCharges = <span style="color:#A31515; "0.00";
<span style="color:Blue; string Usage = <span style="color:#A31515; "0.00";
<span style="color:Blue; string ExtraFields = <span style="color:#A31515; "NULL";
<span style="color:Green; //(@Vendor_ID, @Service_ID, @EID, @Serial, @ItemRegion,@Model, @CallNumber, @IMEI, @TotalMonthlyCharges, @Usage, @Name, @SBG, @SBU, @Country, @Region, @ExtraFields)", cs); @TotalMonthlyCharges, @Usage, @Name, @SBG, @SBU, @Country, @Region, @ExtraFields)", cs);
da.UpdateCommand = <span style="color:Blue; new SqlCommand
(<span style="color:#A31515; "UPDATE dbo.item SET Vendor_ID = @Vendor_ID, Service_ID = @Service_ID, EID = @EID, Serial = @Serial, ItemRegion = @ItemRegion, Model=@Model, CallNumber= @CallNumber, IMEI = @IMEI, TotalMonthlyCharges = @TotalMonthlyCharges, Usage = @Usage, Name = @Name, SBG= @SBG, Country= @Country, Region = @Region, ExtraFields= @ExtraFields WHERE EID= @EID", cs);
da.UpdateCommand.Parameters.Add(<span style="color:#A31515; "@Vendor_ID", SqlDbType.Int).Value = Convert.ToInt32(tbCarrierEdit.Text);
da.UpdateCommand.Parameters.Add(<span style="color:#A31515; "@Service_ID", SqlDbType.Int).Value = Convert.ToInt32(tbDeviceEdit.Text);
da.UpdateCommand.Parameters.Add(<span style="color:#A31515; "@EID", SqlDbType.VarChar).Value = tbEIDEdit.Text;
da.UpdateCommand.Parameters.Add(<span style="color:#A31515; "@Serial", SqlDbType.VarChar).Value = tbNumberEdit.Text;
da.UpdateCommand.Parameters.Add(<span style="color:#A31515; "@ItemRegion", SqlDbType.VarChar).Value = tbRegionEdit.Text;
da.UpdateCommand.Parameters.Add(<span style="color:#A31515; "@Model", SqlDbType.NVarChar).Value = tbModelEdit.Text;
da.UpdateCommand.Parameters.Add(<span style="color:#A31515; "@CallNumber", SqlDbType.VarChar).Value = CallNumber;
da.UpdateCommand.Parameters.Add(<span style="color:#A31515; "@IMEI", SqlDbType.VarChar).Value = tbIMEINumberEdit.Text;
da.UpdateCommand.Parameters.Add(<span style="color:#A31515; "@TotalMonthlyCharges", SqlDbType.Money).Value = TotalMonthlyCharges;
da.UpdateCommand.Parameters.Add(<span style="color:#A31515; "@Usage", SqlDbType.Money).Value = Usage;
da.UpdateCommand.Parameters.Add(<span style="color:#A31515; "@Name", SqlDbType.NVarChar).Value = tbDisplayNameEdit.Text;
da.UpdateCommand.Parameters.Add(<span style="color:#A31515; "@SBG", SqlDbType.VarChar).Value = tbSBGEdit.Text;
da.UpdateCommand.Parameters.Add(<span style="color:#A31515; "@SBU", SqlDbType.VarChar).Value = tbSBUEdit.Text;
da.UpdateCommand.Parameters.Add(<span style="color:#A31515; "@Country", SqlDbType.VarChar).Value = tbCountryEdit.Text;
da.UpdateCommand.Parameters.Add(<span style="color:#A31515; "@Region", SqlDbType.VarChar).Value = tbRegionEdit.Text;
da.UpdateCommand.Parameters.Add(<span style="color:#A31515; "@ExtraFields", SqlDbType.Xml).Value = ExtraFields;

cs.Open();
da.UpdateCommand.ExecuteNonQuery();
cs.Dispose();
<span style="color:Green; //now here if i take out the "cs.Dispose" the code works fine
<span style="color:Green; //do i need this dispose command?
cs.Close();


MessageBox.Show(<span style="color:#A31515; "Please verify that the modification is correct before you continue", <span style="color:#A31515; "Agent-Aid Advisor", MessageBoxButtons.OKCancel, MessageBoxIcon.Stop);
<span style="color:Blue; if (dr == DialogResult.Cancel)
{
MessageBox.Show(<span style="color:#A31515; "You have cancled the opperation", <span style="color:#A31515; "Agent-Aid Advisor", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

<span style="color:Blue; this.btnEditAsset.Visible = <span style="color:Blue; false;
<span style="color:Blue; this.btnEditCancel.Visible = <span style="color:Blue; false;
<span style="color:Blue; this.btnEditConfirm.Visible = <span style="color:Blue; false;
<span style="color:Blue; this.btnConfirmAddition.Visible = <span style="color:Blue; false;
<span style="color:Blue; this.panEdit.Visible = <span style="color:Blue; false;
<span style="color:Blue; this.btnRemoveAsset.Visible = <span style="color:Blue; true;
<span style="color:Blue; this.btnAddAsset.Visible = <span style="color:Blue; true;
<span style="color:Blue; this.btnEditAsset.Visible = <span style="color:Blue; true;
<span style="color:Blue; this.tbEID.Text = <span style="color:#A31515; "";
<span style="color:Blue; this.tbDisplayName.Text = <span style="color:#A31515; "";
<span style="color:Blue; this.MaskedTBSerial.Text = <span style="color:#A31515; "";
<span style="color:Blue; this.Device.Items.Clear();
<span style="color:Blue; this.maskedTBRegion.Text = <span style="color:#A31515; "";
<span style="color:Blue; this.maskedTBCountry.Text = <span style="color:#A31515; "";
<span style="color:Blue; this.btnClear.Visible = <span style="color:Blue; true;
cs.Dispose();



}


[/code]
What gives? I have always used the Dispose command, i thought that this was a 100% needed thing.. when i take it out, then i dont get the error, but will this cause any issues with performance?
Please advise thanks!! <hr class="sig Loving life since 1981 Preston Lambeth

View the full article
 
Back
Top