我有一个 C# 程序,它从 csv 文件导入数据并将数据放入 SQLServerCE 数据库表(在本地 C 驱动器上)。该程序适用于许多用户的机器,但少数用户不断收到错误:
System.Data.OleDb.OleDbException (0x80004005): Invalid setting in Excel key of the Engines section of the Windows Registry. at
System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) at
System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) at
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) at
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at
System.Data.OleDb.OleDbConnection.Open()
这是 C# 代码:
string connStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathToFile + ";Extended Properties=Text;";
string sqlCmd = "SELECT * FROM [" + filenameOnly + "]";
using (OleDbConnection conn = new OleDbConnection(connStr))
{
OleDbCommand cmd = new OleDbCommand(sqlCmd, conn);
using (OleDbDataAdapter dadapt = new OleDbDataAdapter(cmd))
{
conn.Open();
dadapt.TableMappings.Add("Table", dataSourceAlias);
dadapt.Fill(ds);
conn.Close();
}
}
我已经尝试了几件事:
- 已验证 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4\Engines\Text 的格式键有“CSVDelimited”
- 验证用户拥有最新版本的 Jet4.0(Msjet40.dll 版本 4.0.9511.0 Windows XP SP3 和安全公告 MS08-028)
- 已验证 HKEY_LOCAL_MACHINE\Software\Microsoft\Jet\4.0\Engines\Text 的扩展名不超过 4 个字符
但是,在这一切之后,用户仍然无法导入 csv 文件数据,因为“Windows 注册表引擎部分的 Excel 键中的设置无效”
有什么建议么?