DocumentDB存储过程错误

时间:2015-11-20 08:27:17

标签: c# powershell azure-cosmosdb

您好我需要将PowerShell与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 = / sprocs / 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

为什么?

1 个答案:

答案 0 :(得分: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" } 
);