Results 1 to 2 of 2

Thread: How to use finally()**SOLVED**

  1. #1

    Thread Starter
    Hyperactive Member Sgt-Peppa's Avatar
    Join Date
    Mar 2003
    Location
    Munich - Germany
    Posts
    476

    How to use finally()**SOLVED**

    Hey folks, me again with a simple(at least I hope) problem. How do I use the finally clause! Heres what I am trying to do :
    I open up a connection to a database, and want to close that conn in my finally block, heres my code
    Code:
    public string response_message(string message)
    {
    SqlConnection conn;
    try
    {
    conn = new SqlConnection(sConn);
    }
    catch
    {
    }
    finally
    {
    conn.Close();
    }
    }
    Trying to compile this code i get an error saying it doesnt know the variable conn.
    So how can I use that connection in my finally block?

    Thanx in advance,

    Stephan
    Last edited by Sgt-Peppa; Oct 6th, 2003 at 04:38 AM.
    Keep Smiling - even if its hard
    Frankie Says Relax, wossname Says Yeah!
    wossname:--Currently I'm wearing a gimp suit and a parachute.
    C# - Base64 Blog

  2. #2

    Thread Starter
    Hyperactive Member Sgt-Peppa's Avatar
    Join Date
    Mar 2003
    Location
    Munich - Germany
    Posts
    476
    ups, found my mistake, had to assign a value to conn. So I assigned null, for all interested!

    Thanx, Stephan
    Keep Smiling - even if its hard
    Frankie Says Relax, wossname Says Yeah!
    wossname:--Currently I'm wearing a gimp suit and a parachute.
    C# - Base64 Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width