C#.NET·ÀÖ¹SQL×¢Èëʽ¹¥»÷
1 ·ÀÖ¹sql×¢Èëʽ¹¥»÷(¿ÉÓÃÓÚUI²ã¿ØÖÆ£© #region ·ÀÖ¹sql×¢Èëʽ¹¥»÷(¿ÉÓÃÓÚUI²ã¿ØÖÆ£©
2
3 /**/ ///
4 /// ÅжÏ×Ö·û´®ÖÐÊÇ·ñÓÐSQL¹¥»÷´úÂë
5 ///
6 /// ´«ÈëÓû§Ìá½»Êý¾Ý
7 /// true-°²È«£»false-ÓÐ×¢Èë¹¥»÷ÏÖÓУ»
8 public bool ProcessSqlStr( string inputString)
9 {
10 string SqlStr = @" and|or|exec|execute|insert|select|delete|update|alter|create|drop|count|\*|chr|char|asc|mid|substring|master|truncate|declare|xp_cmdshell|restore|backup|net +user|net +localgroup +administrators " ;
11 try
12 {
13 if ((inputString != null ) && (inputString != String.Empty))
14 {
15 string str_Regex = @" \b( " + SqlStr + @" )\b " ;
16
17 Regex Regex = new Regex(str_Regex, RegexOptions.IgnoreCase);
18 // string s = Regex.Match(inputString).Value;
19 if ( true == Regex.IsMatch(inputString))
20 return false ;
21
22 &
Ïà¹ØÎĵµ£º
ÎÒÃǵÄSQLÓï¾äµÄÖ´Ðж¼ÊÇÓÉÒ»¸öÀàÀ´Íê³ÉµÄ£¡Õâ¸öÀà¾ÍÊÇSQLStatement£¬Õâ¸öÀà¾ÍÊÇÎÒÃÇÓÃÀ´Ö´ÐÐSQLÓï¾äµÄÀ࣬¸ÃÀàµÄʹÓÃÒ²ÊǷdz£¼òµ¥µÄ£¬ÎÒÃÇÖ»ÐèÒª¼ÇסÁ½¸öÊôÐÔÁ½¸ö·½·¨¡£ÎÒÃÇÀ´¿´Ò»Ï£¡
textÊôÐÔ£ºËùÒªÖ´ÐеÄSQLÓï¾ä£¬¸ÃÊôÐÔÊÇÒ»¸ö×Ö·û´®¸ñʽ£¬ËùÒÔÎÒÃǵÄSQLÓï¾ä¶¼ÊÇ×Ö·û´®£¡
sqlConnectionÊôÐÔ£º¸ÃÊôÐÔÊÇÉèÖÃSQLSt ......
create table tb (ptoid int,proclassid int,proname varchar(10))
insert tb
select 1,1,'Ò·þ1'
union all
select 2,2,'Ò·þ2'
union all
select 3,3,'Ò·þ3'
union all
select 4,3,'Ò·þ4'
union all
select 5,2,'Ò·þ5'
union all
select 6,2,'Ò·þ6'
union all
select 7,2,'Ò·þ7'
union all
select 8 ......
ÔÎĵØÖ·£ºhttp://www.eygle.com/case/Use.sql_trace.to.Diagnose.database.htm
SQL_TRACEÊÇOracleÌṩµÄÓÃÓÚ½øÐÐSQL¸ú×ÙµÄÊֶΣ¬ÊÇÇ¿ÓÐÁ¦µÄ¸¨ÖúÕï¶Ï¹¤¾ß.ÔÚÈÕ³£µÄÊý¾Ý¿âÎÊÌâÕï¶ÏºÍ½â¾öÖУ¬SQL_TRACEÊǷdz£³£Óõķ½·¨¡£
±¾ÎľÍSQL_TRACEµÄʹÓÃ×÷¼òµ¥Ì½ÌÖ£¬²¢Í¨¹ý¾ßÌå°¸Àý¶Ôsql_traceµÄʹÓýøÐÐ˵Ã÷.
Ò»¡¢ »ù´¡½éÉÜ
(a) ......
µÚÒ»Ìõ£º
select * from where field in (1,2,3) ÕâÖÖд·¨Ó¦¸ÃÉáÆúÁË£¬¶øÓ¦¸ÃÕâÑùд£º
select * from table where field = 1 or field = 2 or field = 3
ΪʲôÄØ£¿
·²ÊÂÖ»ÓÐ×ö¹ý²ÅÖªµÀ£¬×Ô¼º½¨¸ö±í£¬²åÈë10WÌõ²âÊÔÊý¾Ý£¬ÓÃsql²âÊÔһϱãÖª£¬ÒòΪ¹¤×÷±ãÀû£¬ÎÒÔÚ²úÆ·»úºÍÍâÍø²âÊÔ»ú¶¼ÒѾ²âÊÔ¹ý£ ......
ÓÐÐí¶à²»Í¬ÀàÐ͵ÄÊý¾Ý¿â¹ÜÀíÔ±¡£ һЩÀàÐ͵ÄÊý¾Ý¿â¹ÜÀíÔ±ÖÂÁ¦ÓÚÓÚ¿ª·¢ÁìÓò£¬¶øÆäËûµÄÒ»²¿·Ö¸üÖØÊÓÊý¾Ý¿âÐÔÄܵĵ÷ÕûÒÔ¼°ÈÔÈ»ÓÐÒ»²¿·ÖÊý¾Ý¿â¹ÜÀíÔ±ÔòÖÂÁ¦ÓÚ¹ÜÀíSQL ServerµÄÒµÎñ¡£ ÒÀ¾ÝÊý¾Ý¿â¹ÜÀíÔ±µÄ¹¤×÷»·¾³²»Í¬£¬ËûÃǽ«Ö´ÐÐÒ»¶¨ÊýÁ¿µÄ²»Í¬µÄÈÎÎñ¡£ÎªÁËÇø·ÖËùÓв»Í¬µÄÈÎÎñ£¬Êý¾Ý¿â¹ÜÀíÔ±¿ÉÄÜÒªÖ´ÐÐÎÒÇåµ¥ÉÏËùÁеÄÈÎÎñ¡£
¡¡ ......