未找到 ODBC 数据源
我正在尝试通过 Sqlalchemy 和 Python 3.6.2 从 Windows Server 2016(安装了适用于 SQL Server 的 ODBC 驱动程序 17)连接到 Windows SQL Server。 如所述 这里我在Odbc数据源管理器中创建了一个数据源
我无法使用 pyodbc,但我可以使用它连接并运行查询。 我还可以从 Windows Server 连接到数据库并使用 SQL Server Management Studio 运行查询。
我正在尝试什么:
sqlalchemy.create_engine('mssql+pyodbc://DB_INSTANCE_ADDRESS/DB_NAME?driver=ODBC_DATA_SOURCE?Trusted_Connection=yes')
我已经得到什么:
Traceback (most recent call last):
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\base.py", line 3250, in _wrap_pool_connect
return fn()
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 310, in connect
return _ConnectionFairy._checkout(self)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 868, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 476, in checkout
rec = pool._do_get()
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\impl.py", line 146, in _do_get
self._dec_overflow()
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\util\langhelpers.py", line 72, in __exit__
with_traceback=exc_tb,
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\util\compat.py", line 207, in raise_
raise exception
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\impl.py", line 143, in _do_get
return self._create_connection()
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 256, in _create_connection
return _ConnectionRecord(self)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 371, in __init__
self.__connect()
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 666, in __connect
pool.logger.debug("Error on connect(): %s", e)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\util\langhelpers.py", line 72, in __exit__
with_traceback=exc_tb,
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\util\compat.py", line 207, in raise_
raise exception
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 661, in __connect
self.dbapi_connection = connection = pool._invoke_creator(self)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\create.py", line 590, in connect
return dialect.connect(*cargs, **cparams)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\default.py", line 597, in connect
return self.dbapi.connect(*cargs, **cparams)
pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 2, in table_names
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\util\deprecations.py", line 401, in warned
return fn(*args, **kwargs)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\base.py", line 3220, in table_names
with self._optional_conn_ctx_manager(connection) as conn:
File "C:\Users\Public\Documents\Python\Python36\lib\contextlib.py", line 81, in __enter__
return next(self.gen)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\base.py", line 2972, in _optional_conn_ctx_manager
with self.connect() as conn:
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\base.py", line 3204, in connect
return self._connection_cls(self, close_with_result=close_with_result)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\base.py", line 96, in __init__
else engine.raw_connection()
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\base.py", line 3283, in raw_connection
return self._wrap_pool_connect(self.pool.connect, _connection)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\base.py", line 3254, in _wrap_pool_connect
e, dialect, self
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\base.py", line 2101, in _handle_dbapi_exception_noconnection
sqlalchemy_exception, with_traceback=exc_info[2], from_=e
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\util\compat.py", line 207, in raise_
raise exception
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\base.py", line 3250, in _wrap_pool_connect
return fn()
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 310, in connect
return _ConnectionFairy._checkout(self)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 868, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 476, in checkout
rec = pool._do_get()
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\impl.py", line 146, in _do_get
self._dec_overflow()
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\util\langhelpers.py", line 72, in __exit__
with_traceback=exc_tb,
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\util\compat.py", line 207, in raise_
raise exception
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\impl.py", line 143, in _do_get
return self._create_connection()
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 256, in _create_connection
return _ConnectionRecord(self)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 371, in __init__
self.__connect()
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 666, in __connect
pool.logger.debug("Error on connect(): %s", e)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\util\langhelpers.py", line 72, in __exit__
with_traceback=exc_tb,
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\util\compat.py", line 207, in raise_
raise exception
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 661, in __connect
self.dbapi_connection = connection = pool._invoke_creator(self)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\create.py", line 590, in connect
return dialect.connect(*cargs, **cparams)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\default.py", line 597, in connect
return self.dbapi.connect(*cargs, **cparams)
sqlalchemy.exc.InterfaceError: (pyodbc.InterfaceError) ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
(Background on this error at: https://sqlalche.me/e/14/rvf5)
I'm trying to connect to a Windows SQL Server from a Windows Server 2016 (with ODBC Driver 17 for SQL Server installed) through Sqlalchemy and Python 3.6.2.
As stated here I created a data source in the Odbc Data Source Administrator
I cannot use pyodbc but I'm able to connect and run queries using it.
I'm also able to connect to the database and run queries using SQL Server Management Studio from the Windows Server.
What I'm trying:
sqlalchemy.create_engine('mssql+pyodbc://DB_INSTANCE_ADDRESS/DB_NAME?driver=ODBC_DATA_SOURCE?Trusted_Connection=yes')
What I've got:
Traceback (most recent call last):
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\base.py", line 3250, in _wrap_pool_connect
return fn()
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 310, in connect
return _ConnectionFairy._checkout(self)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 868, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 476, in checkout
rec = pool._do_get()
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\impl.py", line 146, in _do_get
self._dec_overflow()
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\util\langhelpers.py", line 72, in __exit__
with_traceback=exc_tb,
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\util\compat.py", line 207, in raise_
raise exception
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\impl.py", line 143, in _do_get
return self._create_connection()
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 256, in _create_connection
return _ConnectionRecord(self)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 371, in __init__
self.__connect()
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 666, in __connect
pool.logger.debug("Error on connect(): %s", e)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\util\langhelpers.py", line 72, in __exit__
with_traceback=exc_tb,
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\util\compat.py", line 207, in raise_
raise exception
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 661, in __connect
self.dbapi_connection = connection = pool._invoke_creator(self)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\create.py", line 590, in connect
return dialect.connect(*cargs, **cparams)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\default.py", line 597, in connect
return self.dbapi.connect(*cargs, **cparams)
pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 2, in table_names
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\util\deprecations.py", line 401, in warned
return fn(*args, **kwargs)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\base.py", line 3220, in table_names
with self._optional_conn_ctx_manager(connection) as conn:
File "C:\Users\Public\Documents\Python\Python36\lib\contextlib.py", line 81, in __enter__
return next(self.gen)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\base.py", line 2972, in _optional_conn_ctx_manager
with self.connect() as conn:
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\base.py", line 3204, in connect
return self._connection_cls(self, close_with_result=close_with_result)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\base.py", line 96, in __init__
else engine.raw_connection()
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\base.py", line 3283, in raw_connection
return self._wrap_pool_connect(self.pool.connect, _connection)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\base.py", line 3254, in _wrap_pool_connect
e, dialect, self
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\base.py", line 2101, in _handle_dbapi_exception_noconnection
sqlalchemy_exception, with_traceback=exc_info[2], from_=e
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\util\compat.py", line 207, in raise_
raise exception
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\base.py", line 3250, in _wrap_pool_connect
return fn()
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 310, in connect
return _ConnectionFairy._checkout(self)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 868, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 476, in checkout
rec = pool._do_get()
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\impl.py", line 146, in _do_get
self._dec_overflow()
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\util\langhelpers.py", line 72, in __exit__
with_traceback=exc_tb,
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\util\compat.py", line 207, in raise_
raise exception
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\impl.py", line 143, in _do_get
return self._create_connection()
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 256, in _create_connection
return _ConnectionRecord(self)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 371, in __init__
self.__connect()
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 666, in __connect
pool.logger.debug("Error on connect(): %s", e)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\util\langhelpers.py", line 72, in __exit__
with_traceback=exc_tb,
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\util\compat.py", line 207, in raise_
raise exception
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\pool\base.py", line 661, in __connect
self.dbapi_connection = connection = pool._invoke_creator(self)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\create.py", line 590, in connect
return dialect.connect(*cargs, **cparams)
File "C:\Users\Public\Documents\Python\Python36\lib\site-packages\sqlalchemy\engine\default.py", line 597, in connect
return self.dbapi.connect(*cargs, **cparams)
sqlalchemy.exc.InterfaceError: (pyodbc.InterfaceError) ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
(Background on this error at: https://sqlalche.me/e/14/rvf5)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论