间歇性错误-.Net Framework数据提供程序需要Microsoft数据访问组件

时间:2018-10-26 13:47:50

标签: asp.net iis

我们正在将全框架(.Net 4.5.1)网站部署到IIS服务器。

我们间歇性地遇到此错误:

  

应用程序错误:System.AggregateException:发生一个或多个错误。 ---> System.Exception:SelectAllTOCBasedOnRole无法执行。 ---> System.InvalidOperationException:.Net Framework数据提供程序需要Microsoft数据访问组件(MDAC)。请安装Microsoft数据访问组件(MDAC)2.6版或更高版本。 ---> System.Runtime.InteropServices.COMException:检索具有CLSID {2206CDB2-19C1-11D1-89E0-00C04FD7A829}的组件的COM类工厂由于以下错误而失败:800703fa尝试对已经存在的注册表项进行非法操作标记为删除。 (来自HRESULT的异常:0x800703FA)。

该站点正在访问DB2数据库。

服务器上安装了MDAC 2.8.1。在运行该站点的所有计算机上还安装了用于DB2 5.0版的Microsoft OLE DB提供程序。

如果重新启动应用程序池,则将在一段时间内解决该错误。然后,该错误将随机地再次出现,并持续到再次重新启动应用程序池为止。

同一Web应用程序位于另一台服务器上,尽管我看不到服务器及其安装的组件之间的任何实际差异,但似乎没有出现此问题。

下面是连接到DB2实例的代码段。也许这有点时髦。?

public async Task<IList<WebTOC>> GetAllTOCAsync(string countryCode, string languageCode, string employeeNumber, string tocIdentifier)
{
    IList<WebTOC> results = new List<WebTOC>();
    using (OleDbConnection connection = new OleDbConnection(_connectionString))
    {
        // Parameter order matters with OLEDBCommands
        try
        {
            using (OleDbCommand command = connection.CreateCommand())
            using (OleDbDataAdapter adapter = new OleDbDataAdapter(command))
            {
                command.CommandText = _selectAllTOCCommand;
                command.Parameters.AddWithValue("?", $"{tocIdentifier}%");
                command.Parameters.AddWithValue("?", countryCode);
                command.Parameters.AddWithValue("?", languageCode);
                command.Parameters.AddWithValue("?", employeeNumber);
                command.Parameters.AddWithValue("?", DateTime.Now.ToString("yyyy-MM-dd"));

                LogHelper.Log($"Prepare DB2 Command selectAllToCCommand", level: LogHelper.LogLevel.Debug);

                //// FAILS HERE WHEN ATTEMPING TO OPEN THE CONNECTION ////                      
                connection.Open();

                try
                {                       

                    using (INullSafeDataReader dataReader = new NullSafeDataReader(await command.ExecuteReaderAsync()))
                        try
                        {
                            results = dataReader.MapToList<WebTOC>(true);
                        }
                        finally
                        {
                            dataReader.Close();
                        }
                }
                catch (Exception exDR)
                {           
                    LogHelper.Log($"Failed to read data from DB2", level: LogHelper.LogLevel.Error);
                    throw new Exception("Failed to read data from database.", exDR);
                }
            }
        }
        catch (Exception ex)
        {
            /// HITS THIS CATCH ///
            LogHelper.Log($"SelectAllTOCBasedOnRole failed to execute", level: LogHelper.LogLevel.Error);
            throw new Exception("SelectAllTOCBasedOnRole failed to execute.", ex);
        }
        finally
        {
            if (connection.State != System.Data.ConnectionState.Closed)
                connection.Close();
            connection.Dispose();
        }
    }
    return results;
}

0 个答案:

没有答案