惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News | PayPal Newsroom
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
大猫的无限游戏
大猫的无限游戏
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
LangChain Blog
S
SegmentFault 最新的问题
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Project Zero
Project Zero
P
Privacy & Cybersecurity Law Blog
V
Vulnerabilities – Threatpost
博客园 - 三生石上(FineUI控件)
Recorded Future
Recorded Future
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
宝玉的分享
宝玉的分享
aimingoo的专栏
aimingoo的专栏
T
Tor Project blog
T
The Exploit Database - CXSecurity.com
Schneier on Security
Schneier on Security
H
Help Net Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
M
MIT News - Artificial intelligence
W
WeLiveSecurity
P
Proofpoint News Feed
A
About on SuperTechFans
S
Securelist
I
InfoQ
G
Google Developers Blog
博客园 - 司徒正美
博客园 - 叶小钗
Latest news
Latest news
F
Fortinet All Blogs
G
GRAHAM CLULEY
腾讯CDC
Jina AI
Jina AI
S
Schneier on Security
I
Intezer
V
Visual Studio Blog
美团技术团队
V2EX - 技术
V2EX - 技术
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
Microsoft Security Blog
Microsoft Security Blog
Blog — PlanetScale
Blog — PlanetScale
P
Proofpoint News Feed
罗磊的独立博客
Y
Y Combinator Blog

博客园 - 左少白

oracle 找回DROP掉的表 求解,工作流点通过时,弹出窗口让用户录入审核意见 oracle 游标 c# 多态 sqlserver 按五分钟分组 c# 继承 查询行转列 oracle oracle trunc (date,dd )函数 oracle 游标 对象集合转换为datatable 用C# 正则 提取HTML标签中的值? oracle decode 与 case when ,空的处理 oracle select for update sql1 同期进度,完成率 Oracle Index 相關知識 玩转DevExpress.XtraGrid.view.gridview oracle索引 在Oracle中进行大小写不敏感的查询2
SqlParameter序列化的问题
左少白 · 2011-05-20 · via 博客园 - 左少白

SqlParameter remoting 客户端调用服务端方法: DataSet ExecuteProc(string procedurename, SqlParameter[] a);

              调用:  DataSet ds = SqlUtil.ExecuteProc("存储过程名", parameters);//

parameters  为

 SqlParameter[] 类型的实例

              报错: 由于安全限制,无法访问类型 System.Runtime.Remoting.ObjRef。原因是

SqlParameter不能序列化.需要添加一个类来转换.

 添加如下类:

namespace Modal.SerSqlParameter
{
    [Serializable]
    
public class SerSqlParameter
    {
        
public SerSqlParameter(SqlParameter sPara)
        {
            
this.paraName = sPara.ParameterName;
            
this.paraLen = sPara.Size;
            
this.paraVal = sPara.Value;
            
this.sqlDbType = sPara.SqlDbType;
        }
public SqlParameter ToSqlParameter()
        {
            SqlParameter para 
= new SqlParameter(this.paraName, this.sqlDbType, this.paraLen);
            para.Value 
= this.paraVal;
            
return para;
        }
private string paraName = "";
        
public string ParaName
        {
            
get { return this.paraName; }
            
set { this.paraName = value; }

        }

private int paraLen = 0;
        
public int ParaLen
        {
get { return this.paraLen; }
            
set { this.paraLen = value; }
        }
private object paraVal = null;
        
public object ParaVal
        {
            
get { return this.paraVal; }
            
set { this.paraVal = value; }
        }
private SqlDbType sqlDbType = SqlDbType.NVarChar;
        
public SqlDbType SqlDbType
        {
            
get { return this.sqlDbType; }set { this.sqlDbType = value; }
        }
    }
}

服务端原来的  

//原来的
public DataSet ExecuteProc(string procedurename, SqlParameter[] arParams)   { 
            DataSet ds 
= SqlUtil.ExecuteProc(procedurename, arParams);
            
return ds;
        }
//修改为
 public DataSet ExecuteProc(string procedurename, IList<SerSqlParameter> arParams)
        {
            SqlParameter[] p 
= new SqlParameter[arParams.Count];
            
for (int i = 0; i < arParams.Count;i++ )
            {
                p[i]
=arParams[i].ToSqlParameter();
            }
            DataSet ds 
= SqlUtil.ExecuteProc(procedurename, p);
            
return ds;
        }

客户端修改为 

//原来的调用
DataSet ds = SqlUtil.ExecuteProc("过程名", parameters);//修改后
 IList<SerSqlParameter> list = new List<SerSqlParameter>();
            
foreach (SqlParameter pa in parameters)
            { 
                SerSqlParameter serparam 
= new SerSqlParameter(pa);
                list.Add(serparam);
            }

 DataSet ds=SqlUtil.ExecuteProc("过程名",list);