我正在使用 OleDbCommand 截断 DBF 文件。它适用于大多数文件,但如果文件大小为 400 MB,我会收到“未指定错误”。我在某处读到 dbf 文件的大小限制为 2 GB,所以我希望有一种方法可以处理这么大的文件......
System.Data.OleDb.OleDbException: Unspecified error
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
at OleDbTruncateTest.Program.Main(String[] args) in C:\Users\henjoh\Visual Studio 2008\Projects\OleDbTruncateTest\OleDbTruncateTest\Program.cs:line 22
以下是操作的基本代码:
using System;
using System.Data.OleDb;
using System.IO;
namespace OleDbTruncateTest
{
class Program
{
static void Main(string[] args)
{
try
{
string file = @"C:\Temp\largefile.DBF";
string pathName = Path.GetDirectoryName(file);
string fileName = Path.GetFileName(file);
using (OleDbConnection connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + pathName + "; Extended Properties=dBase III"))
{
connection.Open();
using (OleDbCommand comm = new OleDbCommand("DELETE FROM " + fileName, connection))
{
comm.ExecuteNonQuery();
}
}
Console.WriteLine("Done");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.WriteLine("ENTER to exit...");
Console.ReadLine();
}
}
}
关于如何截断大型 dbf 文件的任何想法?