最近我们的正式环境一直在报错一个异常,首先我贴出来异常信息

BLL层 捕获到了请求的url

Net.BLL.MobileFun MobileFun.GetBusinessBidPolicy 异常

传入参数为:AucId=643129;CarId=680362;businessid:41773;

异常信息为:必须声明标量变量 "@UID"。 必须声明标量变量 "@UID"。 必须声明标量变量 "@UID"。

URL:http://*********.com/httpHandler/ForMobileServiceHandler.ashx?action=getBidPolicy&aucId=643129&carId=680362&businessid=BC440DE0D6DCA7FD&version=v3.2.8&onlineid=021d162e-ba3e-45ac-8c59-8d265522d6ef&clienttype=0

Dao层捕获到的异常信息

Net.DAL.AuctionDao 位置:Net.DAL.AuctionDao,方法:GetBidPolicy,错误信息:System.Data.SqlClient.SqlException (0x80131904): 必须声明标量变量 "@UID"。 必须声明标量变量 "@UID"。 必须声明标量变量 "@UID"。 在 System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) 在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) 在 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) 在 System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() 在 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, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) 在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) 在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) 在 System.Data.SqlClient.SqlCommand.ExecuteScalar() 在 Net.DBUtility.MySqlHelper.ExecuteScalar(SqlConnection connection, CommandType commandType, String commandText, SqlParameter[] commandParameters) 在 Net.DBUtility.MySqlHelper.ExecuteScalar(String connectionString, CommandType commandType, String commandText, SqlParameter[] commandParameters) 在 Net.DBUtility.MySqlDataProvider.GetSingle(String SQLString, IDataParameter[] cmdParms) 在 Net.DAL.AuctionDao.GetBidPolicy(String aucId) ClientConnectionId:48c2084f-c6b0-46b5-93b9-8a59ebcd29ed

现在我贴出来 我这几个方法

BLL层

        public string GetBusinessBidPolicy(string AucId, string CarId, string businessid)
{
ConvertToJson ctj = new ConvertToJson();
try
{
int tag = -;
int Offer = ;
int price = ;
int priceNonlocal = ;
objAuctionDao.GetBusinessBidInfo(AucId, CarId, ref tag, ref Offer, ref price, ref priceNonlocal, businessid);
ctj.Append("ResId", "");
ctj.Append("ResMsg", "获取商户出价方案和报价成功!");
ctj.Append("BidWay", tag);//0:本市;1 外迁;-1 尚未选择出价方式
ctj.Append("price", price);
ctj.Append("priceNonlocal", priceNonlocal);
ctj.Append("MyOptimizationOffer", Offer);
}
catch (Exception e)
{
ctj.Append("ResId", "");
ctj.Append("ResMsg", "出现异常,获取商户出价方案和报价失败!");
m_objLog.Error("MobileFun.GetBusinessBidPolicy 异常 传入参数为:AucId=" + AucId + ";CarId=" + CarId + ";businessid:" + businessid + ";异常信息为:" + e.Message+"URL:"+HttpContext.Current.Request.Url);
}
return ctj.ToObject();
}

DAO层

   public void GetBusinessBidInfo(string aucId, string CarId, ref int tag, ref int Offer, ref int price, ref int priceNonlocal, string businessID = "")
{ try
{
string busID = "";
if (string.IsNullOrEmpty(businessID))
busID = new MemberDto().BusinessId;
else
busID = businessID;
//-1 需要出价承诺,其他不需要车价承诺
int tag1 = GetBidPolicy(aucId);
if (tag1 != && tag1 != && tag1 != && tag1 != )
{
tag = ; return;
} // _strSql = string.Format(@"SELECT TOP 1 Tag FROM tbAuction_BidPolicyNow with(nolock) WHERE AucId = {0} AND BusinessId = {1} ORDER BY Created DESC
// SELECT Offer FROM tbSHD_OptimizationQuote with(nolock) WHERE BusinessID={1} AND AucID={0}
// SELECT TOP 1 ISNULL(price,0) price,ISNULL(priceNonlocal,0) priceNonlocal FROM tbAuction_Evaluate with(nolock) WHERE businessId={1} AND carid={2} ORDER BY created desc
// ", aucId, busID, CarId);
_strSql =
@"SELECT TOP 1 Tag FROM tbAuction_BidPolicyNow with(nolock) WHERE AucId = @AucID AND BusinessId = @UID ORDER BY Created DESC
SELECT Offer FROM tbSHD_OptimizationQuote with(nolock) WHERE BusinessID=@UID AND AucID=@AucID
SELECT TOP 1 ISNULL(price,0) price,ISNULL(priceNonlocal,0) priceNonlocal FROM tbAuction_Evaluate with(nolock) WHERE businessId=@UID AND carid=@CarID ORDER BY created desc
";
SqlParameter[] par = { new SqlParameter("@AucID", aucId), new SqlParameter("@UID", businessID), new SqlParameter("@CarID", CarId) };
DataSet obj = _loacaldbRead.Query(_strSql, par);
if (obj != null && obj.Tables.Count > )
{
if (obj.Tables[].Rows.Count > )
{
tag = int.Parse(obj.Tables[].Rows[][].ToString());
}
else
{
tag = -;
}
if (obj.Tables[].Rows.Count > )
{
Offer = int.Parse(obj.Tables[].Rows[][].ToString());
}
if (obj.Tables[].Rows.Count > )
{
price = int.Parse(obj.Tables[].Rows[][].ToString());
priceNonlocal = int.Parse(obj.Tables[].Rows[][].ToString());
}
}
}
catch (Exception e)
{
string error = string.Format("位置:{0},方法:{1},错误信息:{2}", this.GetType().ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, e);
_log.Error(error);
throw; }
       public int GetBidPolicy(string aucId)
{
// _strSql = string.Format("SELECT nonlocaltag FROM tbauction_baseinfo with(nolock) WHERE id = {0}", aucId); try
{
_strSql = "SELECT nonlocaltag FROM tbauction_baseinfo with(nolock) WHERE id = @AucID";
SqlParameter[] par = { new SqlParameter("@AucID", aucId) };
object obj = _loacaldbRead.GetSingle(_strSql, par);
if (obj == null) return -;
return Convert.ToInt32(obj);
}
catch (Exception e)
{
string error = string.Format("位置:{0},方法:{1},错误信息:{2}", this.GetType().ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, e);
_log.Error(error);
throw; } }

我一直很奇怪 我用写的参数化查询语句  然后值初始化在参数数组中丢给ADO.NET执行,为什么会说我没有声明@UID这个变量呢?

而且还有一个异常 无法找到表1

GetBidPolicy  这个方法中根本没有用到@UID的参数但是报错却说
Net.DAL.AuctionDao 位置:Net.DAL.AuctionDao,方法:GetBidPolicy,错误信息:System.Data.SqlClient.SqlException (0x80131904): 必须声明标量变量 "@UID"。 必须声明标量变量 "@UID"。 必须声明标量变量 "@UID"。

现在可以确定 找不到表1 的这个异常是

if (obj.Tables[1].Rows.Count > 0)
                    {
                        Offer = int.Parse(obj.Tables[1].Rows[0][0].ToString());
                    }

这里取 table[1].rows.count  的时候 发现dataset中 表1 null  所以抛出这个异常

那么问题来了 我的三个查询一起执行 就算没有查询到数据  dataset 中也会有三张表 即便是空表 也不能没有表

现在请教  各位 这个异常到底是什么原因产生的呢?

URL 我本地,生产环境都试过了 直接敲出来没有报错异常..

另请教 参数化的sql语句  ado.net 去数据库执行的时候 是如何把值赋给参数的 ,求详解!

关于ADO.NET参数化查询的提问的更多相关文章

  1. SQL Server 2008 R2——VC++ ADO 操作 参数化查询

    ==================================声明================================== 本文原创,转载在正文中显要的注明作者和出处,并保证文章的完 ...

  2. ADO.NET 参数化查询

    参数化查询 使用参数化查询的情景有很多,但最常用的情景是需要用户在查询中进行输入的情况. 有两种方法可供使用.第一,可以讲用户输入嵌入到查询字符串中,例如可能使用.NET Framework中的Str ...

  3. ADO.net参数化查询陷阱

    避免SQL漏洞注入攻击,往往采用的是参数化查询!然而在使用参数化查询中,往往为了方便就直接通过构造方法来进行数据的初始化了,然而这样就引发一个这样的问题,当参数值为0时,就出现参数为空的情况了. 一. ...

  4. C# SqlServer Ado.net参数化查询插入null数据

    DateTime? dt=null; if (dt.HasValue) { cmd.Parameters.AddWithValue("@CreateDateTime", dt); ...

  5. 第19课-数据库开发及ado.net ADO.NET--SQLDataReader使用.SqlProFiler演示.ADoNET连接池,参数化查询.SQLHelper .通过App.Config文件获得连接字符串

    第19课-数据库开发及ado.net ADO.NET--SQLDataReader使用.SqlProFiler演示.ADoNET连接池,参数化查询.SQLHelper .通过App.Config文件获 ...

  6. ADO学习笔记之注入漏洞与参数化查询

    ADO学习笔记之注入漏洞与参数化查询 作为新手,在学习ADO程序时,使用 sql 语言查询数据时,很容易写类似如下代码: using (SqlConnection con = new SqlConne ...

  7. (ADO.NET)SqlCommand参数化查询

    string strcon = "Persist Security Info=False;User id=sa;pwd=lovemary;database=student;server=(l ...

  8. SQL参数化查询

    参数化查询(Parameterized Query 或 Parameterized Statement)是指在设计与数据库链接并访问数据时,在需要填入数值或数据的地方,使用参数 (Parameter) ...

  9. SQL参数化查询自动生成SqlParameter列表

    string sql = @"INSERT INTO stu VALUES (@id,@name) "; 参数化查询是经常用到的,它可以有效防止SQL注入.但是需要手动去匹配参数@ ...

随机推荐

  1. MVC 如何在一个同步方法(非async)方法中等待async方法

    MVC 如何在一个同步方法(非async)方法中等待async方法 问题 首先,在ASP.NET MVC 环境下对async返回的Task执行Wait()会导致线程死锁.例: public Actio ...

  2. mysql导出和导入命令更改数据库名称数据库

    概要 mysql 数据库导入和导出,有两种方法 1)从试点SQL脚本.导入(导入导出又分两种:1. 命令. 2. 工具.这里我们仅仅介绍命令). 2)直接拷贝数据库文件(此方法不推荐). 一.mysq ...

  3. Unity3D游戏开发最佳实践20技能(两)

    [扩展和MonoBehaviourBase] 21.扩展一个自己的Mono Behaviour基类.然后自己的全部组件都从它派生 这能够使你方便的实现一些通用函数.比如类型安全的Invoke.或者是一 ...

  4. Developer Tool - 1. Text Tool and GNU/Linux Tool

    Below two links list famous tool about text processing and provide a good category. And it will give ...

  5. 模仿QQ截图片

    原文:模仿QQ截图片 两个picturebox,一个放图片 完整代码如下 using System; using System.Collections.Generic; using System.Co ...

  6. android:更改PagerTabStrip背景颜色,标题字体样式、颜色和图标,以及指示条的颜色

    1.更改PagerTabStrip背景颜色 我们直接在布局中设置background属性可以: <android.support.v4.view.ViewPager android:id=&qu ...

  7. JMeter怎么在get URL请求、POST请求中添加动态参数用于服务器段安全验证

    从前一个页面(含有服务器段返回给客户端的参数,用于在下一次请求时验证)中添加后置处理器中的Regular Expression Extractor,使用正则表达式对参数进行提取. 在用到这些变量时可以 ...

  8. eclipse 构造 C++ 11 -- ubuntu 12.04

    设备g++ 4.8 sudo apt-get install python-software-properties sudo add-apt-repository ppa:ubuntu-toolcha ...

  9. 胖client和瘦client

    胖和瘦?纠结了妙龄少女,更郁闷了无数男女老少.每天充斥在宿舍的一句话就是:从明天開始我要减肥!!结果,可想而知,真的永远是明天而已.就这样,胖和瘦在我们人类之间无缝不在的存在着.但是client怎么就 ...

  10. 详解JMeter函数和变量

    JMeter函数可以被认为是某种特殊的变量,它们可以被采样器或者其他测试元件所引用.函数调用的语法如下: ${__functionName(var1,var2,var3)} 其中,__function ...