[python-win32] python.exe crashes while connecting to MSSQL Database using pyodbc.connect

Vernon Cole vernondcole at gmail.com
Wed Dec 17 16:45:06 CET 2008


Do you have some special reason for using pyodbc, such as higher
performance?
If not, you might try replacing pyodbc with adodbapi.

import adodbapi
try:
            DBCon = adodbapi.connect("DSN=TestDB;UID=tester;PWD=tester")
except adodbapi.Error, erno:
            mesg = "Unable to connect testDB Database check the UserID and
Password"
            print mesg,erno
            return 1
return 0

adodbapi (using dbapi version 2.0) and odbc (using dbapi version 1.0) are
both included in pywin32. (upgrade your version of pywin32 to get bug fixes
to both packages.)

Tim is also correct about not needing a DSN (unless other code is using it
elsewhere) so you may be able to discard all that.

In your situation, I would try something like:
adodbapi.connect("Provider=sqloledb; Data Source=server; Initial Catalog
=testDB; User Id=tester;Password=tester")

Connection string examples for many other situations can be found at
www.connectionstrings.com


On Wed, Dec 17, 2008 at 7:45 AM, Tim Golden <mail at timgolden.me.uk> wrote:

> siddhartha veedaluru wrote:
>
>> i have created a System DSN in my local machine using python script which
>>> uses ctypes module
>>> using pyodbc module i'm trying to connect to remote database.
>>>
>>> sometimes python.exe crashes in the connect function
>>>
>>
>
> Not answering your question directly but... did you know
> that you don't need to create a DSN just to connect via
> ODBC? This kind of thing will do it just as well:
>
> <code>
>
> import pyodbc
>
> connection = "Driver={SQL
> Server};Server=SVR;Database=DB;TrustedConnection=Yes"
> db = pyodbc.connect (connection)
>
> </code>
>
> TJG
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20081217/f886aa96/attachment.htm>


More information about the python-win32 mailing list