问题
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