Results 1 to 2 of 2

Thread: ConnectionString to Database

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    1

    ConnectionString to Database

    I have a problem and I am unsure how to go about it. I am creating a simple vb.net program that uses MS Access as a backend. I place the database in c:\data\data.mdb. In the visual basic designer on one of the forms, I have a odbcconnection object where inside the connectionstring property it points to the database on my machine. I then have controls that look toward a command object which in turns looks through the connection object.

    My problem is, what if I package the program up and gave it to someone else to install. The database on thier computer will not be in c:\data\data.mdb. Therefore the connectionstring in the command object is incorrect because the connectionstring is based where I had the database and not where it is on the users machine.

    How do you go about creating a program where multiple individuals will install the program and you have to adjust the connectionstring to where the database is on thier computer?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: ConnectionString to Database

    First off, you should really choose OleDb over OdbcClient when working with Access.

    Oftentimes you will put the database in a subfolder of your application folder, in which case you can use Application.StartupPath to build the full path. Alternatively, you could store your connection string in the config file and then either manually or in code edit it for each installation. You would generally use an OpenFileDialog or SaveFileDialog to let the user select the database location and then build the path into your connection string if you wanted to do it in code. Note that ConnectionString is a dynamic property so you can store it in the config file with just a few mouse clicks.

    http://msdn.microsoft.com/library/de...albasicnet.asp
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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