Python adodb

G

gt_mac

In trying to use the adodb module, I have had good success. However I
need to access a database with a username and password at this time.
And cannot find a way to do it without using a ODBC or other older
techniques. Can someone help me with this, below is the code I am
currently attempting to use. I am just not sure where to place the
username and password information or how to pull this from a text file.

import mx.ODBC.Windows
import adodb
import win32com.client

con = win32com.client.Dispatch(r'ADODB.Connection')
DSN = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:/test.mdb;'
con.Open(DSN)
rs = win32com.client.Dispatch(r'ADODB.Recordset')
rs_name = 'testtbl'
rs.Open("SELECT * FROM testtbl", con)
 
K

Kent Johnson

In trying to use the adodb module, I have had good success. However I
need to access a database with a username and password at this time.

I have used a connection string like this to connect to MS SQL Server from adodb:
connStrSQLServer = r"Provider=SQLOLEDB.1; User ID=user; Password=passwd;Initial Catalog=Northwind;Data Source=(local)"

HTH
Kent
 
L

LenS

I have used the following code in ADO:

# The following code creates a connection object,
# assigns the connection string, opens the
# connection object, and then verifies a good
# connection.

oConn = Dispatch('ADODB.Connection')

oConn.ConnectionString = "Provider=SQLOLEDB.1;" +\
"Data Source=servername;" +\
"uid=loginid;" +\
"pwd=password;" +\
"database=databasename"

oConn.Open()
if oConn.State == adStateOpen:
print "Database connection SUCCEEDED"
else:
print "Database connection FAILED"

Hope this helps
 
G

gt182

Thank you everyone for your posts. Listed below is the correct code,
solution reached. And to include the username and password you can
simply inter it behind Persist Security devieded off with semicolons.







con = win32com.client.Dispatch(r'ADODB.Connection')
DSN = r'Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\test.mdb;Mode=ReadWrite;Persist Security Info=False'
con.Open(DSN)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top