Error when adding parameters to ADODB command in a .NET assembly

I have a .NET assembly that is being consumed by a classic ASP page. I've created a method that returns a ADODB recordset. In my ADODB command object I'm supplying parameters using the following format to a adCmdStoredProc CommandType property...

With ADODBCmd .ActiveConnection = ADODBConn .Prepared = True .CommandType = CommandTypeEnum.adCmdStoredProc .NamedParameters = True .CommandText = Sql_GetMyBook .Parameters.Append(.CreateParameter("@book", DataTypeEnum.adChar, ParameterDirectionEnum.adParamInput, 50, MyBook)) End With

I get a casting error ...

System.Exception was unhandled Message=System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to class type 'ADODB.InternalParameter'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.

at line:

.Parameters.Append(.CreateParameter("@book", DataTypeEnum.adChar, ParameterDirectionEnum.adParamInput, 50, MyBook))

Any ideas?

Stored Proc:

ALTER PROCEDURE [dbo].[GetMybook] -- Add the parameters for the stored procedure here @book char(50) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here SELECT BookTitle, Author, PulishedDate FROM Library WHERE BookTitle=@book


There is a difference (unintended or not) between the return value of the ".CreateParameter" method in Microsoft ActiveX Data objects Library

2.7 - Returns "ADODB.InternalParameter" (which is expected by the ADODB.Command object)

2.8 - Returns "System.__ComObject" (which the ADODB.Command can't handle or doesn't know what to do with)

For my purposes I had to change my reference from 2.8 to 2.7 library in order to append parameters created to the command object.

Thanks to Chris Behrens for helping me narrow down my search for a solution.


I think it has to do with the value of "MyBook". We should expect it to be a single character, from the data type, but the error message seems to be indicating that it's a full-blown COM object. Maybe it should be something like "MyBook.Id"?


  • .NET Core + Openiddict InvalidCastException
  • Change text for multiple buttons in one operation
  • What are the first steps for tracking down a exception triggered in the mono asp.net libraries?
  • Problem with Application.DoEvents() while waiting for WebBrowser to finish loading
  • Must Office.initialize always be set?
  • Referencing native C++ DLL in C++ windows app only works when added as reference
  • How can I automate the t4 code generation for SubSonic
  • Cast uint -> double invalid?
  • How can I pipe to a bash alias from an npm script?
  • When I try to upload and save an image file using Struts in eclipse it shows the file name as null
  • Jooq casting String to BigDecimal
  • RavenDB indexing errors
  • Multiple Left Join LINQ-to-entities
  • Suqueries in select clause with JPA
  • Default parameter as generic type
  • URLConnection doesn't work since API 10 and higher?
  • Unable to install Git-core+svn by MacPorts
  • Unable to decode certificate at client new X509Certificate2()
  • Retrieve list of sent friend requests from friend_request FQL table
  • The plugin 'org.apache.maven.plugins:maven-jboss-as-plugin' does not exist or no valid ver
  • NHibernate Validation Localization with S#arp Architecture
  • How can I send an e-mail from a vbs script
  • Launch Runnable Jar from Web Start
  • Accessing IRQ description array within a module and displaying action names
  • How to convert from System.Drawing.Color to Excel.ColorFormat in C#? Change comment color
  • javascript inside java/jsp code
  • Validaiting emails with Net.Mail MailAddress
  • Timeout for blocking function call, i.e., how to stop waiting for user input after X seconds?
  • Is there a mandatory requirement to switch app.yaml?
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Android Studio and gradle
  • Proper folder structure for lots of source files
  • Hits per day in Google Big Query
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Getting Messege Twice Using IMvxMessenger
  • How does Linux kernel interrupt the application?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Linking SubReports Without LinkChild/LinkMaster
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • How can i traverse a binary tree from right to left in java?