未找到数据源名称,并且在Azure Runbook中未指定默认驱动程序 [英] Data source name not found and no default driver specified in Azure Runbook

查看:27
本文介绍了未找到数据源名称,并且在Azure Runbook中未指定默认驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在Azure Automation Runbook中运行此代码,但始终收到相同的错误

cnxn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT='+port+';
DATABASE='+database+';UID='+username+';PWD='+password+';Authentication=ActiveDirectoryPassword')

错误:

pyodbc.InterfaceError: ('IM002', u'[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

推荐答案

如果要使用pyodbc模块连接Azure SQL数据库,运行环境应安装Microsoft ODBC Driver for SQL Server。如果它没有驱动程序,您将收到错误消息。更多详情请参考document。但Azure自动化沙箱没有该驱动程序。

根据情况,我建议您将脚本托管在Azure函数上。

例如(我在Azure HTTP触发器函数上托管脚本)

我的代码


async def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    
    server = 'jimtestsql.database.windows.net'
    database = 'test'
    username = 'jim@hanxia.onmicrosoft.com'
    password = 'Wdsr199545#'
    driver= '{ODBC Driver 17 for SQL Server}'
    cnxn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT=1433;DATABASE='+database+';UID='+username+';PWD='+ password+';Authentication=ActiveDirectoryPassword')
    cursor = cnxn.cursor()
    cursor.execute("SELECT Top(1) * FROM [dbo].[StarWars]")
    row = cursor.fetchone()

    return func.HttpResponse(str(row[0]) + " " + str(row[1]))

这篇关于未找到数据源名称,并且在Azure Runbook中未指定默认驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆