我正在尝试将 XML 文件中的数据导入数据库。我已经使用 制作了一个测试脚本BULK INSERT
,但是当我在实时数据库上进行测试时,权限BULK
被禁用。
尝试#1:
BULK INSERT XMLTable FROM 'C:\Radu\test.xml' WITH (ROWTERMINATOR = '>');
因此,我继续研究以找到一种避免使用的方法,BULK
并找到了其他选项,例如OPENROWSET
and OPENDATASOURCE
。但不幸的是,这些操作的权利也被撤销了。
尝试#2:
SELECT *
FROM OPENROWSET('MSDASQL',
'Driver={Microsoft Text Driver (*.xml)};DefaultDir=C:\Radu\test.xml;',
'SELECT * FROM [test.xml];' )
导致错误:
Msg 15281, Level 16, State 1, Line 1
SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', see "Surface Area Configuration" in SQL Server Books Online.
我已经尝试了RECONFIGURE
这个权限,但没有成功。
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'Ad Hoc Distributed Queries', 1;
RECONFIGURE;
还导致:
Msg 15247, Level 16, State 1, Procedure sp_configure, Line 94
User does not have permission to perform this action.
Msg 5812, Level 14, State 1, Line 2
You do not have permission to run the RECONFIGURE statement.
Msg 15123, Level 16, State 1, Procedure sp_configure, Line 51
The configuration option 'Ad Hoc Distributed Queries' does not exist, or it may be an advanced option.
Msg 5812, Level 14, State 1, Line 4
You do not have permission to run the RECONFIGURE statement.
我仍在尝试寻找解决方案只是将信息导入数据库,我不需要特殊格式,只需获取系统中的数据,虽然理想情况下我想将每个 xml 行作为记录导入我的桌子。
看来我的大部分选择都被切断了,所以我非常感谢任何建议。
更新:
我将创建一个存储过程来导入这些数据,所以理想情况下这将是通用的,没有使用 XML 信息进行硬编码。