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.

Community
  • 1
  • 1
Naresh
  • 658
  • 1
  • 7
  • 22
  • 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. – Naresh Jan 05 '14 at 09:37

1 Answers1

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!)

meda
  • 45,103
  • 14
  • 92
  • 122
Rory
  • 40,559
  • 52
  • 175
  • 261
  • 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. – Naresh Mar 16 '14 at 12:24