C# 中的悖论表

发布于 2024-07-08 12:26:33 字数 1101 浏览 11 评论 0原文

我正在尝试将 Paradox 5 表读入数据集或模拟数据结构,以便将其放入 SQL Server 2005 表中。 我已经搜索过谷歌和SO,但运气不佳。 我尝试过 ODBC:

public void ParadoxGet()
{
    string ConnectionString = @"Driver={Microsoft Paradox Driver (*.db )};DriverID=538;Fil=Paradox 5.X;DefaultDir=C:\Data\;Dbq=C:\Data\;CollatingSequence=ASCII;";

    DataSet ds = new DataSet();
    ds = GetDataSetFromAdapter(ds, ConnectionString, "SELECT * FROM Growth");
    foreach (String s in ds.Tables[0].Rows)
    {
        Console.WriteLine(s);
    }
}
public DataSet GetDataSetFromAdapter(DataSet dataSet, string connectionString, string queryString)
{
    using (OdbcConnection connection = new OdbcConnection(connectionString))
    {
        OdbcDataAdapter adapter = new OdbcDataAdapter(queryString, connection);
        connection.Open();
        adapter.Fill(dataSet);
        connection.Close();
    }
    return dataSet;
}

这只是返回错误

错误 [HY000] [Microsoft][ODBC Paradox 驱动程序] 外部表不是预期的格式。

我也厌倦了 OELDB (Jet 4.0),但得到相同的外部表不是预期的格式错误。

我在数据文件夹中有 DB 文件和 PX(增长表)...任何帮助将非常感激。

I'm trying to read a Paradox 5 table into a dataset or simular data structure with the view to putting it into an SQL server 2005 table. I've trawled google and SO but with not much luck. I've tried ODBC:

public void ParadoxGet()
{
    string ConnectionString = @"Driver={Microsoft Paradox Driver (*.db )};DriverID=538;Fil=Paradox 5.X;DefaultDir=C:\Data\;Dbq=C:\Data\;CollatingSequence=ASCII;";

    DataSet ds = new DataSet();
    ds = GetDataSetFromAdapter(ds, ConnectionString, "SELECT * FROM Growth");
    foreach (String s in ds.Tables[0].Rows)
    {
        Console.WriteLine(s);
    }
}
public DataSet GetDataSetFromAdapter(DataSet dataSet, string connectionString, string queryString)
{
    using (OdbcConnection connection = new OdbcConnection(connectionString))
    {
        OdbcDataAdapter adapter = new OdbcDataAdapter(queryString, connection);
        connection.Open();
        adapter.Fill(dataSet);
        connection.Close();
    }
    return dataSet;
}

This just return the error

ERROR [HY000] [Microsoft][ODBC Paradox Driver] External table is not in the expected format.

I've also tired OELDB (Jet 4.0) but get the same External table is not in the expected format error.

I have the DB file and the PX (of the Growth table) in the Data folder... Any help would be much appriciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

终止放荡 2024-07-15 12:26:33

我也有同样的错误。 当我在 Win2008 64 上启动我的 C# 项目时(以前的操作系统是 Win2003 32),它出现了。 我还发现它在控制台应用程序中运行良好,但在 winforms 中给出了不同的错误。 问题似乎来自于 64 位系统上工作的 32 ODBC 驱动程序的具体情况。
我的解决方案是:

// Program.cs
static void Main()
{
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        // it is important to open paradox connection before creating
        // the first form in the project
        if (!Data.OpenParadoxDatabase())
            return;
        Application.Run(new MainForm());
}

连接字符串是常见的:

string connStr = @"Driver={{Microsoft Paradox Driver (*.db )}};DriverID=538;
                   Fil=Paradox 7.X;DefaultDir=C:\\DB;Dbq=C:\\DB;
                   CollatingSequence=ASCII;";

打开连接后,您可以在创建第一个表单后在任何地方关闭它(如果您需要在大部分时间保持数据库关闭),例如:

private void MainForm_Load(object sender, EventArgs e)
{
    Data.CloseParadoxDatabase();
}

这样做之后,您可以每次打开和关闭连接您希望在执行应用程序期间不会出现任何异常。

I've had the same error. It appeared when I started my C# project on Win2008 64 (previos OS was Win2003 32). Also I found out that it worked fine in console apps and gave different errors in winforms. It seems that problem comes from the specifics of 32 ODBC driver working on 64-bit systems.
My solution was:

// Program.cs
static void Main()
{
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        // it is important to open paradox connection before creating
        // the first form in the project
        if (!Data.OpenParadoxDatabase())
            return;
        Application.Run(new MainForm());
}

The connectionstring is common:

string connStr = @"Driver={{Microsoft Paradox Driver (*.db )}};DriverID=538;
                   Fil=Paradox 7.X;DefaultDir=C:\\DB;Dbq=C:\\DB;
                   CollatingSequence=ASCII;";

After opening connection you may close it in any place after creating first Form (if you need to keep DB closed most of time), for example:

private void MainForm_Load(object sender, EventArgs e)
{
    Data.CloseParadoxDatabase();
}

After doing that you may open and close connection every time you want during execution of your application and you willn't get any exceptions.

醉态萌生 2024-07-15 12:26:33

也许这会对您有所帮助,

http://support.microsoft.com/support/kb/articles/Q237/9/94.ASP?LN=EN-US&SD=SO&FR=1
http://support.microsoft.com/support/kb/ articles/Q230/1/26.ASP

看来最新版本的 Microsoft Jet 数据库引擎

(JDE) 并不完全支持 Paradox,除非

还安装了 Borland 数据库引擎 (BDE)。

Maybe this will help you out,

http://support.microsoft.com/support/kb/articles/Q237/9/94.ASP?LN=EN-US&SD=SO&FR=1
http://support.microsoft.com/support/kb/articles/Q230/1/26.ASP

It appears that the latest version of the Microsoft Jet Database Engine

(JDE) does not fully support Paradox unless the Borland Database Engine

(BDE) is also installed.

青巷忧颜 2024-07-15 12:26:33

尝试使用“以管理员身份运行”权限运行所有应用程序,尤其是使用“以管理员身份运行”权限运行 VS.NET...我相信您的问题会得到解决

Try to Run all The Applications with the "Run As Administrator" privileges especially run the VS.NET with "Run As Administrator "... and I am sure your problem get solved

清晰传感 2024-07-15 12:26:33

这不是一个答案,而是一个问题:您尝试使用 C# 进行数据操作而不是使用 SQL Server 工具直接加载数据有什么特殊原因吗? DTS 或 SSIS 之类的东西似乎是完成这项工作的更好工具。

This isn't an answer, but more of a question: any particular reason you're trying to use C# to do the data manipulation as opposed to using SQL Server tools to load the data directly? Something like DTS or SSIS would seem like a better tool for the job.

千年*琉璃梦 2024-07-15 12:26:33

谢谢,我会尝试一下。 我想使用 C#,这样我就可以将它放在一些网页上,而无需额外将其放入 SQL Server 中。

Thanks, I'll give that a try. I wanted to use C# so I can put it on some web pages without the extra set of putting it in SQL server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文