2015-11-20 127 views
0

您好,我需要使用PowerShell与DocumentDB。我的代码在这里DocumentDB存储过程错误

$url = "https://**********.documents.azure.com:443/" 
$key = "*****************************" 

$client = [Microsoft.Azure.Documents.Client.DocumentClient]::new([uri]$url,$key) 

$db_list = $client.ReadDatabaseFeedAsync().Result 

$coll_list = $client.ReadDocumentCollectionFeedAsync($db_list.CollectionsLink).Result 

有我们的收集,所有的好, 现在我们创建过程

$proc = [Microsoft.Azure.Documents.StoredProcedure]::new() 
$proc.id = 'hello_world' 
$proc.body = 'function hello_world() { 
      var context = getContext(); 
      var response = context.getResponse(); 

      response.setBody("Hello, World"); 
    }' 

$procedure = $client.CreateStoredProcedureAsync($coll_list.SelfLink,$proc) 

程序已成功创建并在$ procedure.Result.Resource.Selflink我们有链接:DBS/ONIYAA ==/colls/ONIYAI9WJgA = /存储过程/ ONIYAI9WJgAHAAAAAAAAgA ==/

现在我们可以尝试执行程序,我们总是有误差

$client.ExecuteStoredProcedureAsync($procedure.Result.Resource.Selflink) 

错误日志中ExecuteStoredProcedureAsync:

ErrorRecord     : Unable to find an overload for "ExecuteStoredProcedureAsync" and a number of arguments: "2". 
StackTrace     : в CallSite.Target(Closure , CallSite , Object , Object , String 
          ) 
           в System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet 
           ](CallSite site, T0 arg0, T1 arg1, T2 arg2) 
           в System.Management.Automation.Interpreter.DynamicInstruction`4. 
           Run(InterpretedFrame frame) 
           в System.Management.Automation.Interpreter.EnterTryCatchFinallyI 
           nstruction.Run(InterpretedFrame frame) 
WasThrownFromThrowStatement : False 
Message      : Unable to find an overload for "ExecuteStoredProcedureAsync" and a number of arguments: "2". 
Data      : {System.Management.Automation.Interpreter.InterpretedFrameInfo} 
InnerException    : 
TargetSite     : System.Object CallSite.Target(System.Runtime.CompilerServices.Closu 
           re, System.Runtime.CompilerServices.CallSite, System.Object, System 
           .Object, System.String) 
HelpLink     : 
Source      : Anonymously Hosted DynamicMethods Assembly 
HResult      : -2146233087 

为什么?

+0

我不熟悉PowerShell中使用异步.NET包,所以我只有猜测,但会不会是你的CreateStoredProcedure电话还没有结束并且当您调用ExecuteStoredProcedure时,您以$ procedure形式发送空值?你可以通过打印出$ procedure来确认这一点,尽管听起来你可能已经这样做了。 –

回答

1

我怀疑你需要将两个参数传递给$client.ExecuteStoredProcedureAsync()。第一个参数是存储过程的链接,第二个参数是要传入存储过程本身的参数数组。

下面是相应的C#代码:

await client.ExecuteStoredProcedureAsync<bool>("/dbs/db_rid/colls/col_rid/sprocs/sproc_rid/", 
    new Player { id="1", name="joe" } , 
    new Player { id="2", name="john" } 
);