在64位系统上使用PowerShell操作Foxpro
admin
2023-02-08 12:20:04
0

操作步骤:


1. 下载Foxpro的OLEDB驱动VFPOLEDBSetup.msi,安装,选择允许everyone运行。


2. 注册OLEDB驱动:

regsvr32 /s "C:\Program Files (x86)\Common Files\system\ole db\vfpoledb.dll"


3. 运行x86版PowerShell:

在64位系统上使用PowerShell操作Foxpro


$ConnString = "Provider=vfpoledb.1;Data Source=c:\accounts.dbf;Collating Sequence=machine;"
$Conn = new-object System.Data.OleDb.OleDbConnection($connString)
$conn.open()
$cmd = new-object System.Data.OleDb.OleDbCommand("select * from accounts", $Conn)
$DataAdapter = new-object System.Data.OleDb.OleDbDataAdapter($cmd)
$dataset = new-object System.Data.Dataset
$DataAdapter.fill($dataset)
$dataset.Tables[0]


在64位系统上使用PowerShell操作Foxpro


坑列表:


  1. 从Foxpro驱动描述:

    “The VFPODBC driver is no longer supported. We strongly recommend using the Visual FoxPro OLE DB provider as a replacement.”

  2. ODBC驱动分为32位和64位。只有编译为32位的应用程序才能调用32位的ODBC驱动。

    "A 32-bit app uses a 32-bit ODBC driver even when installed on 64-bit Windows. But on 64-bit systems, there are two views on ODBC - one is 64-bit, the other is 32-bit. It looks like you opened the default 64-bit view which doesn't show the 32-bit ODBC drivers. To solve this go to c:\windows, there you see a folder named SysWOW64. Here you find odbcad32.exe. After launching the exe you can add a new system dsn or user dsn for the required ODBC driver. Configure it as usual. All other ODBC drivers you have been missing will appear there."

    在64位系统上使用PowerShell操作Foxpro

  3. 安装了Visual Foxpro后,会安装32位ODBC驱动VFPODBC.DLL。

    在64位系统上使用PowerShell操作Foxpro

  4. 安装OLEDB驱动时要选择允许everyone运行。

  5. 要注册vfpoledb.dll。

  6. OLEDB驱动的Provider为vfpoledb.1。

  7. 要在32位PowerShell下运行来调用该驱动。


后记:


尝试在32位PowerShell下操作ODBC驱动,失败。

$ConnString ="Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB='c:\foxpro\';Exclusive=No;Collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;"
$Connection = New-Object System.Data.Odbc.OdbcConnection
$Connection.ConnectionString = $ConnString
$Connection.Open()
$Command = New-Object System.Data.Odbc.OdbcCommand
$Command.Connection = $Connection
$Command.CommandText = $Query
$Reader = $Command.ExecuteReader()
$Counter = $Reader.FieldCount
while ($Reader.Read()) {
    $SQLObject = @{}
    for ($i = 0; $i -lt $Counter; $i++) {
        $SQLObject.Add(
            $Reader.GetName($i),
            $Reader.GetValue($i));
    }
    $SQLObject
}
$Connection.Close()
$Reader.Close()

在64位系统上使用PowerShell操作Foxpro

但在32位操作系统上运行是正常。若其他语言在开发时应编译为32位版本。


相关内容

热门资讯

专访王虹:从北大数学系曾经的“... “获奖挺好的。”王虹说话慢慢的,随后话锋一转,带着自嘲式的笑意,“但是题该做不出来,还是做不出来。”...
意大利纵火犯用猫助燃,当地动保... 【环球时报记者 林泽宇 环球时报特约记者 文简】据《意大利晨报》23日报道,近日意大利南部野火肆虐。...
第8国?美媒爆料:美政府正研究... 【环球时报综合报道】据美国《华盛顿邮报》23日报道,多名美国官员透露,美政府正研究是否在西非国家马里...
男子在采血站采血后口吐白沫、神... 7月23日,山西广播电视台《慧帮忙》栏目报道“我弟弟在霍州康宝生物科技采血站采血后口吐白沫、神志不清...
“安全先生”,不安全了 当地时间7月17日凌晨,以色列第25届议会以62票赞成、0票反对通过一项有关政党经费法的相关修正案,...
“AI科学家”,实验效率直接“... □ 本报记者 洪叶 徐春晖 窗明几净的空间里没有科研人员,取而代之的是一排充满科技感的自动化岛台,背...
云南一女子电脑屏内现“蚂蚁窝”... 大家平时清洁电脑显示屏吗? 你见过显示屏里进蚂蚁吗? 据媒体报道,云南临沧一名女子近期发现,自己使...
便携脑电采集新品发布,脑电信号... 一根发带将一个比硬币略大的采集设备贴在额头,就能实现脑电信号采集,脑机接口创新企业神舞科技7月22日...
工业和信息化部:依托标准牵引智... 日前,在北京举办的《人工智能 智能体互联》系列标准应用推进专题会上,工业和信息化部科技司副司长甘小斌...