【发布时间】:2021-06-25 20:45:43
【问题描述】:
我有一个旧版 Visual FoxPro 数据库,我需要从中获取数据。 我的数据库文件夹中有 DBC、DCT、DCX 和 FPT 文件。
我安装了 Visual FoxPro 提供程序和驱动程序并编写了一个简短的 C# 程序来访问数据。 我还确保程序在 32 位模式下运行,因为我知道 VFP 驱动程序是 32 位的。 但是我收到以下错误:
附加信息:连接错误:[Microsoft][ODBC Driver Manager] 未找到数据源名称且未指定默认驱动程序
我确保在连接字符串中指定了 Windows ODBC 32 位管理工具中显示的驱动程序名称(“Microsoft Visual FoxPro 驱动程序”),但它似乎没有帮助。
代码:
OleDbConnection yourConnectionHandler = new OleDbConnection(
@"Provider=VFPOLEDB.1;DRIVER=Microsoft Visual FoxPro Driver;Data Source=mydatabase.dbc;Mode=Read;Collating Sequence=machine");
// Open the connection, and if open successfully, you can try to query it
yourConnectionHandler.Open();
if (yourConnectionHandler.State == ConnectionState.Open)
{
string mySQL = "select * from tablename";
var command = yourConnectionHandler.CreateCommand();
command.CommandText = mySQL;
var res = command.ExecuteReader(); // throws the error
yourConnectionHandler.Close();
}
我已经被这个问题困扰了很长时间,并且已经尝试了我在网上可以找到的所有内容。 有什么想法吗?
【问题讨论】:
-
Possibly useful。也许尝试 .dbf 替代方案
-
...
odbc标签也不是oledb -
@MickyD - 现有的表文件是 DBC/DCT 格式,所以我没有 DBF 格式。
-
DBC是数据库容器,DBF在里面,应该和DBC在同一个文件夹中
-
您的连接字符串需要指向 DBC 中的特定 DBF。
标签: c# oledb visual-foxpro