【发布时间】:2013-05-10 20:58:16
【问题描述】:
我正在尝试从测试 vb.net 表单连接到 foxpro 表 (.dbf)。 我收到 OleDbException 消息“无法打开文件 c:\emp\emptbl.dbf”
已尝试使用以下两个连接字符串:
Provider=VFPOLEDB.1;数据源=C:\emp\emptbl.dbf
来自 MSDN 文章 here
Provider=vfpoledb;Data Source=C:\emp\emptbl.dbf;Collating Sequence=machine;
后者似乎是连接到单个表时使用的类型,但无论使用哪种类型都会引发相同的异常。
我可以在visual foxpro 6.0 中打开并执行相同的查询。 这是我的代码:
Dim tbl As DataTable = New DataTable()
Using con = New OleDbConnection(conString)
cmd = New OleDbCommand() With {.Connection = con, .CommandType = CommandType.Text}
Dim sSQL As String = "SELECT * FROM(EMPTBL)"
cmd.CommandText = sSQL
Dim adp As OleDbDataAdapter = New OleDbDataAdapter(cmd)
Dim ds As DataSet = New DataSet()
con.Open()
adp.Fill(ds)
con.Close()
If (ds.Tables.Count > 0) Then
tbl = ds.Tables(0)
End If
End Using
Return tbl
【问题讨论】:
-
可能不相关,但您是否为 AnyCPU 编译并在 x64 操作系统上运行?
-
哈哈!更改为“任何 cpu”似乎做得不错。抛出异常,但现在显示消息“'vfpoledb' 提供程序未在本地计算机上注册”。所以,这至少是现在要研究的事情。谢谢!
-
不,这意味着相反。您正确使用了 x86 平台,因此您生成的 32 位代码与 32 位驱动程序一起使用,而不管底层操作系统的位数如何。如果您切换到 AnyCPU,您会在 64 位系统上生成 64 位代码,并且此代码无法与 32 位驱动程序 (VFPOLEDB) 一起使用
-
啊,疯了!感谢您为我解决这个问题。