Step1:允许Sql Sever访问Access数据库。需要编写sql脚本并运行(和新建查询语句的操作步骤一样):
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
Step2:开始导入:
SELECT *
INTO 表1
FROM OPENDATASOURCE ('Microsoft.Jet.OLEDB.4.0','Data Source="C:\myAccessDb.mdb";')...表2
注:表1指的是SQL Server中的表名称,实现不许要建表,否则会提示表已经存在的错误;表2指的是Access需要导入到Sql server中的表
Step3:关闭Sql Sever到Access的访问
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure
如果不做1,将会出现如下错误提示:
SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用 'Ad Hoc Distributed Queries'。有关启用 'Ad Hoc Distributed Queries' 的详细信息,请参阅 SQL Server 联机丛书中的 "外围应用配置器"。