日期:2014-05-18  浏览次数:20474 次

远程访问数据库出错
select * from opendatasource('sqloledb','server=192.168.0.7;uid=sa;pwd='';database=cdm').cdm.dbo.a01
访问远程数据库
报错:
服务器: 消息 7302,级别 16,状态 1,行 1
未能创建 OLE DB 提供程序 'sqloledb' 的实例。
OLE DB 错误跟踪[Non-interface error: CoCreate of DSO for sqloledb returned 0x80040e73]。

数据库远程访问开通打了SP4的补丁

------解决方案--------------------
SQL code

几种方法:
--1、openrowset  
/*此方法包含访问OLE DB 数据源中的远程数据所需的全部连接信息。当访问链接服务器中的表时,
这种方法是一种替代方法,并且是一种使用OLE DB 连接并访问远程数据的一次性的临时方法。
对于较频繁引用OLE DB 数据源的情况,请改为使用链接服务器。*/
--启动Ad Hoc Distributed Queries
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
--查询
select * from openrowset('SQLOLEDB','135.32.90.22';'sa';'xxx',ZHH.dbo.S)
--关闭Ad Hoc Distributed Queries
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure

--2、首先创建一个连接创建链接服务器 
exec sp_addlinkedserver   'ITSV ', ' ', 'SQLOLEDB ', '远程服务器名或ip地址'  
--查询 
select *  FROM openquery(ITSV, 'SELECT * FROM 数据库.dbo.表名')
--3、opendatasource/openrowset
  SELECT   *  FROM   opendatasource( 'SQLOLEDB ', 'Data Source=ip/ServerName;User ID=登陆名;Password=密码' ).test.dbo.roy_ta

------解决方案--------------------
SQL code

错了下面这个改下 换成你的IP 登录\密码 表就好了
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
--查询
SELECT   *  FROM   opendatasource( 'SQLOLEDB ', 
'Data Source=135.32.90.22;User ID=sa;Password=sniper' ).zhh.dbo.s
--关闭Ad Hoc Distributed Queries
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0