SQL Server¿ç¿â¸´ÖƱíÊý¾ÝµÄ½â¾ö°ì·¨
¿ç¿â¸´ÖƱíÊý¾Ý£¬ÓкܶàÖÖ·½·¨£¬×î³£¼ûµÄÊÇд³ÌÐòÀ´ÅúÁ¿µ¼ÈëÊý¾ÝÁË£¬µ«ÊÇÕâÖÖ·½·¨²¢²»ÊÇ×îÓÅ·½·¨£¬½ñÌì¾ÍÓõ½ÁËÒ»¸öºÜϬÀûµÄ·½·¨£¬¿ÉÒÔÍêÃÀÔÚ Sql Server 2005 ºÍ Sql Server 2008 ÖÐÖ´ÐУ¡
¸ñʽÈçÏ£º
insert into tableA
SELECT * FROM www.2cto.com
OPENDATASOURCE('SQLOLEDB', 'Data Source=127.0.0.1;User ID=sa;Password=sasasa').databaseName.dbo.tableB
ÕÒµ½Õâ¸ö·½·¨ºó£¬×¼±¸Ö´ÐУ¬¿ÉÊÇÈ´²¢²»Ì«Ë³Àû£¬¿ç¿â¸´ÖƱíÊý¾ÝµÄ;ÖУ¬½ÓÁ¬³öÏÖÁ½¸ö´íÎ󣬵ÚÒ»¸ö´íÎó£º
SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', see "Surface Area Configuration" in SQL Server Books Online.
www.2cto.com
·Ò룺
SQL Server ×èÖ¹Á˶Ô×é¼þ 'Ad Hoc Distributed Queries' µÄ STATEMENT'OpenRowset/OpenDatasource' µÄ·ÃÎÊ£¬ÒòΪ´Ë×é¼þÒÑ×÷Ϊ´Ë·þÎñÆ÷°²È«ÅäÖõÄÒ»²¿·Ö¶ø±»¹Ø±Õ¡£ÏµÍ³¹ÜÀíÔ±¿ÉÒÔͨ¹ýʹÓà sp_configure ÆôÓà 'Ad Hoc Distributed Queries'¡£ÓÐ¹ØÆôÓà 'Ad Hoc Distributed Queries' µÄÏêϸÐÅÏ¢£¬Çë²ÎÔÄ SQL Server Áª»ú´ÔÊéÖÐµÄ "ÍâΧӦÓÃÅäÖÃÆ÷"¡£
½â¾ö°ì·¨£º
ÆôÓà Ad Hoc Distributed Queries£ºexec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
´ý²åÈëÍê³ÉºóÔÙ¹Ø±Õ Ad Hoc Distributed Queries£ºexec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure www.2cto.com
´íÎó2 £º
An explicit value for the identity column in table 'cms_TagSubject' can only be specified when a column list is used and IDENTITY_INSERT is ON.
Õâ¸öÕæµÄºÜ¾À½á£¬Ã»°ì·¨£¬Ö»ÓÐ google ÁË£¬Ö®ºó·¢ÏÖ¿ÉÒÔ ÔÚÖ´ÐÐµÄ SQL Óï¾äǰºó¼ÓÉÏ£ºSET IDENTITY_INSERT tableA ON
--Ö´ÐеÄSQL
SET IDENTITY_INSERT tableB ON
ÊÔ¹ýÖ®ºó£¬·¢ÏÖÕâ¸ö·½·¨²¢²»Äܽâ¾ö£¬ÎÞÄΣ¬×îºó ÕÒÁ˰ëÌ죬ÔÚ¹úÍâ
ÂÛ̳ÕÒµ½Á˽â¾ö°ì·¨£¬¾ÍÊÇ£¬ÒªÐ´²éÈëÁеÄÏêϸÐÅÏ¢
½â¾ö°ì·¨£º
insert into tableA (column1,column2.....)
SELECT * FROM www.2cto.com
OPENDATASOURCE('SQLOLEDB', 'Data Source=127.0.0.1,3422;User ID=sa;Password=sasasa;').databaseName.dbo.tableB
ÖÕÓڴ󹦸æ³É£¬ÁíÍ⣬ÀûÓÃÕâÖÖ·½·¨£¬»¹ÊÇ¿ÉÒÔÖ±½Ó´Ó Excel ÀïÃæ²éѯµÄ£¬ºÇºÇ£¬ÕæÇ¿´ó£º
SELECT * FROM OPENROWSET( 'MICROSOFT.JET.OLEDB.4.0','Excel 8.0;IMEX=1;HDR=YES;DATABASE=D:\a.xls',[sheet1$])
¿ç¿â¸´ÖƱíÊý¾Ý,Ò»Öֺܺõķ½·¨£¬ºÇºÇ£¬Ï£ÍûÄܶԴó¼ÒÓÐËù°ïÖú£¡
Õª×Ô À¶¹âÎÞÏÞµÄBLOG