Microsoft Enterprise Library Data Access Application Blocks Execute Reader (Object must implement IConvertible)

Microsoft Enterprise Library Data Access Application Blocks Execute Reader (Object must implement IConvertible)

I've been trying to get the MS Enterprise Library Data Access Applications Blocks working this morning. Yesterday I got the library setup and running. I started to implement the DAAB so that I could call a stored procedure, passing in a parameter, and retrieving a datareader that I could fill into a class. But I was having some horrible problems trying to get the stored procedure to run and fill the datareader using the DAAB.

I was continually getting the error “Object must implement IConvertible“ and was unable to figure out why this was.

sqlCommand = "spCMS_CustomerLostPasswordEmailAddress";
//parameters
SqlParameter [] parms = {new SqlParameter("@EmailAddress", SqlDbType.VarChar, 50)};
parms[0].Value= identifier;
DBCommandWrapper dbcw = db.GetStoredProcCommandWrapper(sqlCommand,parms);
SqlDataReader dr = db.ExecuteReader(dbcw);

It would return the error while trying to perform the ExecuteReader command.

In order to get the code to successfully function I had to do the following

DBCommandWrapper dbcw = db.GetStoredProcCommandWrapper("spCMS_CustomerLostPasswordEmailAddress");
dbcw.AddInParameter("@EmailAddress", DbType.String, identifier);
SqlDataReader dr = (SqlDataReader)db.ExecuteReader(dbcw);

So if you're looking to use execute reader with the Microsoft Enterprise Library Data Access Application Blocks I hope the above code helps!

Also, some resources I used to figure all of this out!

Enterprise Library / Data Access Application Block Follow-up
An Introduction to the Microsoft Enterprise Library by Scott Mitchell

 

Recent Comments

Comment Avatar
Thanks for the info... I was having the same problem and it was driving me crazy! :)
Posted By: Anonymous Poster on Mar 2005
Comment Avatar
Thanks that worked perfect (VB.NET)
Unfortunately it seems to make the data access code a lot more complex.

Seems it would almost be better to NOT use the Enterprise Library in this situation.


Posted By: Anonymous Poster on May 2005
Comment Avatar
I think it's a bug. ----------------------------------------- [email protected]
Posted By: Anonymous on Jan 2006
Comment Avatar
Instead of SqlDataReader, use IDataReader for your 'dr'. You won't have to cast it and it should work perfectly. Strangely enough though, I use the exact same code in two different application. One works fine and the other is throwing the same exception you're getting.
Posted By: Anonymous on Feb 2006
Comment Avatar
here's the working solution: http://forums.asp.net/p/1560116/3850817.aspx
Posted By: mark ern on Aug 2010

Add Comment

Please add your comment by filling out the field(s) below. Your comment may need to be approved before it becomes visible.
Enter your first name for display with the comment
Enter your last name for display with the comment.
Enter your comment here.
If you can't type DNNRocks in, you can't post, plain and simple.
Submit Comment Cancel

Chris Hammond

Chris Hammond is a father, husband, leader, software developer, photographer and car guy. Chris focuses on the latest in technology including artificial intelligence (AI) and has spent decades becoming an expert in ASP.NET and DotNetNuke (DNN) development. You will find a variety of posts relating to those topics here on the website. For more information check out the about Chris Hammond page.

Find me on Twitter, GitHub and LinkedIn.