question

AnkitKumar-6861 avatar image
0 Votes"
AnkitKumar-6861 asked KalyanChanumolu-MSFT commented

Unable to call Cosmos db table in the azure function

Below is the code where I am trying to get the Cosmos Db table Api to do some manipulation. code is triggered in an Azure Function . I am not sure what is wrong but it gives the error "Microsoft.Azure.WebJobs.Host: Can't bind CosmosDB to type 'Microsoft.Azure.Cosmos.Table.CloudTableClient'"

Here is my code:

 public static async void Run([ServiceBusTrigger("SB-events", "SB-tabulardata-processor", Connection = "AzureServiceBusString")] string mySbMsg,            
         [CosmosDB(
     databaseName: "TablesDB",
     collectionName: "tablename",
     ConnectionStringSetting = "CosmosDBTableConnection")] Microsoft.Azure.Cosmos.Table.CloudTableClient table,
                     ILogger log)
     {
            
         try {
             log.LogInformation($"{mySbmsg}");
         Microsoft.Azure.Cosmos.Table.CloudTable table1 = table.GetTableReference("tablename");
             if (await table1.CreateIfNotExistsAsync())
             {
                 log.LogInformation("Created Table named");
             }
             else
             {
                 log.LogInformation("Table already exists");
             }....

If someone can tell me what wrong am I doing??

azure-functionsazure-cosmos-db
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

KalyanChanumolu-MSFT avatar image
0 Votes"
KalyanChanumolu-MSFT answered KalyanChanumolu-MSFT edited

@AnkitKumar-6861, Azure Cosmos DB bindings are only supported for use with the SQL API. For all other Azure Cosmos DB APIs, you should access the database from your function by using the static client for your API, including Azure Cosmos DB's API for MongoDB, Cassandra API, Gremlin API, and Table API

I see that you have added the Microsoft.Azure.Cosmos.Table SDK already.
You will need to read the table connection from appsettings and create an instance of the Table client using the connection string.

Please let me know if you face any issues.



If an answer is helpful, please "Accept answer" or "Up-Vote" for the same which might be beneficial to other community members reading this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.