Is it possible to read to a Paradox 7.x .db file in a .Net app?

独自空忆成欢 提交于 2020-02-04 02:46:27

问题


I'm trying to read a Paradox 7.x .db file in a .Net 3.5 app and I'm not being successful on that.

First of all, when I'm registering the odbc, as a user or system dsn, the Microsoft Paradox ODBC Driver only display versions up to 5.x, so it looks like that it does not support Paradox version 7.x.

At connectionsstrings.com I've found the connection string that is supposed to work with 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

But when I try to test the connection using a Data Adapter I get the following exception:

"ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"

I have specified the ODBC as a user DSN and as a System DSN as well but kept receiving the same error.

Any clues on what should I do?

Thanks,

Pedro


回答1:


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

and

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:


Curious, why not use the OLEDB provider and then use the classes in the System.Data.OleDb namepsace?




回答3:


Here is a piece of code I've worked on in the past that will work. It is based on code from the now dead link in Przemysław Staniszewski's post elsewhere in this thread.

It opens a paradox database file using and OleDbConnection and OleDbDataAdapter, and loads the contents of that file into a DataTable variable.

This code works for me, and was used for a rushed oneshot job, and lacks error handling. It maybe of use to you.

        /// <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
                    }
                }
            }
        }


来源:https://stackoverflow.com/questions/557811/is-it-possible-to-read-to-a-paradox-7-x-db-file-in-a-net-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!