Results 1 to 4 of 4

Thread: Urgent : Using ADO To Gain Access To A MS-Access Database.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    NY, USA.
    Posts
    240

    Post

    Is it possible to use ADO To Gain Access To A MS-Access Database on a Web-Site Using VB??
    If so How?

    ------------------
    OmarSwan

    omarswan@yahoo.com

    http://omarswan.da.ru/


    "Jesus is Lord"

  2. #2
    Member
    Join Date
    Aug 1999
    Posts
    52

    Post


    hi,

    ya it is possible to gain access to ms_access using ADO..this is the sample code below where i used disconnected recordset...

    paste this code in any module.............
    Public Function Testrecordset() As ADODB.Recordset
    Dim adors As ADODB.Recordset
    Dim adocn As ADODB.Connection

    Dim strconnection As String

    Set adocn = New ADODB.Connection
    strconnection = "DRIVER=Microsoft Access Driver (*.mdb);dbq=c:\db_library.mdb;"
    adocn.Open strconnection

    Set adors = New ADODB.Recordset
    adors.ActiveConnection = adocn

    adors.CursorLocation = adUseClient
    adors.Open ssql

    If UCase(Trim(Left(ssql, 6))) = "SELECT" Then
    Set adors.ActiveConnection = Nothing
    Set Testrecordset = adors.Clone
    adors.Close
    adocn.Close
    Set adors = Nothing
    Set adocn = Nothing
    Else
    Set Testrecordset = Nothing
    End If
    End Function
    **********
    paste this code in ur form n pass this paramter...declaring ssql as a PUBLIC VARIABLE in the module.....
    ssql = "select * from tbl_book"
    Set adors = Testrecordset

    hope this might help uuu..
    if still any doubts ask meee..

    kandan.

  3. #3
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    that's wonderful if he can access the database like he would if it were on his C drive, but I think he means he wants to break security on an existing site to get to a database, or he wants to use ASP to display information on his own web page with data from a MS Access Db....

    ???

  4. #4
    Guest

    Post

    ...and the easy way:
    (assuming you're using vb)

    option explicit

    dim conYourConnection As ADODB.Connection
    dim recYourRecordSet As ADODB.Recordset
    dim strYourConnectionString As String
    dim strYourSqlStatement As String
    dim strFullPathToDatabase As String


    public sub AdoAccessTest()
    strFullPathToDatabase = "c:\YourAccessDatabaseName.mdb"
    Set conYourConnection = New ADODB.Connection
    conYourConnection.ConnectionString = "{Microsoft Access Driver (*.mdb)};DBQ=" & strFullPathToDatabase
    conYourConnection.Open
    strYourSqlStatement = "SELECT * FROM YourAccessTable"
    Set recYourRecordSet = New ADODB.Recordset
    recYourRecordSet.Source = strYourSqlStatement
    recYourRecordSet.ActiveConnection = conYourConnection
    recYourRecordSet.Open
    if not(recYourRecordSet.bof and recYourRecordSet.eof) then
    do while not recYourRecordSet.eof
    debug.print recYourRecordSet("NameOfAField")
    recYourRecordSet.MoveNext
    loop
    'clean up
    set recYourRecordset = nothing
    set conYourConnection = nothing
    end sub


    keep in mind this is a DSN-less connection. You can use the same thing in ASP, you just need to modify the path. If you're using ASP on another host the relative path to your database might be http://www.yoursite.com/yourdatabase.mdb but the absolute path could be f:\somedirectory\somesubdirectory\someotherdirectory\yourdatabase.mdb
    ...to avoid problems in ASP use the following:

    strFullPathToDatabase = Server.MapPath("http://www.yoursite.com/yourdatabase.mdb")

    ...the full absolute path as it exists on the server will be translated from the url along with the name of the database.

    -good luck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width