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