【问题标题】:Is it possible to read to a Paradox 7.x .db file in a .Net app?是否可以在 .Net 应用程序中读取 Paradox 7.x .db 文件?
【发布时间】:2009-02-17 17:17:53
【问题描述】:

我正在尝试在 .Net 3.5 应用程序中读取 Paradox 7.x .db 文件,但没有成功。

首先,当我以用户或系统 dsn 身份注册 odbc 时,Microsoft Paradox ODBC 驱动程序仅显示最高 5.x 的版本,因此看起来它不支持 Paradox 7.x 版本.

connectionsstrings.com,我找到了应该适用于 Paradox 7.x 的连接字符串:

Provider=MSDASQL;Persist Security Info=False;Mode=Read;
Extended Properties='DSN=Paradox;DBQ=C:\mydbfolder;
DefaultDir=C:\mydbfolder;DriverId=538;FIL=Paradox 7.X;MaxBufferSize=2048;
PageTimeout=600;';Initial Catalog=C:\mydbfolder

但是当我尝试使用数据适配器测试连接时,出现以下异常:

“错误 [IM002] [Microsoft][ODBC Driver Manager] 未找到数据源名称且未指定默认驱动程序”

我已将 ODBC 指定为用户 DSN 和系统 DSN,但一直收到相同的错误。

关于我应该做什么的任何线索?

谢谢,

佩德罗

【问题讨论】:

    标签: c# odbc paradox


    【解决方案1】:

    http://www.progware.org/Blog/post/Connecting-to-a-PARADOX-DB-with-C-%28Vista-XP%29.aspx

    ConnectionString.Append(@"Provider=Microsoft.Jet.OLEDB.4.0;");
    ConnectionString.Append(@"Extended Properties=Paradox 7.x;");
    ConnectionString.Append(@"Data Source=Z:\Dane;");
    //ConnectionString.Append(@"Mode=ReadWrite;");
    ConnectionString.Append(@"Mode=1;");
    

    【讨论】:

    • 那个链接现在失效了。
    【解决方案2】:

    很好奇,为什么不使用 OLEDB 提供程序,然后使用 System.Data.OleDb 命名空间中的类?

    【讨论】:

    • 当我尝试 OLEDB 提供程序时,我得到一个“外部表不是预期的格式”。错误。我已经浏览过,看起来我还需要安装 Borland 的 BDE。即使我尝试使用 Microsoft Excel 打开表格,也会出现此错误。
    【解决方案3】:

    这是我过去编写的一段代码,它可以工作。它基于 Przemysław Staniszewski 在此线程其他地方的帖子中现已失效的链接中的代码。

    它使用 OleDbConnection 和 OleDbDataAdapter 打开一个悖论数据库文件,并将该文件的内容加载到一个 DataTable 变量中。

    此代码适用于我,用于匆忙的一次性工作,缺乏错误处理。它可能对你有用。

            /// <summary>
            /// ConnectToTable
            /// </summary>
            /// <param name="pFullPath">Full path to .DB file</param>
            /// <param name="pTableName">Name of table to load</param>
            public static void ConnectToTable(string pFullPath, string pTableName)
            {
    
                OleDbConnection _ParadoxConnection = new OleDbConnection();
    
                StringBuilder ConnectionString = new StringBuilder("");
                ConnectionString.Append(@"Provider=Microsoft.Jet.OLEDB.4.0;");
                ConnectionString.Append(@"Extended Properties=Paradox 7.x;");
                ConnectionString.Append(string.Format(@"Data Source={0}", pFullPath));
    
                _ParadoxConnection.ConnectionString = ConnectionString.ToString();
    
                _ParadoxConnection.Open();
    
                using (OleDbDataAdapter da = new OleDbDataAdapter(
                    string.Format("SELECT * FROM {0};", pTableName)
                    , _ParadoxConnection))
                {
                    DataTable tab = new DataTable
                    {
                        TableName = pTableName
                    };
                    da.Fill(tab);
    
                    //tab now contains a data
    
                    //Get the column name
                    foreach(DataColumn col in tab.Columns)
                    {
                        Console.WriteLine(col.ColumnName);
                    }
    
                    //do the rows
                    foreach (DataRow row in tab.Rows)
                    {
                        foreach(var item in row.ItemArray)
                        {
                            //write each row value
                        }
                    }
                }
            }
    

    【讨论】:

      猜你喜欢
      • 2015-01-16
      • 2018-09-12
      • 1970-01-01
      • 2010-11-12
      • 2015-06-02
      • 1970-01-01
      • 2020-07-04
      • 2012-02-22
      • 2011-11-16
      相关资源
      最近更新 更多