Reputation: 1
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.
Upvotes: 0
Views: 10254
Reputation: 1248
Try something like this
import pypyodbc
conn = pypyodbc.connect(driver='{SQL Server}', server='servername', database='dbname', uid='userName', pwd='Password')
Change the servername and other values with your credentials. It Works perfectly for me. If you are using an azure sql server, make sure you add your IP to the firewall rules.
Upvotes: 1
Reputation: 216
try something like this...
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()
Upvotes: 3
Reputation: 1139
The connection string is not correct, Google for a correct sqlserver's ODBC connection string
Upvotes: -2