0

This question is related to, Error when adding parameters to ADODB command in a .NET assembly

I came across this post and was able to resolve my issue from its answer. However, my issue was little different.

cmd.CommandType = CommandTypeEnum.adCmdStoredProc;
cmd.CommandText = "GetUserPreferencesBasedOnScreen";
cmd.let_ActiveConnection(conn);
conn.CursorLocation = CursorLocationEnum.adUseClient;
object dummy = Type.Missing;
Parameters paramets = cmd.Parameters;
int paramCount = paramets.Count;
for (int iParams = paramCount - 1; iParams >= 0; iParams--)
{
    paramets.Delete(iParams);
}
Parameter pMtr = cmd.CreateParameter("Screen_Name", DataTypeEnum.adVarChar, ParameterDirectionEnum.adParamInput, 50);
paramets.Append(pMtr);

The last line throws the following error

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.

When I am using .Net framework 3.5 this code was not giving error. Now, as soon as I changed the framework to 4.0 I started getting this error.

Please let me know if there are any alternatives to use 2.8 otherwise I will have to test everthing again to make sure nothing else broke with adoption of 2.7.

1
  • MSDN says, in 2.8 the following was enhanced. Recordset.ActiveCommand returns an error when invoked from an HTML/ASP page. This prevents the Command object from being misused. Commented Jan 5, 2014 at 9:37

1 Answer 1

0

From what I can tell you're using ADODB but the easiest solution is to use the .NET standard stuff in System.Data, like SqlCommand. This is consistent across .NET 2.0, 3.5, 4.0. (And ADODB is old!)

Sign up to request clarification or add additional context in comments.

1 Comment

The one that you answered is an altenative. But not an answer. However, I am removing downvote, as it is not incorrect to use alternative. But I have a requirement to use old one here, until I am able to change it to .net completely.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.