以前正常的代码出现异常

Exception appeared on code that previously was ok

我的项目突然默认了一个功能问题,到目前为止一直运行良好。这是一个在我的 sql 服务器上调用 存储过程 的函数:

ADODB.Command MyCommand = new ADODB.Command();
ADODB.Parameter TableNameParameter = MyCommand.CreateParameter("@TableName", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 50, TableName);
MyCommand.Parameters.Append(TableNameParameter);  

当它试图附加第一个参数时,它在上面的行中抛出异常:

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.

我从某人那里找到了类似的 post,他通过将引用从 2.8 更改为 2.7 来修复此问题,但是我是 C# 的新手,不知道如何执行此操作。有人可以帮忙,或建议其他修复方法。

如果修复真的只是将参考文件回滚到以前的版本,您可以通过单击解决方案资源管理器中的参考来在您的解决方案中执行此操作。

从那里你 select ADODB 的参考并右键单击并删除 2.8 版本。

然后右键单击引用并select添加引用。

然后您可以在 window 上的 COM 列表中浏览或 select 文件。 这次确保 select 2.7 版本。