一、对于表内的数据量非常大(上百万条记录)可以创建连接服务器如下语句

exec   sp_addlinkedserver     'server','','SQLOLEDB','192.168.1.40'  
  exec   sp_addlinkedsrvlogin   'server','false',null,'用户名','密码'

导入语句:

select   *   into   表   from   'server'.数据库名.dbo.表名   

以后不再使用时删除链接服务器  
 exec   sp_dropserver   'server','droplogins'  

 

二、如果只是临时访问,可用openrowset

  导入语句:
  select   *   into   表   from   openrowset('SQLOLEDB','sql服务器名';'用户名';'密码',数据库名.dbo.表名)

在执行上面语句前要先执行下面的语句

exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure

在导入语句执行完成后在执行下面的语句把AD Hoc Distributed 关闭

exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure

exec sp_configure 'show advanced options',0
reconfigure

 

如果把导入语句写在SqlCommand里执行,需要注意CommandTimeOut的设置。默认是30秒。

 

相关文章:

  • 2021-11-20
  • 2021-04-14
  • 2021-07-24
  • 2021-04-01
  • 2021-12-19
  • 2021-10-28
  • 2021-05-25
  • 2021-12-27
猜你喜欢
  • 2021-11-03
  • 2021-11-21
  • 2021-11-20
  • 2022-12-23
  • 2022-01-15
  • 2021-06-07
相关资源
相似解决方案