Where do I configure the expansion of the |DataDirectory| macro? RRS feed

  • Question

  • Hi Guys n Girls

    When I use VS2005, add a new datasource and pick a JET MDB file say YES to the question "Do you want to copy the DB into your project?", the connection string will end up as:
    And VS will, somewhere internally, set up |DataDirectory| to expand to the  project directory so that design time dataset creation functionality works against the "development" db in the project folder. When copied out and run, |DataDirectory| takes on the meaning of "the path to the current EXE" and all works fine

    Now, skip to using the new ACCDB/Office 12 ACEDB provider. We DON'T get the question "Do you want to coopy the DB into your project?" and our connection string ends up as:
    If I manually edit this to |DataDirectory|, include the DB in the project, set it to Copy Always on Build etc etc it works as runtime, because |DataDirectory| expands to the currently running EXE (the debug instance) and the app works


    I cannot use the DataSet designer because at design time it is expanding |DataDirectory| to be the path of visual studio:
    C:\Program Files\Microsoft Visual Studio 8\Common7\IDE

    So my question is, what trick does VS pull when adding a known-to-be-a-file-based-db-and-hence-can-use-the-datadirectory hack that I'm not doing?
    Tuesday, February 17, 2009 2:05 PM

All replies

  • See if the following forum thread helps:

    Paul ~~~~ Microsoft MVP (Visual Basic)
    Tuesday, February 17, 2009 7:52 PM
  • I'm not sure that that is the answer to this question, because it seems to be that AppDomain.SetData is something that you call at RUNTIME, but here I am asking where to set at DESIGN_TIME so that VisualStudio itself knows how to expand DataDirectory (in the DataSet designer).

    Friday, February 20, 2009 11:38 AM
  • There is no design time setting. The value is retrieved from the AppDomain cache when the DataDirectory macro is referenced.
    Paul ~~~~ Microsoft MVP (Visual Basic)
    Friday, February 20, 2009 4:02 PM
  • OK, so my question stands as:

    When a design-time tool such as the dataset designer wants to "[retrieve] from the AppDomain cache when the DataDirectory macro is referenced" how do I alter the AppDomain cache so that it reads the correct value?

    Monday, February 23, 2009 2:12 PM
  • To clarify, as a design time option it's limited. By default the path returned is for the location of the application that is opening the database. At design time that would be the IDE and I'm not aware of any way to change that.

    It's rather obvious that they didn't consider the designer when they implemented this feature. I'm pretty sure they are aware of this issue since you would have the same problem in design mode when implementing the feature in a user control.

    Paul ~~~~ Microsoft MVP (Visual Basic)
    Monday, February 23, 2009 5:13 PM