System.Data.SqlClient.SqlException: ',' 附近有语法错误。
关键字 'as' 附近有语法错误。
关键字 'as' 附近有语法错误。
关键字 'as' 附近有语法错误。
关键字 'as' 附近有语法错误。
关键字 'as' 附近有语法错误。
')' 附近有语法错误。
   在 System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   在 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   在 System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
   在 System.Data.SqlClient.SqlDataReader.get_MetaData()
   在 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   在 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
   在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
   在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   在 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   在 System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   在 System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
   在 System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   在 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   在 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
   在 LHZ.Website.Common.Utility.SqlHelper.FillDataset(SqlConnection connection, SqlTransaction transaction, CommandType commandType, String commandText, DataSet dataSet, String[] tableNames, SqlParameter[] commandParameters)
   在 LHZ.Website.Common.Utility.SqlHelper.FillDataset(SqlConnection connection, CommandType commandType, String commandText, DataSet dataSet, String[] tableNames, SqlParameter[] commandParameters)
   在 LHZ.Website.Common.Utility.SqlHelper.FillDataset(String connectionString, CommandType commandType, String commandText, DataSet dataSet, String[] tableNames, SqlParameter[] commandParameters)
   在 LHZ.Website.ProductList.DAL.ProductDAL.GetProductListByCondition(Int32 CategoryID, Int32 BrandID, Int32 Page, Int32 PageSize, String SortCol, Int32 ProductGroupID, Int32 ProductTypeID, String keywords, Int32 sex, Int32 style, String colorname, Decimal pricefrom, Decimal priceto, Int32 tagID, Int32& TotalNum)
   在 LHZ.Website.ProductList.BLL.ProductBLL.GetProductListByCondition(Int32 CategoryID, Int32 BrandID, Int32 Page, Int32 PageSize, String SortCol, Int32 ProductGroupID, Int32 ProductTypeID, String keywords, Int32 sex, Int32 style, String colorname, Decimal pricefrom, Decimal priceto, Int32 tagID, Int32& TotalNum) 2012-3-31 11:13:01
通过log.txt 我知道 是GetProductListByCondition这个方法下调用的FillDataset方法调用的...(省略N个方法)最终导致了System.Data.SqlClient.SqlConnection.OnError的异常。
可能是输入参数,或者查询条件有问题,但是问题来了,我不知道哪里有错误,哪个参数 没有检查,不能定位错误的地方,无法模拟再现错误的情况。求帮助啊。之前试过 “穿山甲”SQL注入测试工具,但是不是很会用。

解决方案 »

  1.   

    sql语句有语法错误,自己查吧,特别对于用变量拼接的,如果变量值为 "" 空字符串,就很容易产生这错误
      

  2.   

    System.Data.SqlClient.SqlException: ',' 附近有语法错误。
    关键字 'as' 附近有语法错误。
    关键字 'as' 附近有语法错误。
    关键字 'as' 附近有语法错误。
    关键字 'as' 附近有语法错误。
    关键字 'as' 附近有语法错误。
    ')' 附近有语法错误。
    =====================================
    系统已经给出了出现错误的提示,sql语句有错误,把具体的sql语句写入log中,查看sql,查找具体错误。
      

  3.   


    这是SQL注入后的问题。检查你的数据库吧  肯定有被JS或者乱码注入 
    数据还原 清理下   然后再做好防注入措施    
      

  4.   

    DECLARE @DeptCount intEXEC [dbo].[GetProductListByCondition] 
    @CategoryID=111,
    @BrandID=-1,
    @ProductGroupID=-1,
    @ProductTypeID=-1,
    @keyword ='',
    @Sex =-1,
    @Style =-1,
    @ColorName ='',
    @SalesPriceFrom =-1,
    @SalesPriceTo =-1,
    @TagID =-1,
    @Page =1,
    @PageSize =32,
    @SortCol ='addtime desc',
    @TotalNum=@DeptCount OUTPUT
    PRINT @DeptCount
    我在SQLSERVER2008里面手动运行这个存储过程,谁能够写一个SQL注入的 到这个里面 我试试 会不会报错,看看BUG在哪。。谢谢
      

  5.   

    额我还是找找 防止SQL注入的方法看看
      

  6.   

    其实应该很简单的吧,你把你用双引号连接的sql前后添加一个空格就好了比如 "select * from t_table where id= "+txtID.Text+" and name= "+txtName.Text;