0

I am using python 3.3 + pypyodbc. When I try:

connection = pypyodbc.connect("DRIVER{SQLServer};
                               SERVER=serverIP;
                               UID=myid;
                               PWD=mypwd;
                               DATABASE=mydb")

I get an error:

pypyodbc.DatabaseError: ('08001', '[08001] 
                                   [Microsoft]
                                   [ODBC SQL Server Driver]
                                   [DBNETLIB]Invalid connection.')

I know the IP and credentials are correct, I use them every day to query server using Microsoft SQL Server Management Studio Express. What am I missing here?

Thanks.

4

3 回答 3

3

尝试这样的事情......

import pypyodbc

connection_string ='Driver={SQL Server Native Client 11.0};Server=YOURSERVER;Database=YOURDATABASE;Uid=YOURUSER;Pwd=YOURPASSWORD;'

connection = pypyodbc.connect(connection_string)

SQL = 'SELECT * FROM <YOURTABLE>'

cur = connection.cursor()
cur.execute(SQL)

cur.close()
connection.close()
于 2014-02-28T22:19:01.790 回答
1

尝试这样的事情

import pypyodbc
conn = pypyodbc.connect(driver='{SQL Server}', server='servername', database='dbname', uid='userName', pwd='Password')

使用您的凭据更改服务器名称和其他值。它非常适合我。如果您使用的是 azure sql 服务器,请确保将您的 IP 添加到防火墙规则中。

于 2016-09-15T07:49:42.597 回答
-2

连接字符串不正确,谷歌求正确的sqlserver的ODBC连接字符串

于 2014-02-19T11:39:38.890 回答