I'm using a OleDbCommand to truncate DBF-files. It works fine for most files, but if the file size is e.g. 400 MB I get an "Unspecified error". I've read somewhere that the size limit of a dbf-file is 2 GB, so I hope there is a way to work with files that large...
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
Below is the essential code for the operation:
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();
}
}
}
Any ideas on how to be able to truncate large dbf-files?