Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-03-19
7
Medium Priority
?
3,040 Views
Last Modified: 2008-01-09
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.
0
Comment
Question by:Junior_Developer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 37

Expert Comment

by:samtran0331
ID: 18751516
have a look at this:
http://www.c-sharpcorner.com/UploadFile/dclark/InsOutsinCS11302005072332AM/InsOutsinCS.aspx

towards the bottom (right above the final "summary"), it shows you how to define a parameter for output and then get that value back....
0
 

Author Comment

by:Junior_Developer
ID: 18751804
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,
0
 
LVL 15

Accepted Solution

by:
Thogek earned 2000 total points
ID: 18752229
To start, make sure you know how to retrieve the connection string itself, which you can get at http://msdn2.microsoft.com/en-us/library/ms178411.aspx.

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");

with

    SqlConnection cnPubs = new SqlConnection(connString);

where connString is populated as given in http://msdn2.microsoft.com/en-us/library/ms178411.aspx.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 9

Expert Comment

by:sun4sunday
ID: 18754546
Go to Web.Config file

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


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

SqlConnection sqlcon = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
0
 
LVL 9

Expert Comment

by:sun4sunday
ID: 18754554
For using the stored procedure check out the web , there are plently of tutorials one is below
http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson07.aspx

sun4sudnay
0
 

Author Comment

by:Junior_Developer
ID: 18756160
Thogek,
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"

0
 
LVL 15

Expert Comment

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

    SqlConnection cnPubs = new SqlConnection(connString.ConnectionString);
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question