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

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. (大数据工程师学习路径)第四步 SQL基础课程----SQL介绍及mysql的安装

    一.数据库和SQL介绍 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库,它的产生距今已有六十多年.随着信息技术和市场的发展,数据库变得无处不在:它在电子商务.银行系统等众多领域都 ...

  2. 使用C++实现功能下载文件

    今天问一个同学C++实现的下载链接下载并保存给定的文件,互联网搜索.看到这样的事情在网上.因此,改变下直接带来,因为他的代码是在VC++,我导入到VS2010中出现点小问题.所以改了下贴了个VS中亲測 ...

  3. AngularJS与ASP.NET MVC登录超时解决方案

    问题: 1.在Action中判断Ajax请求的方法Request.IsAjaxRequest()始终是false 2.返回给前台StatusCode和HttpUnauthorizedResult,前台 ...

  4. PL/SQL 9 许可证

    code:j6stndb9tk72xfbhbqczcdqnjd8lyj466n number:882851 ps:xs374ca 我是PL/SQL版本号是: Version 9.0.3.1641 要注 ...

  5. Nlog 配置总结

    Writes log messages to one or more files. Since NLog 4.3 the ${basedir} isn't needed anymore for rel ...

  6. Prototype and Constructor in JavaScript

    The concept of prototype in JavaScript is very confusing, especially to those who come with a C++/JA ...

  7. android登录界面

    在网上在到一个登录界面感觉挺不错的,给大家分享一下~先看效果图: 这个Demo除了按钮.小猫和Logo是图片素材之外,其余的UI都是通过代码实现的. 一.背景 背景蓝色渐变,是通过一个xml文件来设置 ...

  8. WPF 辅助开发工具

    原文:WPF 辅助开发工具 以下介绍的工具均为免费版,有些是源代码开放,希望对大家有用. Kaxaml 轻量级XAML 编辑器,可以同时进行图像和XAML 代码的编辑.最终生成开发人员想要的XAML ...

  9. Opencv on Ubuntu (from Ubuntu)

     OpenCV Introduction Contents Introduction Installation Step 1 Step 2 Running OpenCV Python in C I ...

  10. centos 7安装源

    参照 http://www.linuxidc.com/Linux/2015-03/114690.htm http://www.cnblogs.com/mchina/archive/2013/01/04 ...