繁体   English   中英

在C#中使用OLEDB创建DBF进行dBASE IV崩溃

[英]In C# Creating DBF Using OLEDB for dBASE IV Crashes

我的代码在下面,每当​​我为此运行单元测试(或实际应用程序)时,它都会停止执行测试(尽管将下面的代码包装在try catch中,并将catch中的断点包裹起来)。

生成的文件具有“严重性”和“消息”字段,但没有其他字段。 我已经间歇性地看到此运行,但是,我似乎无法使其再次运行。

//DBF Create Table
var currentLogTime = DateTime.UtcNow.ToString("yyMMddHH");
protected const string FORMAT_CONNECTION_STRING = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=dBASE IV";
var connectionString = String.Format(FORMAT_CONNECTION_STRING, DBFPath);
Connection = new OleDbConnection(connectionString);
Connection.Open();
using (var command = Connection.CreateCommand())
{
    command.CommandText =
        String.Format(
            "CREATE TABLE {0} ([SEVERITY] NUMERIC, [MESSAGE] MEMO, [STACKTRACE] MEMO, [OCCURRED] CHAR(50))",
            currentLogTime);
    try
    {
        command.ExecuteNonQuery();
    }
    catch(Exception ex)
    {

    }
}

可能是因为您仅在日期数字上创建了一个表。 您无法创建看起来像16021715的表,例如“ yyMMddHH”。请尝试使用日志前缀创建表,例如...

String.Format("CREATE TABLE Log{0} (etc.....", parm);

因此表名实际上将变为“ Log16021715”,并且是有效的表名。

VisualFoxPro创建表

var currentLogTime = DateTime.UtcNow.ToString("yyMMddHH");
protected const string FORMAT_CONNECTION_STRING = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=dBASE IV";

var connectionString = String.Format(FORMAT_CONNECTION_STRING, DBFPath);
Source="yourFilePathToSourceFile";Extended Properties=dBase IV";
using (OleDbConnection connection = new OleDbConnection(connectionString))
using (OleDbCommand command = connection.CreateCommand())
{
    connection.Open();
    command.CommandText = String.Format("CREATE TABLE {0} (SEVERITY I, MESSAGE M, STACKTRACE M, OCCURRED C(50) NOCPTRANS"
    command.ExecuteNonQuery();
}

似乎在为MEMO字段创建DBT文件时,OleDB驱动程序遇到了最大路径长度问题。 缩短路径可以解决此问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM