1、SQL Server 阻止了对组件 Ad Hoc Distributed Queries 的访问想用openrowset查询远程数据库,结果提示SQL Server 阻止了对组件 Ad Hoc Distributed Queries 的访问错误,在网上搜索了一下,找到解决方法:-Ad Hoc Distributed Queries 是advanced options ,因此必须先将show advanced options,1,打开高级选项后才能对它进行设置。关闭时,也是先关Ad Hoc Distributed Queries 再关advanced options。启用Ad Hoc Distr
2、ibuted Queries:exec sp_configure show advanced options,1 reconfigure exec sp_configure Ad Hoc Distributed Queries,1 reconfigure 使用完成后,关闭Ad Hoc Distributed Queries: exec sp_configure Ad Hoc Distributed Queries,0 reconfigure exec sp_configure show advanced options,0 reconfigure-以上,在SQL2005运行时遇到。若没有将sp
3、_configure中以上两个参数进行配置,则都会报错。访问外部链接数据库,获取记录集两种方法SELECT * FROM OPENDATASOURCE( SQLOLEDB, -此处是连MYSQL Data Source=ServerName;User ID=sa;Password=sa ).DataBaseName.dbo.Tableselect * from openrowset( SQLOLEDB , IP地址; 用户名; 密码,数据库名.dbo.表名) -此处是连MYSQL若是连ACCESS和EXCEL则变成:select * from openrowset(Microsoft.Jet.
4、OLEDB.4.0,IP地址或数据库路径(例:c:xxx.mdb);用户名(一般默认为admin);密码(一般为空),数据库名.dbo.表名)select * from opendatasource(Microsoft.Jet.OLEDB.4.0,Data Source=数据库路径;User ID=admin;password=).DataBaseName.dbo.Table -连ACCESSselect * from opendatasource(Microsoft.Jet.OLEDB.4.0,Data Source=数据库路径;User ID=admin;password=;Extended properties=Excel 5.0).DataBaseName.dbo.Table -连EXCEL-若没有加Extended Properties则会报错。-运行完后,需要记得再改回去,以避免安全性问题