사용자 도구

사이트 도구


kb:pythonado

Python ADO

http://adodbapi.sourceforge.net/

여러 가지 모듈 찾아봤는데, 그나마 제일 깔끔하게 설치된 모듈. 유닛 테스트 실패하던데… -_-

Connection String

Access

data_source = "C:\Program Files\Microsoft Office\Office\Samples\northwind.mdb;"
conn_str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + data_source

SqlServer + Non-trusted Connection

computer_name="(local)"
database_name="Northwind"
conn_str = "Provider=SQLOLEDB.1; User ID=sa; Initial Catalog=%s;Data Source=%s" %(database_name, computer_name)

SqlServer + Trusted-Connection

computer_name = "(local)"
database_name = "AdventureWorks"
conn_str = "Provider=SQLOLEDB.1;Initial Catalog=%s;Data Source=%s;Trusted_Connection=Yes" %(database_name, computer_name)

Sample Code

SqlServer + Trusted connection

import win32com.client
import adodbapi
 
computer_name = "(local)"
database_name = "AdventureWorks"
conn_str = "Provider=SQLOLEDB.1;Initial Catalog=%s;Data Source=%s;Trusted_Connection=Yes" %(database_name, computer_name)
 
conn = adodbapi.connect(conn_str)
cursor = conn.cursor()
 
cursor.execute("SELECT AddressID, City FROM Person.Address")
while 1:
    result = cursor.fetchone()
    if result == None: 
        break
 
    print(result[0])
 
conn.close()

kb/pythonado.txt · 마지막으로 수정됨: 2014/11/10 19:26 저자 excel96