executescalar requires an open and available connection executescalar requires an open and available

Posted by Nandakishore under ASP.NET on 11/9/2012 | Points: 10 | Views : 1404 | Status : [Member] | Replies : 1
executescalar requires an open and available connection executescalar requires an open and available connection im getting this error how to recover it




Responses

Posted by: Rajesh081725 on: 11/9/2012 [Member] Bronze | Points: 25

Up
0
Down
hi ,
try this one

using (SqlConnection con = new SqlConnection(conString))
{
con.Open();

using (cmd = new SqlCommand("SP_DMS", con))
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

SqlCommand cmd = new SqlCommand(@"INSERT INTO [dbo].[main] ([first], [second], [third], [fourth], [fifth], [sixth]) VALUES (@first, @second, @third, @fourth, @fifth, @sixth)", con);
komanda.Parameters.AddWithValue("@first", ..................);
komanda.Parameters.AddWithValue("@second", ..............);
komanda.Parameters.AddWithValue("@third", .................);
komanda.Parameters.AddWithValue("@fourth", ...............);
komanda.Parameters.AddWithValue("@fifth", ..................);
komanda.Parameters.AddWithValue("@sixth", .................);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Session["notice"] = "Success...:";

Response.Redirect("Default.aspx");
// Response.Write("ConnectionStatus:" + con.State.ToString());

ViewState["HeadId"] = Convert.ToString(cmd.ExecuteScalar());
}

}

Time is Gold
Thanks & Regards,
Rajesh Kumar,
9962038582.

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

Login to post response