Pergunta

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.

Foi útil?

Solução

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top