Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have written this code

C#
static string _con = ConfigurationManager.ConnectionStrings["tours_travel"].ConnectionString;
   SqlConnection con = new SqlConnection(_con);



but while using with stored procedure there is an error of instance failure on

cmd.Connection = con;


C#
cmd.CommandText = "usp_packageinsert";
       cmd.CommandType = CommandType.StoredProcedure;
       cmd.Parameters.AddWithValue("@package_name", txtpname.Text);
       cmd.Parameters.AddWithValue("@package_description", txtpdesc.Text);
       int check = 0;
       cmd.Connection = con;
       con.Open();
       check = cmd.ExecuteNonQuery();
       con.Close();
       if (check == 1)
       {
           lblmsg.Visible = true;
           lblmsg.Text = "Package added";
       }
Posted
Comments
uspatel 4-Apr-13 3:41am    
share your connection string you have uses.....
Member 9671810 4-Apr-13 3:44am    
<connectionstrings>
<add name="tours_travel" connectionstring="Data Source=EXPERT-17A055DD\\SQLEXPRESS;Initial Catalog=Tours_Travel_System;Integrated Security=True;Pooling=False"></add>
</connectionstrings>

1 solution

Hi,

Why are you using static string variable in the first place?
Code your connection string something as below:

C#
SqlConnection xconn = new SqlConnection(ConfigurationManager.ConnectionString["connectionStrings"].ToString());


where connectionStrings is defined in the config file. You might wana also check your Data Source name in the config file.
Try these stuffs and then debug, it should work.

-Anurag
 
Share this answer
 
Comments
Member 9671810 4-Apr-13 3:48am    
i have tried yours but same error.
i have my connection string in web config.. and i used static just cauze i have declared it as global i mean in class.
Anurag Sinha V 4-Apr-13 4:03am    
Hmm..thanks for the info..
I guess you need to remove the double slash from your connection string.
Instead of EXPERT-17A055DD\\SQLEXPRESS, it should be EXPERT-17A055DD\SQLEXPRESS...
check the following link:http://stackoverflow.com/questions/1830824/instance-failure-in-asp-net

-Anurag
Member 9671810 4-Apr-13 9:11am    
oh.. thanx.. a lot... :)
Anurag Sinha V 4-Apr-13 9:31am    
np..enjoy..

-anurag

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900