Results 1 to 14 of 14

Thread: How to store and retrieve information

  1. #1

    Thread Starter
    Frenzied Member schoemr's Avatar
    Join Date
    Apr 2016
    Location
    South Africa
    Posts
    1,404

    How to store and retrieve information

    Hi, so I have an argument with my lecturer. After login I retrieve the user information from the database e.g. FistName, Lastname, PhoneNumber etc. I then use this information all over in the application e.g. Message with the person's name etc.

    So what is the best way to store and use this information?

    1) Store as global variables in module
    2) Store in session
    3) Store in cache?

  2. #2
    Addicted Member
    Join Date
    Jan 2022
    Posts
    139

    Re: How to store and retrieve information

    I reckon this depends what he is concerned about. If hes not concerned about it being in the DB but then concerned you are using it in an app, then hes not a very good lecturer, that would be my answer to him/her.

    after that it makes no difference how you temporarily store the data, other than the time it takes to do so. Obviously you wouldn't write it to settings or any file

    I use the Environment.Username to communicate to the user and also use that to link arbitrary application options, such as storing user filter strings and configuration options.

    Also, in the UK and perhaps some other Countries it is best NOT to even include a phone number at all anywhere at any time period. Leave that entirely up to HR 100%
    Last edited by vbdotnut; Feb 6th, 2023 at 08:12 AM.

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

    Re: How to store and retrieve information

    Quote Originally Posted by vbdotnut View Post
    I reckon this depends what he is concerned about. If hes not concerned about it being in the DB but then concerned you are using it in an app, then hes not a very good lecturer, that would be my answer to him/her.

    after that it makes no difference how you temporarily store the data, other than the time it takes to do so. Obviously you wouldn't write it to settings or any file

    I use the Environment.Username to communicate to the user and also use that to link arbitrary application options, such as storing user filter strings and configuration options.

    Also, in the UK and perhaps some other Countries it is best NOT to even include a phone number at all anywhere at any time period. Leave that entirely up to HR 100%
    I don't think, that has anything to do with OP's description, especially that Environment-Thing.

    In any ERP-System worth its salt, you have "sensitive" Data (Phone-No.) so that is not really out of left field for that sample-database/application

    I think OP's question was more in general, how/where to store/keep the Data while he's working with the Program.

    To OP's question: I would "blackbox" it as far as it is possible/viable.

    "Cache" implies a file written to disk: No-Go --> or do you mean something else with "cache"?
    "Session" sounds like a Web-Application --> No Idea

    Bottom Line: "Data" must be destroyed when logging out
    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

  4. #4

    Thread Starter
    Frenzied Member schoemr's Avatar
    Join Date
    Apr 2016
    Location
    South Africa
    Posts
    1,404

    Re: How to store and retrieve information

    Also, in the UK and perhaps some other Countries it is best NOT to even include a phone number at all anywhere at any time period. Leave that entirely up to HR 100%
    This is Africa, we don't have time for that first world nonsense 🙂

    Over here HR will come pull you out of your house and slap you around a bit if you didn't go to work, nevermind worry about your phone number

    But I get what you're saying.

    Zvoni, yes that is what I'm also thinking. Both those methods is writing to the server?

    When the user exists all the loaded information must be gone. My lecturer thinks if I want to say Msgbox("Welcome Mary") I should get Mary's name from the database each and every time. Me think you only get that information once when you login. Otherwise you keep calling the database for information over and over again...

  5. #5
    Addicted Member
    Join Date
    Jan 2022
    Posts
    139

    Re: How to store and retrieve information

    I should get Mary's name from the database each and every time
    That is just silly.

    My point was, chances are Mary can be found locally from the machine environment, but if that is not satisfactory and you have to get this from DB then I would set a Form level variable(s) with only columns that will be consumed, which I would not opt for any sensitive data at all. No matter what block/module/class you put this it lives in memory and is not accessible by anything but the running application and that would be machine-code... like a bunch of bytes, so I really dont know what point hes trying to make. What is the reasoning he has provided?

  6. #6
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    3,692

    Re: How to store and retrieve information

    Quote Originally Posted by vbdotnut View Post
    That is just silly.

    My point was, chances are Mary can be found locally from the machine environment
    Not necessarily.

    I know of lot of systems, where the UserName for Login doesn't has to do anything with the "real" Name of the User.

    Example: Active Directory
    In the company i work for, users can have Windows-login-usernames whatever they want, it still shows "FirstName, MiddleName Lastname" because it pulls out the Data from the Database in the AD
    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

  7. #7

    Thread Starter
    Frenzied Member schoemr's Avatar
    Join Date
    Apr 2016
    Location
    South Africa
    Posts
    1,404

    Re: How to store and retrieve information

    What is the reasoning he has provided?
    I didn't write down everything in details because in my head i was already arguing with him........

    I have:

    1) Reduced memory usage: if you store info in a global variable the memory will be reserved for the entire life of the program
    2) Improved scalability: As info in db grow so does the amount of memory required
    3)Better security: If sensitive info such as passwords is stored in gv's it can be vulnerable to security risks e.g. malicious user can access info and cause harm
    4) Easier maintenance: If you need to change the information in the db then you have to update all your gv's in multiple places and can make maintenance difficult especially in large applications/databases

    That is why (according to him) it is better to only retrieve the information when needed.

    So now it is okay to "hit" the database a million times for info you can get in once call??
    Last edited by schoemr; Feb 6th, 2023 at 11:51 AM.

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,063

    Re: How to store and retrieve information

    Assuming this is a desktop application (I wasn't clear about that from the first post, as session state sounds more like web), I wouldn't worry about storing a few items in memory. Memory is cheap. Since the dawn of computing, people have generally traded memory for performance, and this is another case of doing that. You certainly COULD go to the DB to get the information every single time. That would come at a performance cost, though perhaps not one that anybody would really notice. If you were doing it frequently, it would add up, but computers usually spend most of their time waiting for the meat bag at the keyboard to get around to doing something, so you likely wouldn't see the cost.

    Still, that would be pretty absurd. Alternatively, if you were to store the information in a variable, no matter whether it be local or global, then it is inaccessible outside of the program. Technically, that isn't quite true. It might linger in memory even after the program has closed. Depending on the hardware, it might even be retrievable from RAM even after the computer has been turned off. But none of that is truly plausible. If anybody has sufficient access to your computer to be able to take advantage of any of that, then you have bigger problems than a bit of Personally Identifiable Information.

    Therefore, I'd store it in a variable.
    My usual boring signature: Nothing

  9. #9
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,559

    Re: How to store and retrieve information

    Based on the little info provided I'd write a class,

    Code:
        Public Class UserInfo
            Private _FirstName As String
            Public ReadOnly Property FirstName As String
                Get
                    Return Me._FirstName
                End Get
            End Property
    
            Private _LastName As String
            Public ReadOnly Property LastName As String
                Get
                    Return Me._LastName
                End Get
            End Property
    
            Public Sub New(something_to_access_DB_with As Object)
                'retrieve the user information from the database and set variables
                ' e.g. _LastName
            End Sub
    
        End Class
    and then create an instance of the class and use it everywhere.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  10. #10

    Thread Starter
    Frenzied Member schoemr's Avatar
    Join Date
    Apr 2016
    Location
    South Africa
    Posts
    1,404

    Re: How to store and retrieve information

    Thank you everyone

    Memory is cheap.
    kkrrrr!! ohhhh!!!!! definitely not according to some people!! It is more expensive than gold, especially CPU memory

    thank you dbasnett, that is actually neat

  11. #11
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,079

    Re: How to store and retrieve information

    I think there are times when retrieving data each time when needed is the correct approach. In multiuser systems it may be the best way to insure your working with valid data. Some data lends itself to being modified more than others. Something like "Company Name" probably isn't going to change very often. Things like inventory are more problematic and I'd retrieve and save that kind of information often. Some USER information could also change, like Account Balance.

    I'd say both method have there place.
    Last edited by wes4dbt; Feb 6th, 2023 at 01:47 PM.

  12. #12
    Addicted Member
    Join Date
    Jan 2022
    Posts
    139

    Re: How to store and retrieve information

    If he wants to argue about memory usage over a borderline immeasurable amount of local machine capacity, tell him you are happy to consume the local resource once over spreading the same amount of bytes through the topology and server resources at an undetermined rate, but in both cases is such an insignificant measure and either approach is not going to cripple your application by any means.

    Scalability... again, theres nothing complex about this, theres like 2 parts to the flowchart where part one is run the app...

    Better security, well like Shaggy said, as long as there was a power source there's potential you could access this near impossible address. I am no hardware expert, but I am envisioning myself fishing for a goldfish in the Pacific thats swimming in the Atlantic, and if by chance I caught it I would need to somehow disassemble it in an exact way in order to eat it.

    Which leaves you with maintenance, and thats a thing no matter what. This is the reason project managers exist, good ol documentation.

  13. #13
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,254

    Re: How to store and retrieve information

    Personally in my project's startup events, I will create a property under the MyApplication namespace that represents the global record (as a POCO). This works similarly to PHP's $_SESSION if you are familiar with it.

    A typical use case would be for a user to login to the application and then on successful login I store the record there. Then when the user creates a record I set my audit log fields using something like:
    Code:
    MyRecord.CreatedBy = My.User.UserId
    This works well for me and haven't run into any issues.
    "Code is like humor. When you have to explain it, itís bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  14. #14
    Fanatic Member
    Join Date
    Jun 2019
    Posts
    515

    Re: How to store and retrieve information

    VB18 Code:
    1. public class SomeOperations
    2.   private _loggedUser as LoggedUser
    3.   private _operationsReader as IOperationsReader
    4.   private _operationsWriter as IOperationsWriter
    5.  
    6.   public sub New(
    7.       loggedUser as LoggedUser,
    8.       operationsReader as IOperationsReader,
    9.       operationsWriter as IOperationsWriter)
    10.    
    11.     _loggedUser = loggedUser
    12.     _operationsReader = operationsReader
    13.     _operationsWriter = operationsWriter
    14.   end sub
    15.  
    16.   public sub DoThisOrThat(.. some params ..)
    17.     ...
    18.     ...
    19.     _operationsWriter.CreateSomeObject("operation",
    20.       _loggedUser.UserName,
    21.       _loggedUser.Email)
    22.   end sub
    23. end class

    Inject all dependencies into the objects. Do not rely on global variables. Or you will get in troubles sooner or later...

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