0
String strConnString = ConfigurationManager.ConnectionStrings["EMPLOYEEConnectionString2"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
You have not assigned the connection string to SQLConnection Object.
0
Hello Friend,
The issue lies over here.
you access the connection string value from web.config file
String strConnString = ConfigurationManager.ConnectionStrings["EMPLOYEEConnectionString2"].ConnectionString
You initialized your SqlConnection object
SqlConnection con = new SqlConnection();
and in the btnSave click event
you have not set the SqlConnection ConnectionString property
what you need to do is inside btnSave Click event
con.ConnectionString=strConnString;
and your issue will be solved.
0
Hi...
Can you share the project/website??
It becomes difficult here to explain.
0
hi,
this error might due to wrong Connection string in web config.
can you please share it with us.
else verified your config with following example
<connectionStrings>
<add name="EMPLOYEEConnectionString2" connectionString="Data Source=databaseserverName;user id=sa;password=password;Initial Catalog=databaseName;"/>
</connectionStrings>
hope this will help you.
0
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();
}

0
you can use this code it would be help to you....
SqlConnection cn = new SqlConnection();
cn.ConnectionString = ConfigurationManager.ConnectionStrings["EMPLOYEEConnectionString2"].ConnectionString.ToString();
cn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "JOINMAX";
cmd.Parameters.Add("@NAME", SqlDbType.VarChar).Value = "Gaurav";
cmd.Parameters.Add("@EMAIL", SqlDbType.VarChar).Value = "@gmail.com";
cmd.Parameters.Add("@PHONENO", SqlDbType.VarChar).Value = "9711182587";
cmd.Parameters.Add("@ERROR", SqlDbType.Char, 500);
cmd.Parameters["@ERROR"].Direction = ParameterDirection.Output;
cmd.Connection = cn;
try
{
cmd.ExecuteNonQuery();
string message = (string)cmd.Parameters["@ERROR"].Value;
string msg = "Record inserted successfully";
}
catch (Exception ex)
{
throw ex;
}
finally
{
cn.Close();
cn.Dispose();
}