pyodbc: Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnectW)')

7,294 views
Skip to first unread message

Orgil

unread,
Jan 30, 2011, 4:31:23 AM1/30/11
to Django users
Hello,
I have pyodbc-2.1.8 and python-2.6 on ubuntu-10.4.
I tried to connect to MSSQL2008 database server which is on windows7.
My code is below:
-----------------------
import pyodbc
conn = pyodbc.connect('DRIVER={SQL Server};SERVER=testserver
\mssql2008;DATABASE=eoffice;UID=erp;PWD=123')
-----------------------
When I run this code, the following error occurs:
Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name
not found, and no default driver specified (0) (SQLDriverConnectW)')

I tested the connection string using System.Data.Odbc library on
c#.net. It was fine.
I have no idea to solve my problem because of so general error
message.

Please share your experience!

regards,
Orgil

Adrian Bool

unread,
Jan 30, 2011, 4:41:17 AM1/30/11
to django...@googlegroups.com

On 30 Jan 2011, at 09:31, Orgil wrote:

> My code is below:
> -----------------------
> import pyodbc
> conn = pyodbc.connect('DRIVER={SQL Server};SERVER=testserver
> \mssql2008;DATABASE=eoffice;UID=erp;PWD=123')
> -----------------------

I'd try replacing 'testserver\mssql2008' with a domain name that your ubuntu box can ping - or the IP address of the Windows 7 box.

Regards,

aid

David

unread,
Jan 30, 2011, 11:06:54 AM1/30/11
to Django users
As far as I know, the only way to connect to MSSql using pyodbc on
Linux is to use FreeTDS.

conn = pyodbc.connect(r"DRIVER={FreeTDS};SERVER=testserver
\mssql2008;DATABASE=eoffice;UID=erp;PWD=123")

The "SQL Server" driver is a Windows driver and the above connection
string might work on the same Windows machine that you used to test
the C#.NET connection. Also, if you're putting a backslash in a
string, it either needs to be a raw string or needs to be escaped. I
assume that since you posted this to the Django list that you intend
to use it with django-pyodbc.

Orgil

unread,
Jan 30, 2011, 11:33:27 PM1/30/11
to Django users
> conn = pyodbc.connect(r"DRIVER={FreeTDS};SERVER=testserver
> \mssql2008;DATABASE=eoffice;UID=erp;PWD=123")

Thanks for your reply, David!
You gave me great advice!
As you suggest, now I my connection is fine!
But there is one another problem occurred!
When I run the Select query, result is non unicode data while select
query reads nvarchar column from mssql database. My code is below:
------------------
import pyodbc
conn = pyodbc.connect(r'DRIVER={FreeTDS};SERVER=testserver
\mssql2008;DATABASE=eoffice;UID=erp;PWD=123;')
crms = conn.cursor()
crms.execute('SELECT cc_Name FROM tblHR_CodeClass')
for line in crms:
print 'cc_Name: %s' % (line.cc_Name)
break
conn.close()
------------------
Result is 'cc_Name: ?????, ???'. But I expected the result would be
'cc_Name: Aймаг, хот' because actual data is 'Aймаг, хот'.

Here is my question: Does the pyodbc library support Unicode?

regards,
Orgil
Reply all
Reply to author
Forward
0 new messages