DBCommandWrapper?? WHERE IS IT? RRS feed

  • Question

  • User1141873794 posted

    I'm attempting to learn and use the data aplication block and there are lots of samples available.  Currently, I'm trying to get a paramaterized query to work but all examples use the DBCommandWrapper object and I can't seem to locate this in intellisense.  What references and imports are required?  Anything else that might be helpful would certainly be appreciated too!


    Wednesday, March 29, 2006 3:01 PM

All replies

  • User-109659422 posted

    Hello !

    You can get a DBCommandWrapper from your database object. But, both DBCommandWrapper and Database are abstract classes.

    Instead, you can use a specialized version of these classes, such as SqlDatabase and you could use the following code :

    ' In VB.NET
    dim myDB as SqlDatabase = new SqlDatabase
    dim myCommand as DBCommandWrapper = myDB.GetSqlStringCommandWrapper("SELECT * FROM Employees")

    // In C#
    SqlDatabase myDB = new SqlDatabase();
    DBCommandWrapper myCommand = myDB.GetSqlStringCommandWrapper("SELECT * FROM Employees");

    Hope it helps


    Wednesday, March 29, 2006 4:26 PM
  • User1141873794 posted

    Thanks for the reply but this is exactly what I've found online.  I am unable to get this to work either because I'm missing a reference or import somewhere.  I believe that part of my problem is that I just don't understand how abstract objects work.  Can someone tell me what I need to add/reference/create, etc. to get this to work?  From here I can back-track and find out the inner workings.

    FYI, when I cut and paste your code I get 'sqldatabase is not defined'

    What am I missing or doing wrong?



    Wednesday, March 29, 2006 4:53 PM
  • User-109659422 posted

    Mmmh, sorry, my answer was not precise enough.

    First, be sure you have the following references in your project :

    The SqlDatabase is in the Microsoft.Practices.EnterpriseLibrary.Data.Sql

    Then, to create your database object, you could do this (this was missing in my previous post) :

    dim myDB as Database = DatabaseFactory.CreateDatabase()

    This will read your configuration file to get the connection string and other info needed by the EnterpriseLibrary to build the database object.


    I hope this time it's a little bit clearer than my previous post.


    Thursday, March 30, 2006 1:49 AM
  • User1141873794 posted

    Thanks again for your help.

    My whole point of doing this was to learn about the abstract objects that are not tied into a specific database type. If I decide to change from sql server to oracle all I need to do is change config items.  Now for practicality, I've never worked with Oracle, so this is just for my own development growth....  I was using the following webpage for a tutorial from 4guysfromRolla.com:  http://aspnet.4guysfromrolla.com/articles/030905-1.aspx

    I already have everything that you're mentioning, but I wonder if my references are a problem.  Currently, I'm using ASP.NET 2.0 with the Enterprise Library Jan, 2006.  My referenced DLLs for this project are : Microsoft.Practices.EnterpriseLibrary.Common.dll

    My imports are currently:
    Imports System.Data
    Imports Microsoft.Practices.EnterpriseLibrary.Common
    Imports Microsoft.Practices.EnterpriseLibrary.Data
    Imports System.Data.Common

    Just FYI, I don't appear to have the
    Microsoft.Practices.EnterpriseLibrary.Configuration.dll, and I can't find this in the bin folder of the installation directory.  There is a configuration.design.dll but I'm not sure if this is the same thing, nor needed.

    Here's the code that currently works (info removed), but I'm still not able to find the DBCommandWrapper object.  I wonder if it's just called something different in this version?

     Dim dr As IDataReader
     Dim db As Database = DatabaseFactory.CreateDatabase("database")
     Dim dbCommand As DbCommand = db.GetStoredProcCommand("sp_Name")
     db.AddInParameter(dbCommand, "Param1", DbType.String, "value")

     dr = db.ExecuteReader(dbCommand)

    Seems nearly the same as most examples, but just not using the same objects.  Thoughts?

    Thanks again for your help!

    Thursday, March 30, 2006 1:27 PM
  • User401872198 posted

    I have the exact same issue.

    download and install the "Enterprise Library for .NET Framework 2.0" from microsoft's website


    Friday, September 15, 2006 9:08 AM
  • User-1892114837 posted

    I downloaded the .net enterprise framework and am still receiving an error.

    Error: Namespace or type specified in the Imports 'Microsoft.Practices.EnterpriseLibrary.Common' doesn't contain any member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member.

     Here are my import statements:

    Imports System.Data

    Imports System.Data.SqlClient

    Imports System

    Imports Microsoft.Practices.EnterpriseLibrary.Common

    Imports Microsoft.Practices.EnterpriseLibrary.Data

    Imports System.Data.Common


    I am working in Visual Web Developer Express 2008. I have also added all the files in the reference option. My bin shows Microsoft.SqlServer.DmfSqlClrWrapper.dll


    Please advise. Thanks!

    Tuesday, January 27, 2009 2:20 PM