Results 1 to 7 of 7

Thread: [RESOLVED] Change path of Data Source

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    107

    Resolved [RESOLVED] Change path of Data Source

    hello guys
    i am having problems changing the path of the database that i have used in a project, since i have used 'data source' option to add database into project and now when i opened the same project in different computer i am getting this error:

    Name:  x.bmp
Views: 7177
Size:  376.6 KB

    im not able to change the path of the database since there no code for this present in the form like that of traditional way provider="jet ......."
    can anyone help me how to change its path at its run-time so that this project can be executed on different on different computers.

    Thank You
    Boing

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Change path of Data Source

    If you added the dataset using the standard wizard in VS, then it should have put your connection string in the projects settings file. If you go into project properties, and then settings, is there a DB connection listed there? If so, you can modify it to a path that is available on both machines.

    Another thing you could do is set the |datadirectory| which basically means you use that string of |datadirectory| in your connection string, and then you set the actual value of it at runtime, depending on which machine you are on. More info here:
    http://social.msdn.microsoft.com/For...y-?forum=sqlce

    If you are just needing to do development on 2 machines (I often work on my home and office machine with the same source code), then I find it easier just to setup a similar data structure on both machines. I keep all my source code in a folder at c:\work. This way, on any machine I just make a c:\work folder, and check out my projects (I use source control). The other nice added bonus, is that your paths when dealing with file paths and whatnot, will always be a lot shorter than c:\users\username\desktop, etc..

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    107

    Red face Re: Change path of Data Source

    Quote Originally Posted by kleinma View Post
    If you added the dataset using the standard wizard in VS, then it should have put your connection string in the projects settings file. If you go into project properties, and then settings, is there a DB connection listed there? If so, you can modify it to a path that is available on both machines.
    Thanks a lot for your reply i got my data source, but can you tell me how to change these value because i wanna change it at run time with a textbox giving the source...

    Name:  x.bmp
Views: 6906
Size:  383.5 KB

    i tried uconnectionstring.value="something" but it didnt work.

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

    Re: Change path of Data Source

    Well, your first mistake was using a database that wasn't part of the project. You should have added the database to the project in the Solution Explorer and, when prompted, allowed it to copy the database into the project folder. You should also have then set the Copy To Output Folder to Copy If Newer. The source database in the project folder would then stay clean and your app would work on a copy in the output folder. As such, you would use |DataDirectory| in the connection string for the folder path and it would all just work, both while debugging and after release with no change required to the connection string. It was all designed to work easily and effectively and you just made it all harder.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    107

    Re: Change path of Data Source

    Need more help already read the MSDN forum docs ...how do i set |datadictionary| ?

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

    Re: Change path of Data Source

    What I would suggest is that you delete your DataSet(s) from the Solution Explorer and start again. You can then recreate them "properly" and, as long as you use the same names, all the rest of the code you have that uses them will just continue to work.

    To use an Access database in a VB.NET project you should use the Project menu or right-click your project in the Solution Explorer to Add Existing Item. You navigate to the Access database and, if prompted, you tell VS to copy the file to the project. You can now forget about the original file located on your desktop or wherever because you now have a source file in your project folder and that's the one you care about when it comes to modifying schema or adding default data.

    When you add the database to the project, the IDE will automatically generate a connection string and save it in the config file. That connection string will automatically contain "|DataDirectory|" for the folder path of the data file. The whole point of |DataDirectory| is that it resolves to different locations depending on the type of application and it will work without change from debugging to release. For a Windows application not deployed using ClickOnce, it will resolve to the folder the current EXE was run from. As such, as long as your data file is in the same folder as your EXE, the connection string will work. It doesn't matter what folder that is, as long as both files are in the same place.

    Finally, It's not actually that source file in the project folder that you use at run time. This is a point that confuses a lot of people but it's quite logical that it's done that way. When you build your app, the IDE transforms the files in the source folder in whatever way is appropriate for each one and then places the output in the output folder, which will generally be somewhere under the 'bin' folder of your project. For the VB files, that transformation is compiling into an EXE while, for the database file, it's just a straight copy. It's that copy that your app connects to at run time. That is so that any changes you make while debugging will not affect the original source file so, when it comes time to release, a new copy of the nice clean source file is output rather than your having to clean out all the rubbish you put in there while debugging.

    By default, a new copy is made every time you build your project. That means that, if you run your project and add some data to the database, then change the code and run again, the data you added will have disappeared. That's because the source file was copied over the output file when the project was built again. If you want to keep your test data between runs then you need to edit the Copy To Output Directory property of the data file and set it to Copy If Newer. That way, a new copy will only be made if you make a change to the source file, e.g. add a new table or add some new default data. If you ever want to start with a new, clean database for your testing you simply get rid of the data file in the output folder and replace it with a new copy of the source folder. The easiest way to do that is to set Copy To Output Directory back to Copy Always for just one run.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2009
    Posts
    107

    Re: Change path of Data Source

    Thanks man that was very helpful! Got IT Working!!!

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