Unable to Execute procedure with multiple parameters

久未见 提交于 2020-01-17 06:53:56

问题


i am trying to work with Azure's DocumentDb to validate the user credentials for login but i am not able to get the proper result.

Some Points: 1. this is a partitioned collection and i am passing the partition key. 2. i am passing an array as parameter.

Here is my Code for calling the procedure:

response = await client.ExecuteStoredProcedureAsync<string>(storedProcedurelink, new RequestOptions { PartitionKey = new PartitionKey(partitionKey) }, new dynamic[]{param});

and here is my code for the procedure:

function sample(param) {
var collection = getContext().getCollection();
var query = 'SELECT * FROM c where c.logindata.email="'+param[0]+'" and c.logindata.password="'+param[1]+'" and c.userid>0';
// Query documents and take 1st item.
var isAccepted = collection.queryDocuments(
    collection.getSelfLink(),
    query,
    function (err, feed, options) {
if (err) throw err;
if (!feed || !feed.length) getContext().getResponse().setBody('no docs found');
else getContext().getResponse().setBody(JSON.stringify(feed));

});
if (!isAccepted) throw new Error('The query was not accepted by the server.');
}

I am able to execute the query in the query explorer and get the proper result but when i call the procedure it always gives no docs found. I don't know what i am doing wrong, can someone point me in right direction.


回答1:


I don't know what i am doing wrong.

As param[0] and param[1] can't get the expeted result in store procedure.We can test it from the Azure portal.

can someone point me in right direction.

Please have a try to use 2 paramters in your case.

function sample(email,password) {
var collection = getContext().getCollection();
var query = 'SELECT * FROM c where c.logindata.email="'+email+'" and c.logindata.password="'+password+'" and c.userid>0';
// Query documents and take 1st item.
var isAccepted = collection.queryDocuments(
    collection.getSelfLink(),
    query,
    function (err, feed, options) {
if (err) throw err;
if (!feed || !feed.length) getContext().getResponse().setBody('no docs found');
else getContext().getResponse().setBody(JSON.stringify(feed));

});
if (!isAccepted) throw new Error('The query was not accepted by the server.');
}

And make sure that we can get the expected result from Azure Portal script exploer.

In the C# code

      var user = "xxxxx";
      var password = "xxxx";
      var response = await client.ExecuteStoredProcedureAsync<string>(storedProcedurelink, new RequestOptions { PartitionKey = new PartitionKey(partitionKey) },user,password);



来源:https://stackoverflow.com/questions/43821301/unable-to-execute-procedure-with-multiple-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!