ERROR:The ConnectionString property has not been initialized

Posted by Parthibansk under ASP.NET on 4/19/2013 | Points: 10 | Views : 1515 | Status : [Member] | Replies : 3
I GET THE ERROR:

The ConnectionString property has not been initialized.
==================================================

public partial class j : System.Web.UI.Page
{
// SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["EMPLOYEEConnectionString2"].ConnectionString);
int intcount;
SqlCommand cmd;
string sqlstr;
int count;
String strConnString = ConfigurationManager.ConnectionStrings["EMPLOYEEConnectionString2"].ConnectionString;
SqlConnection con = new SqlConnection();




protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnSave_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "JOINMAX";
cmd.Parameters.Add("@NAME", SqlDbType.VarChar).Value = txtName.Text.Trim();
cmd.Parameters.Add("@EMAIL", SqlDbType.VarChar).Value =txtEMAIL.Text.Trim();
cmd.Parameters.Add("@PHONENO", SqlDbType.VarChar).Value =txtPHONE.Text.Trim();
cmd.Parameters.Add("@ERROR", SqlDbType.Char, 500);
cmd.Parameters["@ERROR"].Direction = ParameterDirection.Output;






cmd.Connection = con;
try
{
con.Open();
cmd.ExecuteNonQuery();
string message = (string)cmd.Parameters["@ERROR"].Value;
Label1.Text = "Record inserted successfully";
}
catch (Exception ex)
{
throw ex;
}
finally
{

con.Close();
con.Dispose();
}




Responses

Posted by: Satyapriyanayak on: 4/19/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
public partial class j : System.Web.UI.Page
{
// SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["EMPLOYEEConnectionString2"].ConnectionString);
int intcount;
SqlCommand cmd;
string sqlstr;
int count;
String strConnString = ConfigurationManager.ConnectionStrings["EMPLOYEEConnectionString2"].ConnectionString;





protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnSave_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "JOINMAX";
cmd.Parameters.Add("@NAME", SqlDbType.VarChar).Value = txtName.Text.Trim();
cmd.Parameters.Add("@EMAIL", SqlDbType.VarChar).Value =txtEMAIL.Text.Trim();
cmd.Parameters.Add("@PHONENO", SqlDbType.VarChar).Value =txtPHONE.Text.Trim();
cmd.Parameters.Add("@ERROR", SqlDbType.Char, 500);
cmd.Parameters["@ERROR"].Direction = ParameterDirection.Output;






cmd.Connection = con;
try
{
con.Open();
cmd.ExecuteNonQuery();
string message = (string)cmd.Parameters["@ERROR"].Value;
Label1.Text = "Record inserted successfully";
}
catch (Exception ex)
{
throw ex;
}
finally
{

con.Close();
con.Dispose();
}

If this post helps you mark it as answer
Thanks

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Parthibansk on: 4/19/2013 [Member] Starter | Points: 25

Up
0
Down
fine..got it..but records inserted message not displaying

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 4/19/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
public partial class j : System.Web.UI.Page
{
// SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["EMPLOYEEConnectionString2"].ConnectionString);
int intcount;
SqlCommand cmd;
string sqlstr;
int count;
String strConnString = ConfigurationManager.ConnectionStrings["EMPLOYEEConnectionString2"].ConnectionString;





protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnSave_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "JOINMAX";
cmd.Parameters.Add("@NAME", SqlDbType.VarChar).Value = txtName.Text.Trim();
cmd.Parameters.Add("@EMAIL", SqlDbType.VarChar).Value =txtEMAIL.Text.Trim();
cmd.Parameters.Add("@PHONENO", SqlDbType.VarChar).Value =txtPHONE.Text.Trim();
//cmd.Parameters.Add("@ERROR", SqlDbType.Char, 500);
//cmd.Parameters["@ERROR"].Direction = ParameterDirection.Output;







cmd.Connection = con;
try
{
con.Open();
cmd.ExecuteNonQuery();
//string message = (string)cmd.Parameters["@ERROR"].Value;
Label1.Text = "Record inserted successfully";
}
catch (Exception ex)
{
throw ex;
}
finally
{

con.Close();
con.Dispose();
}

If this post helps you mark it as answer
Thanks

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response