Python adodb

Discussion in 'Python' started by gt_mac@yahoo.com, Oct 13, 2005.

  1. Guest

    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 13, 2005
    #1
    1. Advertising

  2. Kent Johnson Guest

    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
    Kent Johnson, Oct 13, 2005
    #2
    1. Advertising

  3. LenS Guest

    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
    LenS, Oct 13, 2005
    #3
  4. LenS Guest

    LenS, Oct 13, 2005
    #4
  5. gt182 Guest

    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)
    gt182, Oct 13, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vikas Yadav
    Replies:
    0
    Views:
    1,118
    Vikas Yadav
    Sep 9, 2003
  2. Jim Lacenski
    Replies:
    1
    Views:
    2,763
    Natty Gur
    Oct 18, 2003
  3. PJ
    Replies:
    1
    Views:
    1,786
    George Ter-Saakov
    Oct 30, 2003
  4. Tim Roberts
    Replies:
    0
    Views:
    420
    Tim Roberts
    Apr 27, 2005
  5. Mladen Gogala

    ADOdb for Python

    Mladen Gogala, Jun 25, 2010, in forum: Python
    Replies:
    0
    Views:
    316
    Mladen Gogala
    Jun 25, 2010
Loading...

Share This Page