如何使用SQL脚本将数据从DBF导入到SQL?

发布于 2024-08-22 05:45:22 字数 806 浏览 3 评论 0原文

我正在尝试使用以下命令将数据从 DBF 文件导入到 SQL 表 -

select *
from openrowset('MSDASQL', 
'Driver={Microsoft dBase Driver (*.dbf)};DBQ=E:\data\;',
'select * from E:\data\a.dbf')

但它失败说

    OLE DB provider "MSDASQL" for linked server "(null)" returned message "[Microsoft][ODBC dBase Driver]General Warning Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x120 Thread 0x3084 DBC 0x303dfbc Xbase'.".    
OLE DB provider "MSDASQL" for linked server "(null)" returned message "[Microsoft][ODBC dBase Driver] Disk or network error.".    
Msg 7303, Level 16, State 1, Line 1    
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "(null)".

任何线索为什么会出现错误?对于第二个错误,我已按照某些博客的建议授予了对临时文件夹的完全访问权限。仍然显示两个错误。

I am trying to import data from DBF file to SQL table using the following command -

select *
from openrowset('MSDASQL', 
'Driver={Microsoft dBase Driver (*.dbf)};DBQ=E:\data\;',
'select * from E:\data\a.dbf')

But it is failing saying

    OLE DB provider "MSDASQL" for linked server "(null)" returned message "[Microsoft][ODBC dBase Driver]General Warning Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x120 Thread 0x3084 DBC 0x303dfbc Xbase'.".    
OLE DB provider "MSDASQL" for linked server "(null)" returned message "[Microsoft][ODBC dBase Driver] Disk or network error.".    
Msg 7303, Level 16, State 1, Line 1    
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "(null)".

Any clue why it is giving error? For the second error I have given full access to temp folder as suggested by some blog. Still it is showing both error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

渡你暖光 2024-08-29 05:45:22

如果文件名是 .dbf
试试这个:

select * from
openrowset('MSDASQL',
'Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=E:\Data;',
'SELECT * FROM a')

If filename is a .dbf
Try this:

select * from
openrowset('MSDASQL',
'Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=E:\Data;',
'SELECT * FROM a')
本宫微胖 2024-08-29 05:45:22

您的 SELECT 指定了文件的路径 - 您应该指定表名,大概是“a”。

Your SELECT is specifying the path to the file - you should be specifying the table name instead, which is presumably 'a'.

冷心人i 2024-08-29 05:45:22

为了补充 CodeByMoonlight,驱动程序信息指向找到数据文件的路径,因此您的后续查询应该只是“Select * should from a”,因为路径和 .dbf 扩展名都应该被隐含

To supplement CodeByMoonlight, the Driver information points to the path the data file is found, so then your subsequent query should only be "Select * should from a" since both the path and the .dbf extension should be implied

迷爱 2024-08-29 05:45:22

您使用的是 64 位 SQL Server,当驱动程序是 32 位时,它会查找 64 位 ODBC 源。 FoxPro(也称为 DBF)有一个解决方法,也适用于 dBASE:

在 Visual Studio 中使用 .NET Framework Provider for OLE DB 打开一个新的 SqlDataSource,然后使用 MS OLE DB Provider for VFP。连接字符串应如下所示(或使用 UNC)

Provider=VFPOLEDB.1;Data Source=h:\Programs\Data;Persist Security Info=True;User    ID=Your_user;Password=your_password 

配置向导包含测试 SQL 的部分。您可以使用此运行即席 SQL。

You are using 64-bit SQL Server which is looking to the 64-bit ODBC sources when the drivers are 32-bit. There is a workaround for FoxPro (also DBF) that should work for dBASE as well:

Open a new SqlDataSource in Visual Studio using the .NET Framework Provider for OLE DB then MS OLE DB Provider for VFP. The connection string should look like this (or with UNC)

Provider=VFPOLEDB.1;Data Source=h:\Programs\Data;Persist Security Info=True;User    ID=Your_user;Password=your_password 

The config wizard includes a part to test your SQL. You can use this run ad hoc SQL.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文