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

siddhartha veedaluru siddhartha.veedaluru at gmail.com
Wed Dec 17 15:23:19 CET 2008


Hi,

> Summary-:  python.exe crashes while connecting to the MSSQL Database on
> remote machine using pyodbc module
> OS-: win 2003 server, 32bit
> Installed python products: python 2.5,pyodbc-2.0.52,pywin32-211
>
> Problem Description & Steps followed:
> i have MSSQL Database on a remote machine
> 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
>
> if i reboot the machine, i can connect it,but next try to connect crashes
> python.exe
>
> **Following is the code snippet of my script that are used to do the above
> tasks
>
> Script to Create a System DSN
> ----------------------------------------------
> def create_sys_dsn(driver, **kw):
>     "Create a  system DSN"
>     ODBC_ADD_SYS_DSN = 4
>     nul = chr(0)
>     attributes = []
>     for attr in kw.keys():
>         atrbStr = "%s=%s" % (attr, kw[attr])
>         #print atrbStr
>         attributes.append(atrbStr)
>     #print driver
>     return ctypes.windll.ODBCCP32.SQLConfigDataSource(0, ODBC_ADD_SYS_DSN,
> driver, nul.join(attributes))
>
> retCode = create_sys_dsn("SQL Server", SERVER=server, DESCRIPTION="TestDB
> DSN", DSN="TestDB", Database="testDB")
> if retCode != 1:
>     mesg = "Cannot Create TestDB DSN"
>     print mesg
>     sys.exit(1)
> else:
>     mesg = "TestDB DSN Created"
>     print mesg
>     sys.exit(0)
> ---------------------------------------------------------------------------
>
> Script to connect to database
> ---------------------------------------------------------------------------
> import pyodbc
> try:
>             DBCon = pyodbc.connect("DSN=TestDB;UID=tester;PWD=tester")
> except pyodbc.Error, erno:
>             mesg = "Unable to connect testDB Database check the UserID and
> Password"
>             print mesg,erno
>             return 1
> return 0
> :
> :
> :
> :
> DBCon.close()
>
> Please Help me out
> take a look or forward to concerned developers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20081217/8ceb29b9/attachment.htm>


More information about the python-win32 mailing list