Disposing the database object RRS feed

  • Question

  • User-73514677 posted


    i am using the Data Access Application Block of the Enterprise library 2.0. In the code, i have used:

    Database db= DatabaseFactory.CreateDatabase ();

    int intRowID;



    string strQuery= "select row_id from Users where login_name='" + strUserName.Trim() + "'";

    intRowID = Convert.ToInt32 (db.ExecuteScalar(CommandType.Text ,strQuery));

    return intRowID;


    catch (Exception ex)


    throw new Exception(ex.Message);



    Is it possible to dispose the database object? If yes, how to achieve that?

    please help

    Thursday, December 14, 2006 4:56 AM


  • User1178851682 posted

    From Enterprise library document, you dont need to dispose database object.

    If you are worried about connection open issue then you can use using() or try..catch..funally to close connection.


    PS. for db.ExecuteScalar....you dont need to worry about connection. it will close it for you.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 27, 2006 5:00 AM