Results 1 to 12 of 12

Thread: Save on Access Database trough vb.net

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2021
    Posts
    32

    Save on Access Database trough vb.net

    Hello everyone.
    Creating a software in vb.net and connecting it to Access, through the wizard, there is a problem: the setup, when I bring it to another PC, looks for the database in the path where I created it on my PC. In most cases, all paths pass through my user, therefore being unrepeatable on other PCs. This forces me to create the database in the C: \ drive, which is common to all PCs. To avoid this, and to make it much easier to use, is there a way that wherever the database is, the software always goes to place the data there? Thanks in advance

  2. #2
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,398

    Re: Save on Access Database trough vb.net

    The database should probably be installed to the user AppData folder. You will need to have your installer do this, and then you can set your application to look for the database there.

    Possible useful link:

    https://www.vbforums.com/showthread....path-in-VB-NET

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2021
    Posts
    32

    Re: Save on Access Database trough vb.net

    yes but if I move the DB from the folder AppData it didn't work...

  4. #4
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,398

    Re: Save on Access Database trough vb.net

    Post your code where you are using the path and file name for the database.

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

    Re: Save on Access Database trough vb.net

    Let's be clear.

    Do you have control of the location of the database? Or, do you want the operator to be able to chose a database from anywhere on their PC?

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Save on Access Database trough vb.net

    Unless you have a specific reason to do otherwise, put the database in the same folder as the application and then use "|DataDirectory|" in the connection string as the folder path. That will automatically resolve to path of the folder the current EXE was run from at run time.

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2021
    Posts
    32

    Re: Save on Access Database trough vb.net

    put the database in the same folder as the application and then use "|DataDirectory|" in the connection string as the folder path.
    Hello and thank for your answers, for connect the software to the database, I use the section "data source" trough the wizard. How can I do to do what you say?

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Save on Access Database trough vb.net

    I told you what to do. What is stopping you setting the connection string as I told you?

  9. #9

    Thread Starter
    Member
    Join Date
    Apr 2021
    Posts
    32

    Re: Save on Access Database trough vb.net

    sorry for the ignorance but i haven't used vb.net for a long time and i don't know exactly how to set the connection string. Could you tell me where to set it? Thank you

  10. #10
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: Save on Access Database trough vb.net

    When you created the datasource, you would have been prompted asking if you wanted to save the connection string to the application config file. If you said yes then you can modify the datasource connection string by going to the project properties, select settings, then make the modification.

  11. #11

    Thread Starter
    Member
    Join Date
    Apr 2021
    Posts
    32

    Re: Save on Access Database trough vb.net

    So to make sure that the software always connects to the DB in its same position, what should I enter here?
    Attached Images Attached Images  

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Save on Access Database trough vb.net

    It seems like you're not prepared to make any effort at all to understand how connection strings work. That is already doing exactly what I said to do, i.e. it is using "|DataDirectory|" as the folder path. That gets replaced by the data directory path at run time. For a WinForms app not deployed using ClickOnce, that data directory path will be the folder that the EXE was run from, no matter where that is. That's what I already told you. Is the database in that folder or not? If not, why didn't you mention that when I brought this up in post #6? If it is then what you have should work as is so, if it's not, you're doing something to break it, so you need to provide all the relevant information so that we can work out what you've done wrong.

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