Connecting to SQL Server using pypyodbc

I need to send Unicode to SQL Server using Python 2.7. I failed with pymssql . Now I'm trying to get pypyodbc to work (unlike pyodbc ), as it gives working Unicode examples . The problem is that the connection string in the example is not like anything I recognize. I looked over this one , and after a little trial and error I built this line:

 conn = pypyodbc.connect("DRIVER={SQL Server};SERVER='MyServer';UID='me';PWD='MyPassword';DATABASE='db'") 

Return a DatabaseError focused on the connection string:

 C:\Anaconda\lib\site-packages\pypyodbc.pyc in __init__(self, connectString, autocommit, ansi, timeout, unicode_results, readonly, **kargs) ---> 2 conn = pypyodbc.connect("DRIVER={SQL Server};SERVER='MyServer';UID='me';PWD='password';DATABASE='db'") C:\Anaconda\lib\site-packages\pypyodbc.pyc in __init__(self, connectString, autocommit, ansi, timeout, unicode_results, readonly, **kargs) ---> 2273 self.connect(connectString, autocommit, ansi, timeout, unicode_results, readonly) C:\Anaconda\lib\site-packages\pypyodbc.pyc in connect(self, connectString, autocommit, ansi, timeout, unicode_results, readonly) ---> 2321 check_success(self, ret) C:\Anaconda\lib\site-packages\pypyodbc.pyc in ctrl_err(ht, h, val_ret, ansi) ---> 919 raise DatabaseError(state,err_text) DatabaseError: (u'08001', u'[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.') 

I know that my credentials are correct because I used them to successfully connect using pymssql. What am I missing?

+8
sql-server pyodbc pypyodbc
source share
2 answers

Remove single quotes from the server , uid , pwd and database attributes of the connection string:

 conn = pypyodbc.connect("DRIVER={SQL Server};SERVER=MyServer;UID=me;PWD=password;DATABASE=db") 

Since pypyodbc mentions pypyodbc compatibility, take a moment to look at the pyodbc connection docs and pyodbc.connect () . I use this syntax in pyobbc:

 cnxn = connect(driver='{SQL Server}', server='localhost', database='test', uid='me', pwd='me2') 
+15
source share

Leaving the port number (1433) in the connection string, I threw errors at it from the Linux client (but not on Windows 7). This is probably a configuration issue, but I did not have time to pursue it.

Put it there, in case it helps someone else.

+2
source share

All Articles