Reputation: 171
I build an application to do some number crunching with wxpython. I have to access the data from SQL Server 2005 for my purpose. I am using PYODBC and when I asked my server adminstrator, he provided me the server name and unique data ID for the database.
I don't see the syntax to access database with unique data ID in PYODBC as something like:
Conn=pyodbc.connect('DRIVER={SQL Server};SERVER=USMDUBEDAS215;DATABASE=spam;UID=usr,PWD=pwd')
when you have a database and table name. How can you access the database with server-name and Data_ID?
I don't know from where to start.
Upvotes: 1
Views: 2738
Reputation: 29103
Try to look at the following link: http://code.google.com/p/pyodbc/wiki/GettingStarted
Link to connect method: http://code.google.com/p/pyodbc/wiki/Module#connect
Using the link above you can find the following sample code:
#Make a direct connection to a database and create a cursor.
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=localhost;DATABASE=testdb;UID=me;PWD=pass')
cursor = cnxn.cursor()
cursor.execute("select user_id, user_name from users")
row = cursor.fetchone()
print 'name:', row[1] # access by column index
print 'name:', row.user_name # or access by name
I have tried it in our env and all works as expected
Upvotes: 2