Results 1 to 3 of 3

Thread: [RESOLVED] My |DataDirectory| is messed up

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    523

    Resolved [RESOLVED] My |DataDirectory| is messed up

    My Visual Studio is acting very strangely. When installing a data source, the designer kept getting messed up. When I ended up doing is creating a new application, copying the database into the base address of my app (same place as Form1.vb), and then adding the source. It warned me that it was not in my application, and I told it to copy it.

    This worked in my new application, so I copied my code from my original application attempt (the code in my original Form1.vb file). Everything worked fine. Then I changed the Database property from Always Copy to Never Copy. Now the application will not run, and the system indicates it can't find the file - but it is looking in my original \bin\debug location, not my new \bin\debug location. The line setting up the connection string is:
    Code:
               pCn = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\ArticleCites.accdb; Persist Security Info=False;")
    it is the |DataDirectory| that is pointed to the wrong location. My question is Where is the |DataDirectory| set? I know normally the default would be \bin\debug in my application subdirectory, but somehow this got messed up and I am trying to reset it to the proper setting.

    Any help would be appreciated.

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

    Re: My |DataDirectory| is messed up

    I think that you may have misunderstood what Never Copy means. If you're using |DataDirectory| then you want the database in the same folder as the EXE and that will never happen if you select Never Copy. The most appropriate option in most cases is Copy If Newer. That way you will always have a database in your output folder but it will not get overwritten, thereby losing the changes you made during testing, unless you make a change to the original.

    The reason Microsoft warn about that option is that you don't actually have to change the data or schema in the original database to change the data file, thereby prompting a copy on the next build. Simply opening the file can be enough. Given that Always Copy overwrites your data every time, the occasional overwrit eis not a big deal. Copy If Newer should have been the default because it's what most people want and that's what you should use.

    Dealing with local data files is quite easy. If you're using SQL Server Express or SQL Server CE then you add the data file directly to the project using the IDE. If you're using Access or something else then you just let that program create the data file where it wants and use Add Existing Item to add the data file to the project, in which case it will be copied to the source folder and you can ignore or delete the original. You then select the data file in the Solution Explorer and change Always Copy to Copy If Newer.
    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

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    523

    Re: My |DataDirectory| is messed up

    Thanks. This helps.

Tags for this Thread

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