Trying to Import FoxPro DBF File to SQL Server

2019-01-26 00:56发布

问题:

As the title says, I'm trying to import a FoxPro dbf file into sql server using openrowset. At first I tried to export the DBF to an xls file and import using the Import/Export wizard. This works pretty well normally, but there is one field that sometimes holds a really long string, and this string is being truncated at 4096 characters during the export from the dbf to xls.

I found an old post with instructions on how to do this using openrowset.

When I try the first answer:

select *
from openrowset('MSDASQL', 'Driver=Microsoft Visual FoxPro Driver;
SourceDB=\\path\;
SourceType=DBF',
'select * from TABLE.DBF')

I get the error:

OLE DB provider "MSDASQL" for linked server "(null)" returned message "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified".
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "(null)".

When I try the second answer:

select *
from openrowset('VFPOLEDB',
'\\Path\';'';'',
'select * from TABLE.DBF')

I get the error:

Msg 7403, Level 16, State 1, Line 1
The OLE DB provider "VFPOLEDB" has not been registered.

I tried to register the OLE*.dll files manually with regsvr32, but only some of them worked. On ole32, oleacc, oleaut32, and oleprn I got a success message. On oleacchooks, oleaccrc, oledlg, and oleres I got this error:

The module "oleacchooks" was loaded but the
entry-point DllRegisterServer was not found.

Make sure that "oleacchooks" is a valid DLL or OCX file
and then try again

After some investigation I tried to install the componet, but when I tried to install the msi file for FoxPro (found here), I got this error:

An error occurred while processing the last operation.
Error code 80110408 - Error occurred reading the application file

The event log may contain additional troubleshooting information.

So, I'm officially lost here. Does anybody have suggestions on how to get openrowset to work, or some other way of importing the dbf file?

回答1:

Pat, you can use DBF Commander Pro for this task.

Download it, install, then click File -> Export to DBMS. In the window appears click Build button in order to build the connection string: select MS OLEDB Provider for SQL Server, then choose your server from the list, provide login and password, select a database, click OK:

In the Export to DBMS window select the destination table you want to import source DBF file to, then click Export.

More info on import and export DBF to a database you can find here.

P.S. The app has fully functional free trial 20-days period.



回答2:

Try using VFPOLEDB.1 as the provider. You may be experiencing driver version issues.