Reputation: 1
I'm trying to execute a query in Cosmo DB Mongo API, using the Cdata ODBC through Python. Below is the driver configuration:
[CData ODBC Driver for Cosmos DB]
Description=CData ODBC Driver for Cosmos DB 2019
Driver=/opt/cdata/cdata-odbc-driver-for-cosmosdb/lib/libcosmosdbodbc.x86.so
UsageCount=1
Driver64=/opt/cdata/cdata-odbc-driver-for-cosmosdb/lib/libcosmosdbodbc.x64.so
This is the code I'm using to make the query:
import pyodbc
cnxn = pyodbc.connect("DRIVER={CData ODBC Driver for Cosmos DB};AccountEndpoint=https://[myhost].com:443/;AccountKey=[mypass];")
cursor = cnxn.cursor()
# Find Schemas
cursor.tables()
for (catalog, schema, table, table_type, description) in cursor:
print("Catalog: {}, Schema: {}, Table: {}, Type: {}".format(
catalog, schema, table, table_type
))
# Execute Query
cursor.execute("SELECT luistest from luistest")
rows = cursor.fetchall()
for row in rows:
print(row.luistest)
When I execute it, the query of the tables and schemes returns good, but when I consult the documents I receive the following error:
Catalog: CData, Schema: luis-test, Table: luistest, Type: TABLE
Traceback (most recent call last):
File "mongo_odbc_test.py", line 11, in <module>
cursor.execute("SELECT luistest from luistest")
pyodbc.Error: ('HY000', '[HY000] [Forbidden] Sql api is not supported for this database account\r\nActivityId: 66808c80-83b6-4694-99ac-295693b8f51d, Microsoft.Azure.Documents.Common/2.5.1. (-1) (SQLExecDirectW)')
I have a student Azure account, could this affect? Is it possible to make a query without SQL with this tools?
Thanks.
Upvotes: 0
Views: 4292
Reputation: 15613
This tool seems to be using the SQL API to run SQL Queries. If your Cosmos DB account is using the Mongo API, you should be using tools and drivers that use the Mongo API.
If you are going to use this tool as your main development/use case, I would argue that Mongo API account might not be the correct choice as you have no Mongo requirements, just create a SQL (Core) API account.
Upvotes: 1