简体   繁体   English

无法将pyODBC与SQL Server 2008 Express R2连接

[英]Unable to connect pyODBC with SQL Server 2008 Express R2

I am using following code to connect with SQL 2008 R2: 我正在使用以下代码与SQL 2008 R2连接:

cnxnStoneedge = pyodbc.connect("DRIVER={SQL Server};SERVER=127.0.0.1;DATABASE=myDB;UID=admin;PWD=admin")

Which gives error: 这给出了错误:

Error: ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. (17) (SQLDriverConnect)')
      args = ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNE...t exist or access denied. (17) (SQLDriverConnect)')
      with_traceback = <built-in method with_traceback of Error object>

I am not sure whether SQL connecting via named Pipes or TCP, I did enable IP Address. 我不确定是通过命名管道还是通过TCP连接SQL,我是否启用了IP地址。 Attaching Screen Shot 附加屏幕截图 在此处输入图片说明

The following test code works for me to connect Python 2.7.5 with SQL Server 2008 R2 Express Edition: 以下测试代码对我有用,以将Python 2.7.5与SQL Server 2008 R2 Express Edition连接:

# -*- coding: utf-8 -*-
import pyodbc

connStr = (
    r'Driver={SQL Server};' +
    r'Server=(local)\SQLEXPRESS;' +
    r'Database=myDb;' +
    r'Trusted_Connection=Yes;'
    )

db = pyodbc.connect(connStr)

cursor1 = db.execute('SELECT [word] FROM [vocabulary] WHERE [ID]=5')

while 1:
    row = cursor1.fetchone()
    if not row:
        break
    print row.word
cursor1.close()
db.close()

and the following connection string also works for me because my \\SQLEXPRESS instance is listening on port 52865: 并且以下连接字符串也对我有用,因为我的\\ SQLEXPRESS实例正在侦听端口52865:

connStr = (
    r'Driver={SQL Server};' +
    r'Server=127.0.0.1,52865;' +
    r'Database=myDb;' +
    r'Trusted_Connection=Yes;'
    )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用pyodbc与sql server 2008 r2连接,SQL Server不存在或访问被拒绝 - connect with sql server 2008 r2 using pyodbc, SQL Server does not exist or access denied 在WIN7上从python3.2和pyodbc在SQL Server 2008 R2上创建表的错误 - error of creating tables on SQL server 2008 R2 from python3.2 and pyodbc on win7 Pyodbc 无法在 SQL Server 2008 中执行 proc - Pyodbc unable to execute proc in SQL Server 2008 使用SQL Server Management Studio 2008 r2和adodbapi设置并连接到本地SQLEXPRESS数据库 - Set up and connect to local SQLEXPRESS database using SQL Server Management Studio 2008 r2 and adodbapi 如何使用 Windows 身份验证使用 pyodbc、to_sql 和 sql server management studio express r2 从工作表 excel 文件中推送数据 - How to push data from sheet excel file using pyodbc, to_sql, and sql server managment studio express r2 using windows authentication 使用PyODBC和SQL Express Server 2008进行备份时,我在做什么? - What's am I doing wrong with this backup using PyODBC and SQL Express Server 2008 PYODBC 无法连接到 SQL Express 实例 - PYODBC can't connect to SQL Express instance 如何在 Python 中使用 pyodbc 通过 IP 地址连接到 sql server 2008 - How to connect to sql server 2008 via an IP address using pyodbc in Python 无法使用 pyodbc 连接到远程 SQL 数据库 - Unable to connect to remote SQL database using pyodbc 无法使用 pyodbc 连接到 Azure SQL Server - Cannot connect to Azure SQL Server using pyodbc
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM