Sql api is not supported for this database Error

假如想象 提交于 2020-01-16 09:11:32

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/58126046/sql-api-is-not-supported-for-this-database-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!