visual studio 2010 - sharepoint2010 : database connection in sandboxed web part -


i want make database connection in sandboxed web part. following code works fine when using queries. can tell me how use stored procedure & passing parameters it? how work web service?

    public static dataset chkconn(string strval)     {         public static dataset ds;                 public static string assemblyname = "fulltrustproxy, version=1.0.0.0, culture=neutral, publickeytoken=75e25e9dc5ff21aa";         public static string typename = "dbfulltrust.fulltrustproxy.sqlfulltrustproxy";          try         {             sqlproxyargs proxyargs = new sqlproxyargs();             proxyargs.connectionstring = "persist security info=false;user id=sa;password=;initial catalog=cat;data source=abc";             if (strval == "b")                 proxyargs.command = "select * table1";             else                 proxyargs.command = "select * table2";               proxyargs.returntype = typeof(dataset);             return ds = (dataset)sputility.executeregisteredproxyoperation(assemblyname, typename, proxyargs);                          }         catch         {          }         return ds;     } 

you need change full trust proxy operation.

something take arguments

http://spc3.codeplex.com/sourcecontrol/changeset/view/57419#985226

using (sqlcommand cmd = new sqlcommand(args.command, conn)) {     command.commandtype = commandtype.storedprocedure;     foreach (keyvaluepair<string, object> para in args.parameters) {         cmd.parameters.addwithvalue(para.key, para.value);     }     return cmd.executenonquery(); } 

and use call proxy:

http://spc3.codeplex.com/wikipage?title=databaseproxy

sqldatareaderproxyargs args = new sqldatareaderproxyargs(); args.connectionstring = "data source=;initial catalog=;user id=;password="; args.command = "select * sys.indexes"; args.commandtype = commandtype.text; args.parameters.add(new keyvaluepair<string, object>() { key = "id", value = "1"}); string assemblyname = typeof(sqldatareaderproxyoperation).assembly.fullname; string typename = typeof(sqldatareaderproxyoperation).fullname; object result = sputility.executeregisteredproxyoperation(assemblyname, typename, args); 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -