database question RE: cjards post titled "Changes are gone when I restart the app"

thirteentwenty

Well-known member
Joined
Oct 9, 2008
Messages
80
Location
Honolulu
Programming Experience
Beginner
database question RE: cjards post titled "Changes are gone when I restart the app"

So I just got through reading this post as it addressed a question that I had, and it did answer, cjard, thank you for that, but... there's always a but...

I just tried with an accdb file and it doesn't work as described (read: with the mdb file). Maybe I'm doing something, I'm not sure... but vs2005 didn't give me the option to copy the file as it did with other projects that I've tried.

Does anyone have any suggestions, pointers/tips/clues/etc...?

anyways thanks for the advice =)

heh... maybe I should explain whats happening...

the accdb file appears dimmed (when "Show all files" is selected) and I do not have the option to "Copy if newer" or "Copy Always" in the Properties window for the file. And when adding data source to the project I didn't get the dialog asking to copy to the output directory...

I'm going to feel like a total ass if I left out some crucial step... =(
 
OK, i messed with this for a long time and some things are apparent:

The "do you want to copy the MDB into your project?" dialog is specially implemented and seems to do some special things:
-copies the mdb into your project
-changes the conenctionstring to have |DataDirectory| instead of an absolute path
-sets the DataDirectory of the design-time application domain to (your solution path)

This means you design on the DB that is in the solution folder. and VS is fine with that. It is copied out to the exe folder when you run/debug/build the app. Because you never set DataDirectory in code, and because it defaults to the same folder as the app (for classic apps) or the user data folder (for clickonce apps), when you run your built app (or the IDE runs it for you and attaches the debugger), DataDirectory is assumed (because it is not explicitly set in run-time code) to be one of the two locations given above

i.e. it all works

I can advise you on how to manually replicate 2 out of 3 special things above but I have no idea how to set the datadirectory for the solution to be the solution folder. Ergo what I recommend is:


Take your accdb and put a copy of it in the same folder as visual studio (on my machine it's C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\)
Set your ConnectionString in settings to be |DataDirectory|\uli.accdb
Also copy the uli.accdb to your project and set it to copy-if-newer
Make a pre-build dos command to copy the uli.accdb from VS folder to your solution folder, it is copied before build so any chanegs you made to it using VS, are replicated to your built app


You can put some time into investiating how to set the design-time location of |DataDirectory|, I have no idea how you'll do this and I havent found any reference to it in the project files. I had hoped that putting both an MDB and an ACCDB in the same project, would mean that when the wizard asked to put the MDB in it would set the |DataDirectory| for the entire solution, but oddly, even when the MDB is in and workig fine with a connectionstring that contains |DataDirectory|, the ACCDB connstr (also having |DataDirectory|) does not work and a dialog appears from OLEDB asking for missing info, and quoting the path of the ACCDB to be C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\uli.accdb.

You do also have the option of leaving the connstr as having an absolute path in design mode, and then editing it to have |DataDirectory| when you release your app, giving it filesystem independence. Personally, I'd be inquiring on MSDN forums about what stunts the MDB wizard pulls to get |DataDirectory| working in design time, so that you can replicate that action with your ACCDB.

SOrry I couldnt be of more help
 
Wow... thanks for all the footwork in this, I guess I'll just chalk it up to VS2005 not playing well with the .accdb format. I'll poke around a bit more with it and try some of the solutions that you've suggested, but it seems that if I'm to continue using access, I'll either need to stick with the .mdb format or have to buck up some cash for VS2008...

Thanks again cjard!
 
In reference to your statement: "If by getting the "Include in Project" in the context menu means that it is part of the project, then no, it is not."

If you get the option "Include in Project" when you right click the .mdb file then the file "IS NOT" included in your project yet. Try selecting the "Include in Project" option from the context menu. This should make the .mdb file available, and will also expose the "Copy to Ouput Directory" property. The "Data Source Configuration Wizard" will also pop up and prompt you for input.

I am very interested in hearing your progress on this issue.

I don't get the option to "Include in Project" even if viewed with "View all files" and it is dimmed. as stated before I also don't receive the "Copy to Output Directory" while running through the wizzard (this is most likely because it's a .accdb file and not a .mdb file.

cjard did some massive footwork on how it works and I'm still trying to muddle through his findings but like I said in my last post, it's probably just the way that VS2005 plays (or does not play) with the Access 2007 format...

thanks for the chime in thought, and if you've got a fix for the .accdb thing please do tell...
 
It's cool any suggestions at this point is greatful
 
Back
Top