Click here to Skip to main content
15,889,216 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionC# , WebSockets - HTTPS Pin
sgeorge10615-Jul-14 0:46
sgeorge10615-Jul-14 0:46 
AnswerRe: C# , WebSockets - HTTPS Pin
Wonderful Coder16-Jul-14 17:32
Wonderful Coder16-Jul-14 17:32 
AnswerRe: C# , WebSockets - HTTPS Pin
Wonderful Coder16-Jul-14 17:35
Wonderful Coder16-Jul-14 17:35 
QuestionPerformance testing for 500 concurrent users ends with 100% CPU Utilization on DB Server Pin
antony beula14-Jul-14 3:22
antony beula14-Jul-14 3:22 
AnswerRe: Performance testing for 500 concurrent users ends with 100% CPU Utilization on DB Server Pin
Kornfeld Eliyahu Peter14-Jul-14 3:31
professionalKornfeld Eliyahu Peter14-Jul-14 3:31 
AnswerRe: Performance testing for 500 concurrent users ends with 100% CPU Utilization on DB Server Pin
David Mujica14-Jul-14 4:07
David Mujica14-Jul-14 4:07 
GeneralRe: Performance testing for 500 concurrent users ends with 100% CPU Utilization on DB Server Pin
antony beula15-Jul-14 20:32
antony beula15-Jul-14 20:32 
GeneralRe: Performance testing for 500 concurrent users ends with 100% CPU Utilization on DB Server Pin
Richard Deeming16-Jul-14 2:20
mveRichard Deeming16-Jul-14 2:20 
That code will close the connection if it succeeds. If any part of the code throws an exception, however, the connection will remain open.

Both the SqlConnection and SqlCommand classes implement the IDisposable interface. Whenever you create something that implements IDisposable, use it within a single method, and then throw it away, you should wrap it in a using block to ensure that the Dispose method is always called.

Also, since you're using a data adapter, you don't need to explicitly open and close the connection; the data adapter will take care of that for you.

C#
using (SqlConnection con = new SqlConnection(GetConnectionString()))
using (SqlCommand cmd = new SqlCommand(storedProc, con))
{
    cmd.CommandTimeout = Convert.ToInt32(GetCommandTimeout());
    cmd.Parameters.Add(new SqlParameter("@AssociateId", SqlDbType.Int)).Value = AssociateId;
    // Or: cmd.Parameters.AddWithValue("@AssociateId", AssociateId);
    
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataSet dataset = new DataSet();
    da.Fill(dataset);
    
    return dataset;
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Performance testing for 500 concurrent users ends with 100% CPU Utilization on DB Server Pin
antony beula16-Jul-14 20:26
antony beula16-Jul-14 20:26 
Questionhow to use ajax tabcontainer in asp.net mvc 4 Pin
shwe pwint14-Jul-14 1:04
shwe pwint14-Jul-14 1:04 
AnswerRe: how to use ajax tabcontainer in asp.net mvc 4 Pin
thatraja15-Jul-14 1:02
professionalthatraja15-Jul-14 1:02 
QuestionAuthorization not working in Classic mode(Application pools) Pin
sajithnet13-Jul-14 22:37
sajithnet13-Jul-14 22:37 
AnswerRe: Authorization not working in Classic mode(Application pools) Pin
Richard Deeming16-Jul-14 2:13
mveRichard Deeming16-Jul-14 2:13 
GeneralRe: Authorization not working in Classic mode(Application pools) Pin
sajithnet16-Jul-14 22:44
sajithnet16-Jul-14 22:44 
QuestionHelp with ASP.NET Event Calendar Pin
Member 1092961012-Jul-14 8:36
Member 1092961012-Jul-14 8:36 
QuestionWhat is Katna in asp.net Pin
Tridip Bhattacharjee10-Jul-14 21:29
professionalTridip Bhattacharjee10-Jul-14 21:29 
AnswerRe: What is Katna in asp.net Pin
thatraja10-Jul-14 22:03
professionalthatraja10-Jul-14 22:03 
AnswerRe: What is Katna in asp.net Pin
ZurdoDev11-Jul-14 1:51
professionalZurdoDev11-Jul-14 1:51 
AnswerRe: What is Katna in asp.net Pin
Praveen Dselva24-Jul-14 0:09
professionalPraveen Dselva24-Jul-14 0:09 
QuestionSetting the StatusCode of the response Pin
ThetaClear10-Jul-14 0:16
ThetaClear10-Jul-14 0:16 
QuestionRe: Setting the StatusCode of the response Pin
thatraja10-Jul-14 4:35
professionalthatraja10-Jul-14 4:35 
AnswerRe: Setting the StatusCode of the response Pin
ThetaClear10-Jul-14 7:36
ThetaClear10-Jul-14 7:36 
AnswerRe: Setting the StatusCode of the response Pin
thatraja10-Jul-14 21:58
professionalthatraja10-Jul-14 21:58 
GeneralRe: Setting the StatusCode of the response Pin
ThetaClear12-Jul-14 21:37
ThetaClear12-Jul-14 21:37 
GeneralRe: Setting the StatusCode of the response Pin
ThetaClear12-Jul-14 22:54
ThetaClear12-Jul-14 22:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.