Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6337137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:11:41+00:00 2026-05-24T19:11:41+00:00

using c# vs2008 winforms. My standard forms have a typical usage pattern of Form

  • 0

using c# vs2008 winforms.

My standard forms have a typical usage pattern of
Form load
Sqlconnection object open.

read/write datasets using sqldataadaptors
read many things using sql readers
write many data using stored procedures to write

close sql connection
close form

So whats best practice in handling exceptions in this type of usage pattern
I enclose all read and write code to the sql server in try catch clauses to trap exceptions.

So what do i do when i trap an exception ?
Should i close and dispose all sql objects ?
Should i close the form and dispose the form.
Should i try to let the user continue on
Should i try to re-open my sqlconnection if the exception is that the sql connection broken ?
Given that i open and close connections on form load and close, as that it only in theory opens once and closes once with many reads and writes inbetween.

I’m just not sure what action i should be taking when i trap an exception, to prevent memory and resource leaks.

any advice appreciated

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T19:11:43+00:00Added an answer on May 24, 2026 at 7:11 pm

    It depends on the exception you receive and its severity. If it was error number 1205, you would want to retry, as that’s the SQL Server deadlock error. e.g

    catch (SqlException sqlEx)
    {    
        if (sqlEx.Number == 1205)    
        {        
            // Deadlock occurred, retry...    
        }    
        else        
            throw;
    }
    

    For unrecoverable errors, you would want to clean up and dispose of connections etc.

    Best practice is to use using blocks whenever an object implements IDisposable (such as a SqlConnection, SqlCommand, etc.)

    To get a complete list of error codes, run this TSQL:

    SELECT * FROM sysmessages
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using VS2008 to develop a WinForms 2.0 application. I have read about
Using winforms in vs2008. I have a DataGridView and I would like to detect
In my C#-WinForms-application (.Net 3.5, VS2008) I read the App.Config using: Configuration myConfig =
Using c# vs2008 winforms I have an application with a bunch of child winforms.
using c# winforms vs2008 I've got a textbox on a form with a method
I have to following code in VS2008 .net 3.5 using WinForms: byte percent =
Using VS2008, C#, .Net 2 and Winforms how can I make a regular Button
Using C# and WinForms in VS2008, I want to create a file browser control
using c#, vs2008, winforms If i am passing a parameter via a property to
Using VS2008 C# am attempting to interop a C++ dll. Have a C++ class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.