473,498 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python adodb

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)

Oct 12 '05 #1
4 6303
gt****@yahoo.com wrote:
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
Oct 13 '05 #2
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

Oct 13 '05 #3
You also might want to take a look at;

http://www.mayukhbose.com/python/ado/index.php

I found it very helpful

LenS

Oct 13 '05 #4
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)

Oct 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
4571
by: Erik Johnson | last post by:
This is somewhat a NEWBIE question... My company maintains a small RDBS driven website. We currently generate HTML using PHP. I've hacked a bit in Python, and generally think it is a rather...
5
9081
by: Giles Brown | last post by:
I'm feeling quite dumb this morning. I'm trying to build a COM server DLL using py2exe and it ain't working. Here's what ain't working... setup_dll.py based on py2exe sample: """from...
1
2299
by: WU FUHENG | last post by:
Today,I found a strange problem in python multi-thread programming.When I used function win32com.client.Dispatch('ADODB.Connection') in primary thread, it was OK. But when I called it in...
0
1501
by: warren ali | last post by:
Hi all! I'm new to python and I seem to have a hit a of a brick wall. I hope you guys can help. I'm trying to rewrite some of my vbscripts in python. This particular script connects to a...
0
1240
by: Tim Roberts | last post by:
It looks to me like the handling of the currency type in an ADODB connecction from Python is broken. Currency data in an Access database is stored as a 64-bit integer, scaled by 10000. In an...
4
1724
by: Dan | last post by:
I need to register for a COM callback under Windows. I am using an ADO recordset interface like this: import win32com.client import time connect = win32com.client.Dispatch("ADODB.Connection")...
4
2664
by: Finger.Octopus | last post by:
Hi I wanted to connect Python to Ms-Access database using ADO or ODBC. I have Python 2.5 and on mxODBC site, it has no higher version build than 2.4. Moreoever, mxODBC is required for ADODB....
2
2105
by: bg_ie | last post by:
Hi, I have an sql server from which I'd like to read and write to. The connection string is as follows - "Data Source=localhost\SQLExpress;Initial Catalog=Test;Integrated...
4
2432
by: goldtech | last post by:
Hi, Given an MS-Access table with a date type field with a value of: 12:00:00 AM - just"12:00:00 AM", there's nothing else in the field. I want to print exactly what's in the field, ie....
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7165
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5462
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4910
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4590
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1419
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
291
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.