none
Data Source Bug/Issue for Database in bin\debug folder (|DataDirectory|\bin\debug \bin\debug is duplicated) RRS feed

  • Question

  • Issue:  Data Source to Access Database in bin\Debug results in incorrect path (e.g. when bound to DataGridView)

    You can replicate the problem as follows (note in VS2005, VS2008, and VS2010, using VB.  I also tried C# in VS2008):
    1.  Create a New Windows Application
    2.  Save Solution
    3.  Copy Access Database to applications bin\debug folder (e.g. db.mdb)
    4.  Drag DataGridView to form
    5.  From DataGridView smart tag, create DataSource for database (select any simple table)
         When pop-up windows asks to copy database to solution, select NO (DO NOT copy)
         Note connection string:  Source=|DataDirectory|\bin\Debug\db.mdb
    6.  Run the application, and you get the following error:
         OleDbException was unhandled
         'C:\Users\...\Projects\WindowsApplication2\WindowsApplication2\bin\Debug\bin\Debug\db.mdb' is not a valid path.  Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
    Error Occurs in Form Load at the following:
    Me.ta.Fill(Me.ds.employees)  (Assuming table adaper is ta, data set is ds, and table selected is employees).
    Note:
    See duplicate \bin\Debug\bin\Debug\

    To get the grid to work, you can edit Settings.settings and change the connection string to remove the duplicate \bin\Debug.
    From: Source=|DataDirectory|\bin\Debug\db.mdb
    To: Source=|DataDirectory|\db.mdb

    The application will now work correctly (run the program and Grid is populated).  However, now you cannot edit the data source. 
    A. From Data Sources Window: Select Data Set and Click on "Edit DataSet with Designer"
    Right Click on the Table Adapter Fill/GetData methods --> Select Configure. 
    Get a pop-up windows error:
    "Falied to open a connection to the database
    Could not find the file ''C:\Users\...\Projects\WindowsApplication2\WindowsApplication2\db.mdb'."
    Check the connection and try again.
    OR
    B. From Data Sources Window: Select Data Set and Click on "Configure DataSet with Wizard" and you get the following in the Wizard Window:
    "An error occured while retrieving the information from the database:
    Could not find the file ''C:\Users\...\Projects\WindowsApplication2\WindowsApplication2\db.mdb'  
    Note:  bin\Debug is now missing.

    A. A.


    UPDATED (Quick Way To Replicate Problem):
    Note: Another way to create the problem real quickly is to add a new data source (again, make sure the access database is in the bin\Debug folder and choose NOT to copy the file to your solution).  Then, drag a table from the DataSet to the Windows form.  When you run the application, you'll get the error above (#6)

    • Edited by Aash64 Thursday, April 28, 2011 5:43 AM Added another way to replicate the problem quickly
    Thursday, April 28, 2011 5:20 AM

Answers

  • WORKAROUND BELOW - Still would like to know why this is happening
    Workaround:
    When creating the DataSource, DO NOT save the connection string.
    Next, edit the data sets designer file, e.g. ds.Designer.vb.
      (From solution Explorer, show all files and the file is under the ds.xsd file)
    Modify the following (remove \bin\Debug):
    From: Me._connection.ConnectionString = "Provider=....Data Source=|DataDirectory|\bin\Debug\db.mdb
    To:    Me._connection.ConnectionString = "Provider=....Data Source=|DataDirectory|\db.mdb

    If you bind the Grid to this data source or drag the table from the data set to the form (using DataGridView vs. Details) everything works: Grid displays data and you can edit the DataSource.

    Thursday, April 28, 2011 7:05 AM

All replies

  • WORKAROUND BELOW - Still would like to know why this is happening
    Workaround:
    When creating the DataSource, DO NOT save the connection string.
    Next, edit the data sets designer file, e.g. ds.Designer.vb.
      (From solution Explorer, show all files and the file is under the ds.xsd file)
    Modify the following (remove \bin\Debug):
    From: Me._connection.ConnectionString = "Provider=....Data Source=|DataDirectory|\bin\Debug\db.mdb
    To:    Me._connection.ConnectionString = "Provider=....Data Source=|DataDirectory|\db.mdb

    If you bind the Grid to this data source or drag the table from the data set to the form (using DataGridView vs. Details) everything works: Grid displays data and you can edit the DataSource.

    Thursday, April 28, 2011 7:05 AM
  • Instead of doing the workaround, you could also stop using designers and create your own DAL and Datasets.  This will provide you with far more control over your development process as well as your end products.
    James Crandall ~ http://javitechnologies.com Spatial Database Solutions
    Thursday, April 28, 2011 11:07 AM
  • James, I agree with you and don't use the designer for any real production solutions.  I was experimenting with it during a class and ran into the issue above.  In fact, I don't use Access for anything in production environments.

    Additionally, I know that the intent is not to put the files in the bin\Debug folder, but have VB copy this for you.  However, when manually creating the connection string for quick examples, it's nice to have the database in the same folder as the application start up path.

    Now that we got that out of the way, do you have a solution to this?  Do you agree that this is a bug and is there a better way around this?


    AA
    Tuesday, May 3, 2011 7:33 PM
  • Hi Asah64,

    You can refer here:

    http://support.microsoft.com/?kbid=920700

    http://social.msdn.microsoft.com/Forums/en-US/sqlce/thread/dc31ea59-5718-49b6-9f1f-7039da425296/

    |DataDirectory| (enclosed in pipe symbols) is a substitution string that indicates the database path. Therefore, you do not have to include the full path in the code

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, May 12, 2011 9:06 AM
    Moderator
  • Alan,
    Thanks, I understand how |DataDirectory| works.  The issue is that the Wizard is creating connection strings with errors when the data source is in the bin\Debug folder.  I suppose as James suggested, don't use the wizard.
    AA


    AA
    Wednesday, June 1, 2011 12:35 AM
  • Alan,
    Thanks, I understand how |DataDirectory| works.  The issue is that the Wizard is creating connection strings with errors when the data source is in the bin\Debug folder.  I suppose as James suggested, don't use the wizard.
    AA


    AA


    eggsactly.  When I first jumped into .NET dev work (I am coming from GIS/Spatial Database world) the tier'ed architecture approach (Presentaion/BLL/DAL) seemed to be the ticket, and it has.  Just about all of the recommendations I followed all said to ditch the whole drag-and-drop thingies and build them yourself.  And it has been very beneficial.

    Bonnie over at the adodotnetdataset forum has some great write-ups on how to decouple your own Datasets from the designers -- basically, you build your own StronglyTyped Datasets (and get all of the same great native functionality of them) but you do so totally independent of any designer thingie.  I still use this approach today and it is an incredibly flexible approach and allows for much more control over your datasets/DAL.

    http://social.msdn.microsoft.com/Forums/en/adodotnetdataset/thread/81a90dcb-e019-4ee0-a3a9-7c109a015386

    I am big time into the database development tier as well, so I do a ton of StoredProcedure work (along with creating the db architectures from the start) and using the approach above really is slick because you setup your own SqlDataAdapters and Commands that point to the SProcs and...whamo, there's your .xsd with all of the dataset structure.  Then it's a matter of hydrating this skeleton with real data in the DAL and pass it around the application appropriately.

     

    Wish I had a direct asnwer to your dilema, bud.  Sorry I couldn't have been more helpful for you earlier when you posted this thread!


    James Crandall ~ http://javitechnologies.com Spatial Database Solutions
    Thursday, June 2, 2011 12:40 AM
  • James,

    No problem.  Thanks for your answer and link above.  It's basically the process that I'm using.  Good to see confirmation.

    Just wish there was a little more debugging effort to wizard generated output.  I've also ran into many other errors (e.g. table adapter: changing SQL statement when parameters are used deletes all parameters).  As I stated above, I don't use this for any production code.  However, its nice to demonstrate concepts using the wizard in a classroom environment prior to digging into doing things manually.

    Take Care,

    AA


    AA
    Tuesday, June 7, 2011 4:02 PM
  • Hi Aash64

    I happened to run into the same problem with my DataGrid and DataSet binding, and bumped into your thread looking for a solution on the web. I can see it has been quite a while since you posted this thread and I'm intrigued to find out if there has been any fix to this bug/issue.

    Also, on a separate note, I'm pretty new in C#.net environment, like to build my myself up. We haven't been taught how to create the datasets etc. manually other than using the wizard. Can you possibly mention some resources shedding some light on this.

    Thanks a lot in advance.

    Wednesday, April 11, 2012 10:57 PM
  • Hi Mahab,

    Check out my post in the link that James provided above and then take a look at my blog posts that I linked to there. One of my blog posts has a link to another post of mine about how to create the Typed DataSets manually and without all the TableAdapter junk.


    ~~Bonnie Berent DeWitt [C# MVP]

    geek-goddess-bonnie.blogspot.com

    Saturday, April 14, 2012 4:12 PM