Page 2 of 2 FirstFirst 12
Results 41 to 58 of 58

Thread: Question on refreshing data

  1. #41
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: Question on refreshing data

    I will try to explain.

    The DBClient object is in the client application on the user's computer. The Connect method is called to connect to the server over the network, and it only "pretends" to connect to the database. Instead of connecting to the database it puts the database name in a variable, and it will pass that database name to the server for other calls like GetRs, Execute, etc...

    When you subsequently call another client method like GetRs, the client app will send the DB name (in this case "Test.db") along with other parameters to the server over the network.

    The server will receive the parameters from the network in the cDBAccess class method of the same name (so cDBAccess.GetRs in this case). Each public method in the server cDBAccess class first tries to open a database connection if necessary by calling EnsureConnectionFor with the passed DB name. If the DB connection is already open then EnsureConnectionFor does nothing.

    After calling the internal EnsureConnectionFor method, the called server method does its work on the database and passes the result back to the client over the network.

    So the client app never really touches the DB directly, or has any real connection to the database. It just knows its name.

    On the server though, you are doing actual work against the database, and it is the server that needs to know the password when it tries to open the connection in the EnsureConnectFor method.

    Let's suppose you have more than one database on the server (Test1.db, Test2.db, and Test3.db), and they each have a different password. You could do something like this in the CDBAccess EnsureConnectionFor Method:

    Code:
    Private Function EnsureConnectionFor(DBName As String)
      Dim Password As String
    
      If Cnn Is Nothing Or LastDBName <> LCase$(DBName) Then
         
         ' Get the appropriate password for the known databases
         Select LCase$(DBName)
         Case "test1.db"
           Password = "passwordfordb1"
         Case "test2.db"
           Password = "passwordfordb2"
         Case "test3.db"
           Password = "passwordfordb3"
         Case Else
           Err.Raise vbObjectError, , "Unknown database: " & DBName
         End Select
    
         LastDBName = LCase$(DBName)   ' Remember the DB name that we are opening in case we have to change the connection later for a different DB name
    
         Set Cnn = New_c.Connection(App.Path & "\" & DBName, , Password)    ' Open the passed DBName with the correct Password
      End If
    End Function

    Does that help at all?

  2. #42

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: Question on refreshing data

    jpbro
    I'm so grateful to you for the clarifications you brought
    I understand the connection method.
    However I spent long hours trying to unlock the database but in vain.
    I'm getting a message database file is not a database.
    This means the function I used could not unlock the database.
    I attached Olaf's Demo but the database file Test.db is password protected with "123456"
    Could you please try oo connect to database?
    thank you

    SQLiteServerMode.zip

  3. #43
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Question on refreshing data

    Quote Originally Posted by samer22 View Post
    Could you please try oo connect to database?

    SQLiteServerMode.zip
    I have no problem to open your Test.db with "12345" by placing this PasswordString in the Parameter-Slot,
    jpbro has already shown in post #39:

    Code:
    Private Function EnsureConnectionFor(DBName As String)
      If Cnn Is Nothing Or LastDBName <> LCase$(DBName) Then
         LastDBName = LCase$(DBName)
         Set Cnn = New_c.Connection(App.Path & "\" & DBName, , "12345")
      End If
    End Function
    HTH

    Edit: Just in case ... of course you need to re-compile this SQLiteServer-Dll-Project after such CodeChanges -
    and then ensure, that you place the new Dll-Binary in the RPCDlls-Folder of the machine which runs your real Server-App...

    Olaf
    Last edited by Schmidt; Nov 12th, 2019 at 08:23 AM.

  4. #44
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Question on refreshing data

    Password?
    Olaf, by any chance: Is your sqlite.dll compiled with option "USER_AUTHENTICATION"?
    Wouldn't mind to get the compiling command-line using mingw to compile sqlite with Options USER_ATHENTICATION and stdcall
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  5. #45

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: Question on refreshing data

    I have no problem to open your Test.db with "12345" by placing this PasswordString in the Parameter-Slot,
    jpbro has already shown in post #39:
    Incredible!!!
    I did exactly as jpbro told me but I'm faced with the message Cannot compile .. file is not a database

    Name:  110.png
Views: 225
Size:  13.5 KB

    would you please send me a working Demo?

  6. #46
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: Question on refreshing data

    Did you remember to recompile the SQLiteServer DLL after adding the password?

  7. #47
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Question on refreshing data

    Quote Originally Posted by Zvoni View Post
    Password?
    Yes, SQLite has an Encryption-Interface (which I address with a similar C-module, as the original .NET-Wrapper for SQLite, which was - a decade ago - provided by Robert Simpson, and is to this day still the same in both, the RC5-COM-wrapper and the current "official .NET-wrapper for SQLite", because the same Stream-Cypher is used in both implementations.)

    So, SQLite-DBs which were encrypted using the .NET-wrapper can be opened by the RC5-wrapper and vice versa.

    Quote Originally Posted by Zvoni View Post
    ...by any chance: Is your sqlite.dll compiled with option "USER_AUTHENTICATION"?
    No, I've never used (or needed) that mechanism, because:
    - encrypting the whole DB-File (transparently via a PasssPhrase-Key) is one thing
    - whilst Authentication/Authorization is an entirely different animal

    And the latter one is (IMO) better handled by the "hosting TCP/IP ServerApp" (in this case the RC5-RPC-stuff, which supports this at the Socket-Connect-Level via Diffie-Hellman-Key-exchange).

    Other Server-Host-Apps (like e.g. the MS-WebServer IIS) also have appropriate Auth-mechanisms built-in, which only need to be configured properly...

    A third way would be, to implement this "on top" of the AppServer (not using its built-in Auth) via explicit (normal) RPC-calls, which could establish a "Sesssion-" or "User-token" (in the very first RPC-calls after a TCP-connection is made) - e.g. via CRAM or SCRAM.
    Such a Token would then need to be passed in each and every of the "follow-up" RPC-calls in an additional Parameter-Argument.

    Quote Originally Posted by Zvoni View Post
    Wouldn't mind to get the compiling command-line using mingw to compile sqlite with Options USER_ATHENTICATION and stdcall
    I'm not compiling with MingW (but with VC++) at the moment.

    As for __stdcall ...
    If this is for FreePascal, you should be able to use the normal __cdecl convention with compiled SQLite-binaries.

    If it is for VB6 - feel free to use the "naked" vb_cairo_sqlite.dll of the RC5-package which exports all sqlite-apis as __stdcall ...
    Or alternatively use the MingW/GCC compiler-switch: -mrtd ... to force a __cdecl source into __stdcall mode in your compiles.

    HTH

    Olaf

  8. #48
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Question on refreshing data

    Quote Originally Posted by Schmidt View Post
    *snipp*
    I'm not compiling with MingW (but with VC++) at the moment.
    i have to use mingw since i'm on Linux (cross-compiling)
    As for __stdcall ...
    If this is for FreePascal, you should be able to use the normal __cdecl convention with compiled SQLite-binaries.
    I know that. Just wanted to have the option to "translate" it to stdcall if necessary.
    If it is for VB6 - feel free to use the "naked" vb_cairo_sqlite.dll of the RC5-package which exports all sqlite-apis as __stdcall ...
    No, not for VB6, since i abandoned VB6 (not Office-VBA) 2-3 years ago, but since i'm doing a lot of stuff in VBA (at work) i'd just like to keep my options open

    Or alternatively use the MingW/GCC compiler-switch: -mrtd ... to force a __cdecl source into __stdcall mode in your compiles.

    HTH

    Olaf
    Now, that "-mrtd" looks promising.... thx
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  9. #49
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: Question on refreshing data

    Quote Originally Posted by Zvoni View Post
    Now, that "-mrtd" looks promising.... thx
    Btw, there is equivalent /Gz option with cl.exe.

    /Gz specifies the __stdcall calling convention for all functions except C++ member functions, functions named main, and functions that are marked __cdecl, __fastcall, or __vectorcall. All __stdcall functions must have prototypes. This calling convention is only available in compilers that target x86, and is ignored by compilers that target other architectures.
    cheers,
    </wqw>

  10. #50
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Question on refreshing data

    Quote Originally Posted by wqweto View Post
    Btw, there is equivalent /Gz option with cl.exe.


    cheers,
    </wqw>
    No CL on Linux (at least haven't found it, yet)
    I'm using MinGW or GCC
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  11. #51

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: Question on refreshing data

    Quote Originally Posted by jpbro View Post
    Did you remember to recompile the SQLiteServer DLL after adding the password?
    I'm deeply sorry
    This is the point I was missing

  12. #52
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: Question on refreshing data

    No worries, glad it got sorted out

  13. #53

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: Question on refreshing data

    jpbro
    The users who are using my application and who already have data in their db will lose their data.
    since recompilation of the SQLiteServer DLL is necessary
    thank you

  14. #54
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: Question on refreshing data

    The data should be in the database file, NOT the DLL so there should be no issue with recompiling the DLL. Of course, make sure you have a backup of the DB file anyway in case we don't have a full picture of your environment (you should be keeping backups as a matter of course).

  15. #55
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: Question on refreshing data

    The SqliteServer.dll is part of a bridge between your users and their data, but it is not the data itself.

    UserApp/RPC Client Connection <-> Network <-> RPC Server/Listener App <-> SQLiteServer.dll <-> DatabaseFileWithData

  16. #56

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: Question on refreshing data

    jpbro
    The users who are using my application and who already have data in their db will lose their data.
    since recompilation of the SQLiteServer DLL is necessary
    thank you

  17. #57
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: Question on refreshing data

    That's the same thing you said in post #53. Did you read my answers in post #54 and #55?

    Leave the database file alone and just distribute the new application files (exe & DLL). Recompiling the DLLs will not touch the SQLite database files.

  18. #58

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: Question on refreshing data

    sorry there is duplication of my post I did not how this happened
    thank you sir million times

Page 2 of 2 FirstFirst 12

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