Results 1 to 10 of 10

Thread: VB6 MDB-RemoteAccess via http(s)

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,207

    VB6 MDB-RemoteAccess via http(s)

    Just a small Demo, which shows how to setup these kind of remote-services and -requests in as simple a manner as possible, using:
    - a small WebServer of course, to get serverside http-protocol-support (here, cWebServer from the vbRichClient5-lib is used)
    - a clientside http-COMponent (here, the MS-WinHttp-5.1 Object will be used)
    - a transport-container-Object, which can be serialized to and from ByteArrays (we talk about ADODB.Recordsets here)
    - and finally a simple RPC-call-scheme, which describes the serverside MDB-File in the http-URL - and the SQL-Select-String in the http-Body
    ..(then always returning an ADODB.Recordset, also in case of any Server- or Clientside Error)

    All this is packed into a quite small CodeBase, which should be easy enough to study+understand.
    Later "upgrading" to a "larger WebServer" (e.g. the MS-Internet-Information-Server, aka "IIS") can be done without much fuss,
    e.g. from what I've already described here: https://www.vbforums.com/showthread....g-of-http-RPCs

    The App looks this way:


    And the Project-Source-Code is here:
    MDBServer.zip

    HTH

    Olaf

  2. #2
    Banned
    Join Date
    May 2020
    Location
    https://t.me/pump_upp
    Posts
    42

    Re: VB6 MDB-RemoteAccess via http(s)

    Quote Originally Posted by Schmidt View Post
    Just a small Demo, which shows how to setup these kind of remote-services and -requests in as simple a manner as possible, using:
    - a small WebServer of course, to get serverside http-protocol-support (here, cWebServer from the vbRichClient5-lib is used)
    - a clientside http-COMponent (here, the MS-WinHttp-5.1 Object will be used)
    - a transport-container-Object, which can be serialized to and from ByteArrays (we talk about ADODB.Recordsets here)
    - and finally a simple RPC-call-scheme, which describes the serverside MDB-File in the http-URL - and the SQL-Select-String in the http-Body
    ..(then always returning an ADODB.Recordset, also in case of any Server- or Clientside Error)

    All this is packed into a quite small CodeBase, which should be easy enough to study+understand.
    Later "upgrading" to a "larger WebServer" (e.g. the MS-Internet-Information-Server, aka "IIS") can be done without much fuss,
    e.g. from what I've already described here: https://www.vbforums.com/showthread....g-of-http-RPCs

    The App looks this way:


    And the Project-Source-Code is here:
    MDBServer.zip

    HTH

    Olaf
    I use Windows10x64
    Download your files to run the test, the error is shown below
    So what library is it missing or how to configure it to use it ???
    Have I seen the instructions but did not make sure I did something wrong ?? !!!
    If you are looking forward to it, please give us a little detailed instructions with pictures as possible
    Attachment 179058

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,207

    Re: VB6 MDB-RemoteAccess via http(s)

    Quote Originally Posted by PhuongNam View Post
    So what library is it missing
    It's probably vbRichClient5 (the rest of the libs comes already preinstalled since Win-XP).

    A download-page for the BaseDll-package (with install-instructions) should be on vbRichClient.com.

    HTH

    Olaf

  4. #4
    Banned
    Join Date
    May 2020
    Location
    https://t.me/pump_upp
    Posts
    42

    Re: VB6 MDB-RemoteAccess via http(s)

    Quote Originally Posted by Schmidt View Post
    It's probably vbRichClient5 (the rest of the libs comes already preinstalled since Win-XP).

    A download-page for the BaseDll-package (with install-instructions) should be on vbRichClient.com.

    HTH

    Olaf
    That's great you ... a good solution

    1 / Is there any other way to write code to replace vbRichClient5.dll, right?
    2 / How can the Clients access the Demo.mdb file on the Server ???
    I have just tried to adjust the Demo.mdb path so that another machine can access Demo.mdb but I can't ... error ?? !!

    Code:
    Private Sub Form_Load()
        Dim DataPath As String
        DataPath = "C:\Database\"  ''Path Folder
        Set WS = New_c.WebServer
        Rem  WS.Listen App.Path, IP, PORT
        WS.Listen DataPath, IP, PORT
        Set CnnCache = New_c.Collection
        'now, let's put the http-RPC already to the test (filling the table_names from our Server-DB into cmbTables)
        FillDBTableCombo
    End Sub
    Last edited by PhuongNam; Oct 18th, 2020 at 08:23 PM.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,207

    Re: VB6 MDB-RemoteAccess via http(s)

    Quote Originally Posted by PhuongNam View Post
    1 / Is there any other way to write code to replace vbRichClient5.dll, right?
    Yes, you will have to find a WebServer-replacement.
    My recommendation is still, as already mentioned in my opener-posting here - the MS-IIS,
    since it comes with each Win-OS and can be installed/configured on each Win-Machine via "Products/Features",
    ... it also runs later already as a true Windows-Service, has a nice Config-Editor etc...

    Quote Originally Posted by PhuongNam View Post
    2 / How can the Clients access the Demo.mdb file on the Server ???
    The clientside Code in the Demo is clearly marked (and is not dependent on vbRichClient5).
    Just move the ADO-Helper-Module over to Excel-VBA for example, and steal the Code in
    the Btn-Click-Handlers from the Form-Code.

    Quote Originally Posted by PhuongNam View Post
    I have just tried to adjust the Demo.mdb path so that another machine can access Demo.mdb but I can't ... error ?? !!
    Have just tried that here:
    WS.Listen "c:\temp", IP, PORT
    (after copying the Demo.mdb-File to "c:\temp" on my machine)

    ... and it did work without problems.

    Olaf

  6. #6
    Banned
    Join Date
    May 2020
    Location
    https://t.me/pump_upp
    Posts
    42

    Re: VB6 MDB-RemoteAccess via http(s)

    Quote Originally Posted by Schmidt View Post
    Yes, you will have to find a WebServer-replacement.
    My recommendation is still, as already mentioned in my opener-posting here - the MS-IIS,
    since it comes with each Win-OS and can be installed/configured on each Win-Machine via "Products/Features",
    ... it also runs later already as a true Windows-Service, has a nice Config-Editor etc...



    The clientside Code in the Demo is clearly marked (and is not dependent on vbRichClient5).
    Just move the ADO-Helper-Module over to Excel-VBA for example, and steal the Code in
    the Btn-Click-Handlers from the Form-Code.


    Have just tried that here:
    WS.Listen "c:\temp", IP, PORT
    (after copying the Demo.mdb-File to "c:\temp" on my machine)

    ... and it did work without problems.

    Olaf
    I just tried it and ran very well ... I found out a little bit to understand its method ... so how do I perform the following 3 functions from Client to Database.accdb Server ???

    1 / DELETE * FROM "& TableName
    2 / R.AddNew
    3 / INSERT INTO "& TableName
    Last edited by PhuongNam; Oct 19th, 2020 at 07:28 AM.

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,207

    Re: VB6 MDB-RemoteAccess via http(s)

    Quote Originally Posted by PhuongNam View Post
    I just tried it and ran very well ...
    I found out a little bit to understand its method ...
    so how do I perform the following 3 functions from Client to Database.accdb Server ???

    1 / DELETE * FROM "& TableName
    2 / R.AddNew
    3 / INSERT INTO "& TableName
    You could allow "DB-changing Cnn.Execute calls" by simply changing the WebServer-HandlerProc to the following:
    (changes in Blue-Color)
    Code:
    Private Sub HandleMDBRequest(Response As cWebResponse, DBPath As String, BodyCmd As String)
      On Error GoTo 1
        Response.ContentType = "application/octet-stream"
        
        Dim Cnn As New ADODB.Connection, Rs As New ADODB.Recordset, AffectedRows
        If Not CnnCache.Exists(DBPath) Then CnnCache.Add OpenJetDB(DBPath), DBPath
        Set Cnn = CnnCache(DBPath) 'at this point we can rely on, that the DB-Conn is cached
        
        If Len(BodyCmd) Then
           If InStr(1, BodyCmd, "Select ", 1) = 1 Then 'it's a Select-Command
             Response.SetResponseDataBytes GetBytesFromRs(Cnn.Execute(BodyCmd))
           Else 'it's a Non-Select-Command
             Cnn.Execute BodyCmd, AffectedRows
               Rs.Fields.Append "LastInsertedAutoID", vbLong
               Rs.Fields.Append "AffectedRows", vbLong
               Rs.Open: Rs.AddNew Array(0, 1), Array(Cnn.Execute("Select @@Identity")(0), AffectedRows)
             Response.SetResponseDataBytes GetBytesFromRs(Rs)
           End If
        Else
           Response.SetResponseDataBytes GetBytesFromRs(Cnn.OpenSchema(adSchemaTables))
        End If
        
    1 If Err Then Response.SetResponseDataBytes GetBytesFromRs(GetErrorRs("Server-Error: " & Err.Description))
    End Sub
    This should work for Commands like your listed points 1 and 3 (your 2 would be covered by an Insert-Command like in 3).

    HTH

    Olaf

  8. #8
    Banned
    Join Date
    May 2020
    Location
    https://t.me/pump_upp
    Posts
    42

    Re: VB6 MDB-RemoteAccess via http(s)

    Quote Originally Posted by Schmidt View Post
    You could allow "DB-changing Cnn.Execute calls" by simply changing the WebServer-HandlerProc to the following:
    (changes in Blue-Color)
    Code:
    Private Sub HandleMDBRequest(Response As cWebResponse, DBPath As String, BodyCmd As String)
      On Error GoTo 1
        Response.ContentType = "application/octet-stream"
        
        Dim Cnn As New ADODB.Connection, Rs As New ADODB.Recordset, AffectedRows
        If Not CnnCache.Exists(DBPath) Then CnnCache.Add OpenJetDB(DBPath), DBPath
        Set Cnn = CnnCache(DBPath) 'at this point we can rely on, that the DB-Conn is cached
        
        If Len(BodyCmd) Then
           If InStr(1, BodyCmd, "Select ", 1) = 1 Then 'it's a Select-Command
             Response.SetResponseDataBytes GetBytesFromRs(Cnn.Execute(BodyCmd))
           Else 'it's a Non-Select-Command
             Cnn.Execute BodyCmd, AffectedRows
               Rs.Fields.Append "LastInsertedAutoID", vbLong
               Rs.Fields.Append "AffectedRows", vbLong
               Rs.Open: Rs.AddNew Array(0, 1), Array(Cnn.Execute("Select @@Identity")(0), AffectedRows)
             Response.SetResponseDataBytes GetBytesFromRs(Rs)
           End If
        Else
           Response.SetResponseDataBytes GetBytesFromRs(Cnn.OpenSchema(adSchemaTables))
        End If
        
    1 If Err Then Response.SetResponseDataBytes GetBytesFromRs(GetErrorRs("Server-Error: " & Err.Description))
    End Sub
    This should work for Commands like your listed points 1 and 3 (your 2 would be covered by an Insert-Command like in 3).

    HTH

    Olaf
    Thank you for the guidance
    Basically I did Ok ... so I want to be more flexible in Depending on Database.mdb I gave the following idea, how to handle it

    1 / I write a function from Server that will select 1 Data.mdb file with random name for example: Data1.mdb, Data2.mdb, Data3.mdb ... to connect

    2 / So how does the Client side handle it? Option to get the name of that file without having to declare it publicly as follows

    DBURL = "http: //" & IP & ":" & PORT & "/Demo.mdb"

    That means that the Demo.mdb Files it will automatically retrieve by the Server, connect to the DBURL Client-side connection string

    Thank you

  9. #9
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,742

    Re: VB6 MDB-RemoteAccess via http(s)

    it's easy by netbox for replace iis.support asp.so it can show table data,edit ,delete recordset,do anyting!
    Last edited by Shaggy Hiker; Jun 6th, 2021 at 11:40 PM. Reason: Removed link that was being flagged by AV scans.

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,207

    Re: VB6 MDB-RemoteAccess via http(s)

    Quote Originally Posted by xiaoyao View Post
    it's easy by netbox for replace iis.
    support asp.
    so it can show table data,edit ,delete recordset,do anyting!
    The IIS is a well-tested, hardened Windows-service, which is already on-board in every Win-installation since XP.
    It only needs to be activated via Programs/Features (only requiring about 10 mouse-clicks or so, to configure it with *.asp support).

    So I'm not sure, why somebody should risk installing something else, which offers "serverside scripting via *.asp",
    when the original is so readily available without any costs or larger installation-efforts.

    BTW, clicking the download-buttons on the Page you've linked to, gives me a security-warning in Firefox ("malicious site").

    Probably better, when you remove the link from your posting, before the moderators will do so.

    Olaf

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