Last post Jan 27, 2009 02:20 PM by ocos
Mar 29, 2006 03:01 PM|Skydiver|LINK
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!
Mar 29, 2006 04:26 PM|yvespeneveyre|LINK
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
Mar 29, 2006 04:53 PM|Skydiver|LINK
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?
Mar 30, 2006 01:49 AM|yvespeneveyre|LINK
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.
Mar 30, 2006 01:27 PM|Skydiver|LINK
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:
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:
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!
Sep 15, 2006 09:08 AM|djlao|LINK
I have the exact same issue.
download and install the "Enterprise Library for .NET Framework 2.0" from microsoft's website
Jan 27, 2009 02:20 PM|ocos|LINK
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:
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!