报错:权限被拒绝: 无法远程调用非公共或静态方法
rt

解决方案 »

  1.   

    我做的是remoting 。
    在调用远程对象的时候,传递一些参数(SqlParameter 数组)。
    remoting 里面有一个函数:public SqlCommand BuildQueryCommand(string storedProcName, SqlParameter[] parameters) 

    try 

    if(myCn.State==ConnectionState.Closed) 
    myCn.Open(); 
    SqlCommand command = new SqlCommand( storedProcName, myCn ); 
    command.CommandType = CommandType.StoredProcedure; foreach (SqlParameter parameter in parameters) 

    command.Parameters.Add( parameter ); 

    return command; 

    catch(Exception ex) 

    throw new Exception(ex.Message+"数据库操作失败~(由BuildQueryCommand引发!)\n"); } 
    finally 

    myCn.Close(); 

    } 一调用就报错:权限被拒绝: 无法远程调用非公共或静态方法 
    可我查了下资料
    Parameters.Add( parameter ); 并非静态方法或私有方法如果我把这句话:command.Parameters.Add( parameter ); 
    屏蔽掉,就不会报错了。很奇怪!
      

  2.   

    如果我把这句话:command.Parameters.Add( parameter ); 
    屏蔽掉,就不会报错了。
    那你把这句话封装到服务端内部,不要在接口中体现出来。
      

  3.   

    public SqlCommand BuildQueryCommand(string storedProcName, SqlParameter[] parameters) 
    这个函数本来就是封闭在服务端的,并没有在接口中定义
    command.Parameters.Add( parameter ); 
    更是函数内部的一个调用
      

  4.   

    just because Sql* objects are derived from System.MarshalByRefObject, it doesn't mean you should do remoting on these objectshttp://groups-beta.google.com/group/microsoft.public.dotnet.framework.remoting/msg/8ad8814cc897945f?hl=en
      

  5.   

    http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpguide/html/cpconbuildingremotabletype.asp
      

  6.   

    saucer(思归) 已经说了,SqlParameter不能远程传送
      

  7.   

    好像微软网上有个教程培训上说,凡是从System.MarshalByRefObject继承的类,都是可以被远程化的这是不是微软设计时候的一个问题呢?有什么别的解决方法吗?To saucer(思归)
    顺便来这领分吧。虽然分对你来说没什么意思了
    不过还是来吧^_^
      

  8.   

    To solve this, you will need to pass your query to the server in some form 
    other than a SqlCommand. 对于这一句,您采取的是什么方法呢?
      

  9.   

    To saucer(思归)http://community.csdn.net/Expert/topic/4023/4023517.xml?temp=.7932093请领分