Object must implement IConvertible and the Application Data Block

I get this error from time to time and I must admit it is now a legacy bug I propogated through my first Code Smith templates to generate my businesss logic.  The problem is a simple one to overcome. 

I use the Application Data Blocks to wrap up all my interaction with the database, trust me you want to use them too, do not even question it.  I wont get into the details about them right now, but long and short is there are four or five heavily overloaded methods you can call  to quickly interact with your database to perform extremely common tasks, one is the retrieval of a DataReader or a SQLDataReader.  This is what it looks like when properly implemented:

        Dim dr As SqlDataReader = SqlHelper.ExecuteReader(ConnectionString,    CommandType.StoredProcedure, _
            'spMySproc', New SqlParameter('@IdentifierParam', IdentifierParamValue))

The problem I made when i first defined my Code Smith DAL template (that is Data Access Layer or Business Logic if you were wondering, it helps with the CRUD :)) was that I forgot to add the parameter to define what type of syntax I was calling.  In 99% of my cases it is a stored procedure.

So my call looked something like this:

        Dim dr As SqlDataReader = SqlHelper.ExecuteReader(ConnectionString,             'spMySproc', New SqlParameter('@IdentifierParam', IdentifierParamValue))

Which originally came from the fact that I was just passing the value for the parameter when it was only a one parameter stored procedure.  I found this ocassionally caused issues along the way, where I do not remember.  It is now one of those things where I know how to write the code to eliminate whatever problem I had some 12-18 months ago and that is the way I do it, which is the first way.

So back to the title and reason why I am writing this entry.  If you define your call the second way you will get the following error:

Object must implement IConvertible.

At the time my searches lead to a lot of dead ends in Google and the Microsoft site.  That may have changed, I can not be sure. I did just find a good entry from Google Here on the IConvertable Bug.  I remember it took me a while to find the offending code, because that line will not throw an error at design time because it resovles to a properly overloaded method.  I am not sure if the latest Patterns and Practices version of the Application Data Block work differently.  I am certain they do and that is why I have not upgraded.  I think they took away the shared methods, which sort of defeated the purpose in my mind of reducing code, but that is another entry.

Share This Article With Your Friends!

Googles Ads Facebook Pixel Bing Pixel LinkedIn Pixel