我的一个小程序,需要从一个服务器的数据库中选取数据写入另一个服务器的表中,如下:
sql = "insert table1 select * from 服务器2.数据库2.dbo.表名",假设conn为连接的当前数据库,
我在程序中这样写:conn.execute(sql),为什么就不行呢?难道在VB中SQL语句不能为不同数据库(或不同服务器)吗?请各位高手指教,多谢了

解决方案 »

  1.   

    insert into table1 select * from server2.db2.dbo.table where ........如果不行就要看你的服务器的设置了
      

  2.   

    可以的
    用openrowset 取另一服务器的记录
    openrowset的示例如下:
    SELECT a.*
    FROM OPENROWSET('MSDASQL',
       'DRIVER={SQL Server};SERVER=seattle1;UID=sa;PWD=MyPass',
       pubs.dbo.authors) AS a
    ORDER BY a.au_lname, a.au_fname
      

  3.   

    insert into server1.db1.dbo.table1 select * from server2.db2.dbo.table where ........
    你试一下这个行不行