简体   繁体   中英

Error 400 when trying to Connect Azure Function App to Azure Cosmos DB Table

I am trying to connect to azure CosmosDB Table from function app.

I am getting the error

The remote server returned an error: (400) Bad Request.

When trying to perform the same connection from the sample c# project in visual studio, it works fine.

Code Snippet:

string connectionString = ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString;           
CloudStorageAccount storageAccount = CreateStorageAccountFromConnectionString(connectionString);

CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
CloudTable table = tableClient.GetTableReference("People");

table.CreateIfNotExists();

The connection string is:

DefaultEndpointsProtocol=https;AccountName=digital-signature-db;AccountKey=XXX==;TableEndpoint= https://digital-signature-db.documents.azure.com

Full error stack:

Exception while executing function: Functions.SignPDF Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception while executing function: Functions.SignPDF ---> System.AggregateException : One or more errors occurred. ---> The remote server returned an error: (400) Bad Request. ---> The remote server returned an error: (400) Bad Request. at Microsoft.Azure.WebJobs.Script.Description.DotNetFunctionInvoker.GetTaskResult(Task task) at C:\\projects\\azure-webjobs-sdk-script\\src\\WebJobs.Script\\Description\\DotNet\\DotNetFunctionInvoker.cs : 453 at Microsoft.Azure.WebJobs.Script.Description.DotNetFunctionInvoker.<>c.b__26_0(Task t) at C:\\projects\\azure-webjobs-sdk-script\\src\\WebJobs.Script\\Description\\DotNet\\DotNetFunctionInvoker.cs : 276 at System.Threading.Tasks.ContinuationResultTaskFromTask 1.InnerInvoke() at System.Threading.Tasks.Task.Execute() at async Microsoft.Azure.WebJobs.Script.Description.DotNetFunctionInvoker.InvokeCore(Object[] parameters,FunctionInvocationContext context) at C:\\projects\\azure-webjobs-sdk-script\\src\\WebJobs.Script\\Description\\DotNet\\DotNetFunctionInvoker.cs : 276 at async Microsoft.Azure.WebJobs.Script.Description.FunctionInvokerBase.Invoke(Object[] parameters) at C:\\projects\\azure-webjobs-sdk-script\\src\\WebJobs.Script\\Description\\FunctionInvokerBase.cs : 90 at async Microsoft.Azure.WebJobs.Host.Executors.VoidTaskMethodInvoker 1.InnerInvoke() at System.Threading.Tasks.Task.Execute() at async Microsoft.Azure.WebJobs.Script.Description.DotNetFunctionInvoker.InvokeCore(Object[] parameters,FunctionInvocationContext context) at C:\\projects\\azure-webjobs-sdk-script\\src\\WebJobs.Script\\Description\\DotNet\\DotNetFunctionInvoker.cs : 276 at async Microsoft.Azure.WebJobs.Script.Description.FunctionInvokerBase.Invoke(Object[] parameters) at C:\\projects\\azure-webjobs-sdk-script\\src\\WebJobs.Script\\Description\\FunctionInvokerBase.cs : 90 at async Microsoft.Azure.WebJobs.Host.Executors.VoidTaskMethodInvoker 2.InvokeAsync[TReflected,TReturnType](TReflected instance,Object[] arguments) at async Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync[TReflected,TReturnValue](Object instance,Object[] arguments) at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeAsync(IFunctionInvoker invoker,ParameterHelper parameterHelper,CancellationTokenSource timeoutTokenSource,CancellationTokenSource functionCancellationTokenSource,Boolean throwOnTimeout,TimeSpan timerInterval,IFunctionInstance instance) at async Microsoft.Azure.WebJobs.Host.Ex…

Please Advice.

The CreateIfNotExists call requires a reference to WindowsAzure.Storage-PremiumTable . When referenced in a console app, it will replace the Microsoft.WindowsAzure.Storage.dll with the version 1.0.9.1 . This is not supported by Azure Functions at this point. Kindly raise an issue with CosmosDB team on this issue. We have an issue tracking this at https://github.com/Azure/azure-webjobs-sdk-script/issues/2026#issuecomment-343910660

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM