Import DBF files into Sql Server

2019-07-21 13:22发布

I need a little help figuring this out because I'm new to stored procedures. I am trying to import a .DBF table into Sql Server 2008 using this store procedure.

CREATE PROCEDURE spImportDB
-- Add the parameters for the stored procedure here

AS
BEGIN

-- Insert statements for procedure here

 SELECT * into Products
 FROM OPENROWSET('vfpoledb','C:\Users\Admin\Doc\Data\DBF',
 'SELECT * FROM MyTable')

END
GO

I receive this error. The OLE DB provider "vfpoledb" has not been registered.This isn't true, I've installed it and it works fine in my other application.

I've also tried running it this way with this provider but I receive this error message Cannot initialize the data source object of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)".

CREATE PROCEDURE spImportDB
-- Add the parameters for the stored procedure here

AS
BEGIN

-- Insert statements for procedure here

 SELECT * into Products
 FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','C:\Users\Admin\Doc\Data\DBF',
 'SELECT * FROM MyTable')

END
GO

What's the easiest way to create this stored procedure? I want it to be a stored procedure not a wizard or program so please don't give me any programs.

3条回答
Lonely孤独者°
2楼-- · 2019-07-21 14:02

For anyone else looking for an answer to this, the cause of this error is installing the Foxpro driver for "Just Me" instead of "Everyone".

Run the installer for "Everyone" to avoid this error.

查看更多
疯言疯语
3楼-- · 2019-07-21 14:03

You can try

SELECT * into SomeTable
FROM OPENROWSET('MSDASQL', 'Driver=Microsoft Visual FoxPro Driver;
SourceDB=\\SomeServer\SomePath\;
SourceType=DBF',
'SELECT * FROM SomeDBF')

from this previous question

查看更多
我只想做你的唯一
4楼-- · 2019-07-21 14:14

I'm not sure about the "friendly-name" for VFPOLEDB, but the second SP should work (i.e. using 'Microsoft.Jet.OLEDB.4.0') as long as you're pointing to a specific DBF file by name. It looks like you're pointing to a directory, not the actual file.

Further information may be found in: http://msdn.microsoft.com/en-us/library/ms190312.aspx

查看更多
登录 后发表回答