»ñÈ¡SQL Server·þÎñÆ÷ÁбíµÄ¼¸ÖÖ·½·¨
Ò»¡¢ SQL DMO ÃèÊö£ºSQL Distributed Management Objects£¨SQL·Ö²¼Ê½¹ÜÀí¶ÔÏ󣩣¬´æÔÚÓÚSQLDMO.dllÎļþÖУ¬Êµ¼ÊÉÏÊÇÒ»¸öCOM ¶ÔÏó£¬Í¨¹ýµ÷ÓÃSQL DMOµÄListAvailableSQLServers·½·¨È¡µÃ¡£ ÁбíÀàÐÍ£ºÁоÙ×°ÓС°¿Í»§¶Ë¡±ºÍ¡°·þÎñ¶Ë¡±µÄ¼ÆËã»ú¡£ ÊÊÓÃÌõ¼þ£º×°ÓÐ SQL Server£¬ÇÒÓÐSQLDMO.dllÎļþ¡£ ËٶȣºÖÐ µ÷ÓÃʾÀý£ºGetSQLServerList(ListBox1.items); ´úÂ룺 uses ComObj; function GetSQLServerList(var AList: TStrings): Boolean; var SQLServerApp: Variant; ServerList: Variant; i: Integer; begin Result := True; try SQLServerApp := CreateOleObject('SQLDMO.Application'); ServerList := SQLServerApp.ListAvailableSQLServers; for i := 1 to ServerList.Count do AList.Add(ServerList.Item(i)); SQLServerApp := Unassigned; ServerList := Unassigned; except Result := False; end; end; ¶þ¡¢ NetServerEnum ÃèÊö£ºÍøÂç·þÎñº¯Êý£¬´æÔÚÓÚNetApi32.dllÎļþÖУ»Í¨¹ýNetServerEnumº¯Êý¿ÉÈ¡µÃ×°ÓÐSQL Server·þÎñ¶ËµÄ¼ÆËã»úÁÐ±í£¬Ö»×°ÓÐSQL Server¿Í»§¶ËµÄ¼ÆËã»ú½«²»»á±»ÁоÙÆäÖУ»Èç¹ûһ̨¼ÆËã»úµÄSQL Server·þÎñ¸Õ¸ÕÆô¶¯£¬ÄÇô´Ëº¯Êý½«»á¹ýºÜ¾Ã²ÅÄÜÈ¡µ½¸Ã¼ÆËã»ú¡£ ÁбíÀàÐÍ£º½öÁоÙ×°ÓС°·þÎñ¶Ë¡±µÄ¼ÆËã»ú¡£ ÊÊÓÃÌõ¼þ£ºÓÐNetApi32.dllÎļþ¡£ Ëٶȣº¿ì µ÷ÓÃʾÀý£ºGetSQLServerList(ListBox1.items); ´úÂ룺 type NET_API_STATUS = DWORD; PServerInfo100 = ^TServerInfo100; _SERVER_INFO_100 = record sv100_platform_id: DWORD; sv100_name: LPWSTR; end; {$EXTERNALSYM _SERVER_INFO_100} TServerInfo100 = _SERVER_INFO_100; SERVER_INFO_100 = _SERVER_INFO_100; {$EXTERNALSYM SERVER_INFO_100} const NERR_Success = 0; MAX_PREFERRED_LENGTH = DWORD(-1); SV_TYPE_SQLSERVER = $00000004; function NetApiBufferAllocate(ByteCount: DWORD; var Buffer: Pointer): NET_API_STATUS; stdcall; external 'netapi32.dll' name 'NetApiBufferAllocate'; function NetServerEnum(ServerName: LPCWSTR; Level: DWORD; var BufPtr: Pointer; PrefMaxLen: DWORD; var EntriesRead: DWORD; var TotalEntries: DWORD; ServerType: DWORD; Domain: LPCWSTR; ResumeHandle: PDWORD): NET_API_STATUS; stdcall; external 'netapi32.dll' name 'NetServerEnum'; function NetApiBufferFre
Ïà¹ØÎĵµ£º
1. SQLÓÅ»¯µÄÔÔòÊÇ£º½«Ò»´Î²Ù×÷ÐèÒª¶ÁÈ¡µÄBLOCKÊý¼õµ½×îµÍ,¼´ÔÚ×î¶ÌµÄʱ¼ä´ïµ½×î´óµÄÊý¾ÝÍÌÍÂÁ¿¡£
µ÷Õû²»Á¼SQLͨ³£¿ÉÒÔ´ÓÒÔϼ¸µãÇÐÈ룺
¼ì²é²»Á¼µÄSQL£¬¿¼ÂÇÆäд·¨ÊÇ·ñ»¹ÓпÉÓÅ»¯ÄÚÈÝ
¼ì²é×Ó²éѯ ¿¼ÂÇSQL×Ó²éѯÊÇ·ñ¿ÉÒÔÓüòµ¥Á¬½ÓµÄ·½Ê½½øÐÐÖØÐÂÊéд
¼ì²éÓÅ»¯ ......
ÔÚSQLServerµÄÐÔÄܵ÷ÓÅÖУ¬ÓÐÒ»¸ö²»¿É±ÈÄâµÄÎÊÌ⣺ÄǾÍÊÇÈçºÎÔÚÒ»¶ÎÐèÒª³¤Ê±¼äµÄ´úÂë»ò±»Æµ·±µ÷ÓõĴúÂëÖд¦ÀíÁÙʱÊý¾Ý¼¯?±í±äÁ¿ºÍÁÙʱ±íÊÇÁ½ÖÖÑ¡Ôñ¡£ÈçºÎÈ·¶¨Ê²Ã´Ê±ºòÓÃÁÙʱ±í£¬Ê²Ã´Ê±ºòÓñí±äÁ¿ÄØ£¿ÁÙʱ±íºÍ±í±äÁ¿¶¼ÓÐÌض¨µÄÊÊÓû·¾³¡£
¡¡¡¡±í±äÁ¿
¡¡¡¡±äÁ¿¶ ......
select ID,Item1,Item2,Item3,Item4
into #Temp
from (
select ID='200910',Item1='A',Item2='B',Item3='C',Item4='T1'
union all
select ID='200910',Item1='',Item2='B',Item3='C' ,Item4='G2'
union all
select ID='200910',Item1='A',Item2='D',Item3='C' ,Item4='T3'
union all
select ID='200910',Item ......
--´ÓExcelÎļþÖÐ,µ¼ÈëÊý¾Ýµ½SQLÊý¾Ý¿âÖÐ,ºÜ¼òµ¥,Ö±½ÓÓÃÏÂÃæµÄÓï¾ä:
/*===================================================================*/
--Èç¹û½ÓÊÜÊý¾Ýµ¼ÈëµÄ±íÒѾ´æÔÚ
insert into ±í select * from
OPENROWSET('MICROSOFT.JET.OLEDB.4.0'
,'Excel 5.0;HDR=YES;DATABASE=c:\test.xls',sheet1$)
--Èç ......
¹ØϵÊý¾Ý¿âÖеIJÙ×÷»á¶ÔÕû¸öÐм¯Æð×÷Óá£ÓÉ SELECT Óï¾ä·µ»ØµÄÐм¯°üÀ¨Âú×ã¸ÃÓï¾äµÄ WHERE ×Ó¾äÖÐÌõ¼þµÄËùÓÐÐС£ÕâÖÖÓÉÓï¾ä·µ»ØµÄÍêÕûÐм¯³ÆΪ½á¹û¼¯¡£Ó¦ÓóÌÐò£¬ÌرðÊǽ»»¥Ê½Áª»úÓ¦ÓóÌÐò£¬²¢²»×ÜÄܽ«Õû¸ö½á¹û¼¯×÷Ϊһ¸öµ¥ÔªÀ´ÓÐЧµØ´¦Àí¡£ÕâЩӦÓóÌÐòÐèÒªÒ»ÖÖ»úÖÆÒÔ±ãÿ´Î´¦ÀíÒ»ÐлòÒ»²¿·ÖÐС£Óαê¾ÍÊÇÌṩÕâÖÖ»úÖƵĶԽ ......