Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Microsoft Azure数据仓库和SqlAlchemy_Python_Python 2.7_Azure_Sqlalchemy_Data Warehouse - Fatal编程技术网

Python Microsoft Azure数据仓库和SqlAlchemy

Python Microsoft Azure数据仓库和SqlAlchemy,python,python-2.7,azure,sqlalchemy,data-warehouse,Python,Python 2.7,Azure,Sqlalchemy,Data Warehouse,我正在尝试使用python的sqlalchemy库连接到microsoft azure数据仓库。 以及接收到以下错误: (pyodbc.Error) ('HY000', '[HY000] [Microsoft][ODBC SQL Server Driver][SQL Server]Client driver version is not supported. (46722) (SQLDriverConnect); [HY000] [Microsoft][ODBC SQL Server Driv

我正在尝试使用python的sqlalchemy库连接到microsoft azure数据仓库。 以及接收到以下错误:

 (pyodbc.Error) ('HY000', '[HY000] [Microsoft][ODBC SQL Server Driver][SQL Server]Client driver version is not supported. (46722) (SQLDriverConnect); [HY000] [Microsoft][ODBC SQL Server Driver][SQL Server]Client driver version is not supported. (46722)')
我的windows连接代码:

import sqlalchemy
user_name = 'userName'
password = 'password'
uri = 'sqlServerName'
db_name = 'SQLDBName'
db_prefix = 'mssql+pyodbc://'
db_driver = '{SQL Server}'
connection_string = "{db_prefix}{user_name}:{password}@{uri}/{db_name}?Driver={driver}".format(
                db_prefix=db_prefix, user_name=user_name, password=password, uri=uri, db_name=db_name,
                driver=db_driver)
engine = sqlalchemy.engine.create_engine(connection_string, echo=echo, pool_size=20,
                                                          max_overflow=100)
engine.connect()  # throws the error

提前谢谢

根据您的代码,问题似乎是由于使用了不正确的
驱动程序={SQL Server}
造成的

在Azure portal上,您可以通过以下步骤获取连接字符串,如下图所示

正确的odbc驱动程序名称应为
driver={odbc driver 13 for SQL Server}
。同时,请按照安装适合您当前环境的
pyodbc
的正确版本
3.1.1

下面是我的测试代码

import sqlalchemy

connection_string = "mssql+pyodbc://<user>@<server-host>:<password>@<server-host>.database.windows.net:1433/<database>?driver=ODBC+Driver+13+for+SQL+Server"
engine = sqlalchemy.engine.create_engine(connection_string)
engine.connect()
输出:

(u'Microsoft Azure SQL Data Warehouse - 10.0.8529.1 Jan 13 2017 22:49:03 Copyright (c) Microsoft Corporation', )
import pyodbc
cnxn = pyodbc.connect("Driver={ODBC Driver 13 for SQL Server};Server=<server-host>.database.windows.net,1433;Database=<database>;Uid=<user>@<server-host>;Pwd=<password>;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;")
cursor = cnxn.cursor()
cursor.execute("select @@VERSION")
row = cursor.fetchone()
if row:
    print row
(u'Microsoft Azure SQL Data Warehouse - 10.0.8529.1 Jan 13 2017 22:49:03 Copyright (c) Microsoft Corporation', )