使用Python将Azure Bot连接到Azure SQL

问题描述 投票:0回答:1

我正在使用Python中的Azure Bot Framework SDK构建机器人。该机器人需要能够查询SQL数据库,该数据库也托管在Azure上。

但是,当我尝试

async def on_message_activity(self, turn_context: TurnContext):
    cnxn = pyodbc.connect(<connectionstring>)
    self.cursor = cnxn.cursor()
    self.cursor.execute("SELECT * from tableA")
    desc = self.cursor.description

并向机器人发送消息,出现此错误,该错误在机器人的“问题”标签中进行了跟踪:

There was an error sending this message to your bot: HTTP status code ServiceUnavailable

我已使Azure服务能够访问SQL数据库并对连接字符串进行了三重检查。我想念什么吗?这是从机器人查询SQL数据库的正确方法吗?

python sql azure bots
1个回答
0
投票

我最终使用Azure Functions构建REST API进行查询。避免从机器人直接查询,这可能很危险,并且总体上是一种更好,更干净的解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.