cant find sqldatabase object

Dec 9, 2009 at 11:57 AM
Edited Dec 9, 2009 at 11:59 AM

Hi i have installed the EntLib 4.1 added references to

using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Common;

but cant find the SqlDatabase object. For eg.


Database objDB = new SqlDatabase(ConnectionString);

or the

DbCommand object
Dec 9, 2009 at 12:18 PM

It's in the Microsoft.Practices.EnterpriseLibrary.Data.Sql namespace


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.


Dec 9, 2009 at 1:03 PM

Thanx. Got it.

Following an example i got this code. I want to know what happens to opening and closing the connection. Also what about the finally block. where is that taken care of.

Database objDB = new SqlDatabase(DatabaseUtilities.ConnectionString);
            DbCommand cmd;
            using (cmd = objDB.GetStoredProcCommand("GetCustomeById"))
                objDB.AddInParameter(cmd, "@CustomerId", DbType.Int32, customerID);
            IDataReader reader;
            Customer c = new Customer();        
                reader = objDB.ExecuteReader(cmd);
                while (reader.Read())

            catch (Exception ex)
                throw ex;

            return c;

Dec 10, 2009 at 9:29 AM


The daab is responsible for opening/closing the connection. Except for the excecuteReader that must be explicitly closed. Just like what is shown in your code. You can add your finally block if you have other process which you want to add after the execution.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.