Unable to call Cosmos db table in the azure function

Ankit Kumar 91 Reputation points
2020-10-19T14:07:48.217+00:00

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 Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,212 questions
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,437 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. KalyanChanumolu-MSFT 8,316 Reputation points
    2020-10-20T15:33:54.68+00:00

    @Ankit Kumar , 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.

    0 comments No comments