In C# Connect to database and execute Stored procedure which has output parameter

I am using C# 2005 and SQL server 2005.
I already have default.aspx and web.config file in my application. i just want to connec to database and execute my stored procedure.
Can some one tell me how to do Database connection using Web.config file? as i have defined ConnectionString in Web.config file.
I have created a stored procedure in sql 2005, it takes in 2 input paramenters and return one output parameter. only one value with be return everytime as an output parameter.

Thanks for you help in advance.
Who is Participating?
ThogekConnect With a Mentor Commented:
To start, make sure you know how to retrieve the connection string itself, which you can get at

From there, you can do much as is suggested in the link samtran0331 gave, just replace

    SqlConnection cnPubs = new SqlConnection("server=localhost;integrated security=true;" + "database=pubs");


    SqlConnection cnPubs = new SqlConnection(connString);

where connString is populated as given in
have a look at this:

towards the bottom (right above the final "summary"), it shows you how to define a parameter for output and then get that value back....
Junior_DeveloperAuthor Commented:
The link above is not helpful as it is not using Web.config file's connectstring attribute.
Any other suggestions, it should be pretty straight forward. i am new at 2005 C# .net programming

Waiting for response, thanks,
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Go to Web.Config file

  <add key="ConnectionString" value="server=servername/ IP ;database=DBName;uid=sa;password=password;"/>

On FormLoad(where ever you need) you will get the sqlconnection object

SqlConnection sqlcon = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
For using the stored procedure check out the web , there are plently of tutorials one is below

Junior_DeveloperAuthor Commented:
i am able to get the connection string now but when i use "SqlConnection dbConnection = new SqlConnection(connString);"
i get this error "The best overloaded method match for 'System.Data.SqlClient.SqlConnection.SqlConnection(string)' has some invalid arguments"

Oops.  That connString is actually a ConnectionStringSettings object.  You may need to do something more like:

    SqlConnection cnPubs = new SqlConnection(connString.ConnectionString);
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.