如果在过程里使用连接服务器要加上分布式事务:
两边启动dtcset  XACT_ABORT on
set ANSI_NULL_DFLT_ON on
set ANSI_WARNINGS on BEGIN DISTRIBUTED TRANSACTION
select *  from OPENDATASOURCE('MSDASQL','DRIVER={SQL Server};SERVER=ip;UID=sa;PWD=密码;').pubs.dbo.jobs
commit tran或
select * into 本地库名..表名 from OPENDATASOURCE(
         'SQLOLEDB',
         'Data Source=远程ip;User ID=sa;Password=密码'
         ).库名.dbo.表名insert 本地库名..表名 select * from OPENDATASOURCE(
         'SQLOLEDB',
         'Data Source=远程ip;User ID=sa;Password=密码'
         ).库名.dbo.表名或使用联结服务器:
EXEC sp_addlinkedserver '别名','','MSDASQL',NULL,NULL,'DRIVER={SQL Server};SERVER=远程名;UID=用户;PWD=密码;'
exec sp_addlinkedsrvlogin  @rmtsrvname='别名',@useself='false',@locallogin='sa',@rmtuser='sa',@rmtpassword='密码'
GO
然后你就可以如下:
select * from 别名.库名.dbo.表名
insert 库名.dbo.表名 select * from 别名.库名.dbo.表名
select * into 库名.dbo.新表名 from 别名.库名.dbo.表名
go

解决方案 »

  1.   

    我們的服務器是LAN/SERVER,為何只能用SELECT ,不能用STOREPROCEDURE 取得數據
      

  2.   

    select * into 本地库名..表名 from OPENDATASOURCE(
             'SQLOLEDB',
             'Data Source=远程ip;User ID=sa;Password=密码'
             ).库名.dbo.表名insert 本地库名..表名 select * from OPENDATASOURCE(
             'SQLOLEDB',
             'Data Source=远程ip;User ID=sa;Password=密码'
             ).库名.dbo.表名
      

  3.   

    This error occurs coz Win2000 upgate to Win2003 it disable XA transactions to help prevent the security risk that arises when a user-specified DLL, used by the DTC to communicate with the XA partner's transaction manager, is loaded directly into the DTC process. the distributed transactions fail because MSDTC not be able to do mutual authentication with the other parties (transaction managers, resource managers, clients) involved in the transaction. In some cases, even the local transactions will fail, how to correct this error ,pls see this : http://support.microsoft.com/?id=817066,