Get the App
SLTechnology News&Howtos  ›  Database  › 

Using PowerShell to operate Foxpro on a 64-bit system

Shulou Source: shulou.com Published: 2022-06-01 21:52:17 10月04日 Update

Procedure:

1. Download the OLEDB driver VFPOLEDBSetup.msi for Foxpro, install it, and choose to allow everyone to run.

two。 Register the OLEDB driver:

Regsvr32 / s "C:\ Program Files (x86)\ Common Files\ system\ oledb\ vfpoledb.dll"

3. Run x86 version of PowerShell:

$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]

List of pits:

Description from Foxpro driver:

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

ODBC drivers are divided into 32-bit and 64-bit. Only applications compiled to 32-bit can call 32-bit ODBC drivers.

"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. "

After Visual Foxpro is installed, the 32-bit ODBC driver VFPODBC.DLL is installed.

Choose to allow everyone to run when installing the OLEDB driver.

To register for vfpoledb.dll.

The Provider driven by OLEDB is vfpoledb.1.

To run under 32-bit PowerShell to invoke the driver.

Postscript:

Attempt to operate ODBC driver under 32-bit PowerShell failed.

$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 = $Query$Reader = $Command.ExecuteReader () $Counter = $Reader.FieldCountwhile ($Reader.Read ()) {$SQLObject = @ {} for ($I = 0; $I-lt $Counter) ) {$SQLObject.Add ($Reader.GetName ($I), $Reader.GetValue ($I));} $SQLObject} $Connection.Close () $Reader.Close ()

But running on a 32-bit operating system is normal. If other languages are developed, they should be compiled to a 32-bit version.

Tags: Driver run translate select system operating system only postscript application step version program language attempt application development Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Linux Shulou Tech Info Redmi MariaDB