pyodbc - Connection error: Data source name not found

374 views
Skip to first unread message

Orgil

unread,
Jan 30, 2011, 4:33:06 AM1/30/11
to pyodbc
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

rms...@me.com

unread,
Feb 3, 2011, 11:32:23 AM2/3/11
to pyodbc
Orgil,

I have connected successfully using 2.6 and 2.7. It took me quiet a
while to make the connection, but all of the problems I had connecting
were in setting up the ODBC driver. Once I got it setup, the pyodbc
connection was trivial. I am still having other problems with pyodbc
as you can see from my earlier post.

I have inserted the first few lines of some code that I am using to
test database triggers. The DSN was created within "ODBC Manager" on a
Mac OS 10.6.6 box. The DSN, as set up by the ODBC Manager has the
server name, the server address, and the instance name bound to it. I
have connected to several instances of MS SQL Server 2008 on sever
using this approach.

Mark

import pyodbc
from unittest import TestCase, main
from datetime import datetime
class Test(TestCase):

def setUp(self):
conn = pyodbc.connect("DSN=deepthought-animal-
msharp;UID=msharp;PWD=password")
cursor = conn.cursor()

cursor.execute('''
delete from accounts
where account in ('1111-11-11', '2222-22-22',
'3333-33-33',
'4444-44-44') ''')
conn.commit()

rms...@me.com

unread,
Feb 3, 2011, 1:19:32 PM2/3/11
to pyodbc
I do not have any experience with the ODBC system on the Windows side
of things. Is this the ODBC driver that pyodbc uses?
Mark

rms...@me.com

unread,
Feb 3, 2011, 1:23:35 PM2/3/11
to pyodbc
The reason I ask about the ODBC driver is that the error message
mentions 'unixODBC', which does not sound like the System.Data.Odbc
library used by c#.net.

You have to get the ODBC driver that pyodbc uses set up and connecting
before moving to the pyodbc wrapper. This is what I missed doing when
I started.
Reply all
Reply to author
Forward
0 new messages