IBM Netezza C#驱动报KeyNotFoundException异常求助
排查Netezza驱动无代码变更下的KeyNotFoundException异常
异常详情
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. at System.ThrowHelper.ThrowKeyNotFoundException() at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at NZdotNETTypes.NZdotNETTypesHelper.LoadTypesMappings(NZdotNETConnector conn, NZdotNETBackendTypeMapping TypeMappings, IEnumerable`1 TypeInfoList) at NZdotNETTypes.NZdotNETTypesHelper.CreateAndLoadInitialTypesMapping(NZdotNETConnector conn) at NZdotNET.NZdotNETConnector.Open() at NZdotNET.NZdotNETConnectorPool.GetPooledConnector(NZdotNETConnection Connection) at NZdotNET.NZdotNETConnectorPool.RequestPooledConnector(NZdotNETConnection Connection) at NZdotNET.NZdotNETConnectorPool.RequestConnector(NZdotNETConnection Connection) at NZdotNET.NZdotNETConnection.Open() at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
关联代码
try { var factory = DbProviderFactories.GetFactory("NZdotNET"); using (var connection = factory.CreateConnection()) { if (connection == null) return; connection.ConnectionString = ConfigHelper.IdpConnectionString; using (var command = factory.CreateCommand()) { if (command == null) return; command.CommandType = CommandType.Text; command.CommandText = idpQuery; command.CommandTimeout = ConfigHelper.ImportTaskCommandTimeout; command.Connection = connection; using (var adapter = factory.CreateDataAdapter()) { if (adapter == null) return; adapter.SelectCommand = command; var dataTable = new DataTable(); adapter.Fill(dataTable); Import(dataTable); } } } }
排查方向
- 检查Netezza服务器端类型变更:异常发生在类型映射加载阶段,大概率是数据库侧新增了自定义数据类型,或原有系统类型被修改/移除,导致驱动无法找到对应的.NET类型映射。可查询数据库
_v_datatype视图,对比近期类型变化记录。 - 驱动版本兼容性问题:服务器端Netezza版本可能已更新,当前NZdotNET驱动版本不兼容新版本的服务器类型定义。尝试回滚驱动至之前稳定版本,或升级到匹配服务器版本的驱动。
- 连接器池缓存污染:连接器池中的旧连接缓存了过时的类型映射,导致新连接初始化时冲突。可尝试重启应用服务清空连接池,或在连接字符串中添加
Pooling=false临时禁用连接池测试。 - 系统环境变更:本地和服务器同时出现问题,可能是.NET运行时版本更新、系统补丁安装等环境变更影响了驱动的类型映射逻辑。检查本地和服务器的.NET框架/运行时版本,对比之前的环境配置。
- 最简连接字符串测试:即使拆分了键值对,某些隐性配置(如加密、特定版本标识)可能未正确设置。尝试使用仅包含服务器、数据库、用户名、密码的最简连接字符串进行测试。
内容的提问来源于stack exchange,提问作者Christian Phillips
相关产品推荐
相关产品推荐

