1
votes

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.ContinuationResultTaskFromTask1.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.VoidTaskMethodInvoker2.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.

1
Do you connect locally the same database?Mikhail Shilkov
Looks like this is an issue only in functions portal. Just tried a sample in azure functions using timer trigger to connect to cosmos db which uses Table API.Baskar Rao
@Mikhail - Yes, I am connection to the exact same database. That why it's weird and looks like app function issue.Igor Po
@Baskar - have you received the same error?Igor Po
Yes it is function portal issue. Just tested. Was able to find the following issue in github. github.com/Azure-Samples/…Baskar Rao

1 Answers

0
votes

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