简体   繁体   中英

Accessing SQL Server 2005 with PYODBC

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM