SqlServer远程连接

来源:互联网 发布:彩虹自动发卡源码 编辑:程序博客网 时间:2024/05/21 17:38
在进行sqlServer远程连接数据库进行查询时前提条件是我们要开启
Ad Hoc Distributed Queries 服务 因为这个服务不安全sqlServer默认关闭该服务
我们需要注意的是在开启服务完成查询后,一定要记得关闭这个服务。
开启 Ad Hoc Distributed Queries :
exec sp_configure 'show advanced options',1reconfigureexec sp_configure 'Ad Hoc Distributed Queries',1reconfigure
关闭:
exec sp_configure 'Ad Hoc Distributed Queries',0reconfigureexec sp_configure 'show advanced options',0reconfigure
远程查询:
select top 10 * from openrowset  ( 'SQLOLEDB','10.122.127.20' ; 'sa';'exp123' ,Expense2BizA.dbo.tblsheet) 
     关键字指定连接方式 服务器    用户  密码      数据库      表名
-- 生成本地表 select * into 表 from openrowset ( ' SQLOLEDB ' , ' sql服务器名 ' ; ' 用户名 ' ; ' 密码 ' ,数据库名.dbo.表名) -- 把本地表导入远程表 insert openrowset ( ' SQLOLEDB ' , ' sql服务器名 ' ; ' 用户名 ' ; ' 密码 ' ,数据库名.dbo.表名) select * from 本地表 
0 0
原创粉丝点击