Python adodb

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gt_mac@yahoo.com

    #1

    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'ADO DB.Connection')
    DSN = 'Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=c:/test.mdb;'
    con.Open(DSN)
    rs = win32com.client .Dispatch(r'ADO DB.Recordset')
    rs_name = 'testtbl'
    rs.Open("SELECT * FROM testtbl", con)

  • Kent Johnson

    #2
    Re: Python adodb

    gt_mac@yahoo.co m wrote:[color=blue]
    > 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.[/color]

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

    HTH
    Kent

    Comment

    • LenS

      #3
      Re: Python adodb

      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.Connectio nString = "Provider=SQLOL EDB.1;" +\
      "Data Source=serverna me;" +\
      "uid=logini d;" +\
      "pwd=passwo rd;" +\
      "database=datab asename"

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

      Hope this helps

      Comment

      • LenS

        #4
        Re: Python adodb

        You also might want to take a look at;



        I found it very helpful

        LenS

        Comment

        • gt182

          #5
          Re: Python adodb

          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'ADO DB.Connection')
          DSN = r'Provider=Micr osoft.Jet.OLEDB .4.0;Data
          Source=C:\test. mdb;Mode=ReadWr ite;Persist Security Info=False'
          con.Open(DSN)

          Comment

          Working...