如何解决Remoting无法传输存储过程参数的问题

本文介绍了一种在Remoting服务中正确传递存储过程参数的方法。通过构建哈希表并在服务端将其转换为SqlParameter数组,成功解决了参数传递的问题。

    在项目的开发中使用Remoting,并且所有的数据请求服务都是通过Remoting完成的,所以自然就在其中到了传递参数的存储过程,在业务逻辑中把参数构建好后传递到Remoting服务端,在取出存储过程的参数时报错,具体错误不记得了,自己尝试了各种方法也不行,上网资讯也没有结果,最后变通了一下,问题解决了,例子如下:

以下部分为客户调用端

        

 1None.gif//先声明参数
 2None.gif        private const string PARAM_GUID = "@GUID";
 3None.gif        private const string PARAM_VGA_TREEGUID = "@VGATreeGUID";
 4None.gif        private const string PARAM_MB_TREEGUID = "@MBTreeGUID";
 5None.gif
 6None.gif        public static string GetProductTypeByGUID(string GUID, String VGATreeID, String MbTreeID)
 7ExpandedBlockStart.gifContractedBlock.gif        dot.gif{
 8InBlock.gif            try
 9ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
10InBlock.gif                int lcID = Thread.CurrentThread.CurrentUICulture.LCID;
11InBlock.gif
12InBlock.gif                BaseModel bt = new BaseModel();
13InBlock.gif
14InBlock.gif                //构建一个哈希表,把参数依次压入
15InBlock.gif                Hashtable parames = new Hashtable();
16InBlock.gif                parames.Add(PARAM_PROGUID, GUID);
17InBlock.gif                parames.Add(PARAM_VGA_TREEGUID, VGATreeID);
18InBlock.gif                parames.Add(PARAM_MB_TREEGUID, MbTreeID);
19InBlock.gif
20InBlock.gif                //把存储过程名称和带参数的哈希表传入
21InBlock.gif                DataAccess.DataBase.RunProcedureDataSet(lcID, "GetProductTypeByTreeID", parames, ref bt);
22InBlock.gif
23InBlock.gif                return bt.Rows[0]["ProductType"].ToString();
24ExpandedSubBlockEnd.gif            }

25InBlock.gif            catch (Exception ex)
26ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
27InBlock.gif                CommFunction.WriteErrorLogFile("public static string GetProductTypeByGUID(stirng GUID, String VGATreeID, String MbTreeID)出错:" + ex.Message);
28InBlock.gif                return "Other";
29ExpandedSubBlockEnd.gif            }

30ExpandedBlockEnd.gif        }

31None.gif
32None.gif



以下为服务端:
    

 1ContractedBlock.gifExpandedBlockStart.gifpublic void Query(int lcid, string SQLString, Hashtable cmdHashtable, ref BaseModel baseModel)#region public void Query(int lcid, string SQLString, Hashtable cmdHashtable, ref BaseModel baseModel)
 2InBlock.gif        // -----------------------------------------------------------------------------------------
 3InBlock.gif        public void Query(int lcid, string SQLString, Hashtable cmdHashtable, ref BaseModel baseModel)
 4ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 5InBlock.gif            if (!CheckRemotingClient())
 6ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 7InBlock.gif                return;
 8ExpandedSubBlockEnd.gif            }

 9InBlock.gif            Console.WriteLine(DateTime.Now.ToString() + "调用了Query(" + lcid.ToString() + ", string SQLString, Hashtable cmdHashtable, ref BaseModel baseModel)");
10InBlock.gif            int i = cmdHashtable.Count;
11InBlock.gif            //以下构造存储过程参数
12InBlock.gif            SqlParameter[] cmdParms = new SqlParameter[i];
13InBlock.gif            int j = 0;
14InBlock.gif            foreach (DictionaryEntry de in cmdHashtable)
15ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
16InBlock.gif                cmdParms[j] = new SqlParameter(de.Key.ToString(), de.Value);
17InBlock.gif                j++;
18ExpandedSubBlockEnd.gif            }

19InBlock.gif            Colorful.DBUtility.DbHelperSQL.Query(lcid, SQLString, cmdParms, ref  baseModel);
20ExpandedSubBlockEnd.gif        }

21InBlock.gif        // -----------------------------------------------------------------------------------------
22ExpandedBlockEnd.gif        #endregion

转载于:https://www.cnblogs.com/blockhead/archive/2006/08/17/479720.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值