文章摘要
这篇文章详细描述了在SQL Server环境下配置ACE.OLEDB.12驱动以允许在进程中使用ACE.OLEDB.12功能,并通过临时表将数据导入到数据库。文章首先启用了高级选项,然后设置了ACE.OLEDB.12的两个属性(允许在进程中使用和动态参数),接着使用了`INSERT`语句将数据导入到临时表中。最后,文章提醒用户在完成操作后关闭了所有相关设置,以避免后续操作出现问题。文章的核心内容是通过详细配置实现数据导入功能。
–开启导入功能
exec sp_configure ‘show advanced options’,1
reconfigure
exec sp_configure ‘Ad Hoc Distributed Queries’,1
reconfigure
–允许在进程中使用ACE.OLEDB.12
EXEC master.dbo.sp_MSset_oledb_prop N’Microsoft.ACE.OLEDB.12.0′, N’AllowInProcess’, 1
–允许动态参数
EXEC master.dbo.sp_MSset_oledb_prop N’Microsoft.ACE.OLEDB.12.0′, N’DynamicParameters’, 1
–导入临时表
exec (‘insert into jihua(id,[批次号],Right(”’+ @filepath +”’,charindex(”\”,REVERSE(”’+ @filepath +”’))-1),getdate() FROM OPENDATASOURCE (”Microsoft.ACE.OLEDB.12.0”, ”Data Source=’+@filepath+’;User ID=Admin;Password=” )…计划汇总表’)
–注意这里,要先关闭外围的设置,然后再关闭高级选项
exec sp_configure’Ad Hoc Distributed Queries’,0
reconfigure
exec sp_configure’show advanced options’,0
reconfigure
–关闭ACE.OLEDB.12的选项
EXEC master.dbo.sp_MSset_oledb_prop N’Microsoft.ACE.OLEDB.12.0′, N’AllowInProcess’, 0
EXEC master.dbo.sp_MSset_oledb_prop N’Microsoft.ACE.OLEDB.12.0′, N’DynamicParameters’, 0
–开启导入功能
exec sp_configure ‘show advanced options’,1
reconfigure
exec sp_configure ‘Ad Hoc Distributed Queries’,1
reconfigure
–允许在进程中使用ACE.OLEDB.12
EXEC master.dbo.sp_MSset_oledb_prop N’Microsoft.ACE.OLEDB.12.0′, N’AllowInProcess’, 1
–允许动态参数
EXEC master.dbo.sp_MSset_oledb_prop N’Microsoft.ACE.OLEDB.12.0′, N’DynamicParameters’, 1
–导入临时表
exec (‘insert into jihua(id,[批次号],Right(”’+ @filepath +”’,charindex(”\”,REVERSE(”’+ @filepath +”’))-1),getdate() FROM OPENDATASOURCE (”Microsoft.ACE.OLEDB.12.0”, ”Data Source=’+@filepath+’;User ID=Admin;Password=” )…计划汇总表’)
–注意这里,要先关闭外围的设置,然后再关闭高级选项
exec sp_configure’Ad Hoc Distributed Queries’,0
reconfigure
exec sp_configure’show advanced options’,0
reconfigure
–关闭ACE.OLEDB.12的选项
EXEC master.dbo.sp_MSset_oledb_prop N’Microsoft.ACE.OLEDB.12.0′, N’AllowInProcess’, 0
EXEC master.dbo.sp_MSset_oledb_prop N’Microsoft.ACE.OLEDB.12.0′, N’DynamicParameters’, 0
© 版权声明
文章版权归作者所有,未经允许请勿转载。