如何使用SQL脚本将数据从DBF导入到SQL?
我正在尝试使用以下命令将数据从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果文件名是
.dbf
试试这个:
If filename is a
.dbf
Try this:
您的 SELECT 指定了文件的路径 - 您应该指定表名,大概是“a”。
Your SELECT is specifying the path to the file - you should be specifying the table name instead, which is presumably 'a'.
为了补充 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
您使用的是 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)
配置向导包含测试 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)
The config wizard includes a part to test your SQL. You can use this run ad hoc SQL.