locked
Exception thrown: database file cannot be found RRS feed

  • Question

  • Hi,

    I'm developing a desktop C# app that uses SQL Everywhere as an embedded database.
    I generated strongly typed DataSet and use that to populate a DataGrid on my app.

    When the app first loads, it populates the DataGrid with a line like this:


    this.sTORE_INV_LNTableAdapter.Fill(this.inventoriesDataSet.STORE_INV_LN);

    That all works fine. Later on, after adding more data to the database (through reading a csv file), I wanted to refresh the display on the DataGrid.

    I used the same line of code:

    this.sTORE_INV_LNTableAdapter.Fill(this.inventoriesDataSet.STORE_INV_LN);

    however, this time, the following exception was thrown:

    The database file cannot be found. Check the path to the database. [ File name = .\\Inventories.sdf ]

    Does anyone know what may be going on?  I saw this article about a bug in VS 2005 when using strongly typed DataSets (http://channel9.msdn.com/wiki/default.aspx/MobileDeveloper.DatabaseCannotBeFoundErrorInTypedDataset)
    but that doesn't seem to apply here.

    The connection string is identical both times that line of code is called so I'm a bit baffled with what's going on.

    Any help would be appreciated. Thanks,

    Jose

    Thursday, September 7, 2006 7:34 PM

Answers

  • Thanks for the input!!

    It sounds so simple and yet I hadn't thought about that. I kept looking for the complicated answer.

    It turns out, my database file was there all along. The problem was, after opening and reading the CSV files to import into the db, the next time I tried to access the db the app was looking for the db file in the same directory where my CSVs where...and of course, it wasn't finding it.

    So now, after reading a CSV and prior to re-querying the db, I use Directory.SetCurrentDirectory() to reset where the app looks for its db.

    Thanks for the help, I had been stumped by this for a week.

    -Jose
    Monday, September 11, 2006 6:26 PM

All replies

  • Windows CE does not support relative paths you're trying to use. You must specify correct absolute path to the database located on device file system.

    Also keep in mind Windows CE does not have drive letters and can't see your desktop's C: (D:, etc) drive as many developers seem to believe.

    Thursday, September 7, 2006 8:38 PM
  • I'm not running this on Windows CE. I'm trying out the new SQL Server Everywhere and using it on Windows XP.

    Thanks though.

    Friday, September 8, 2006 4:46 PM
  • If file can not be found that's probably because it can't be found. You can use File.Exists() to verify that.

    Friday, September 8, 2006 6:35 PM
  • Thanks for the input!!

    It sounds so simple and yet I hadn't thought about that. I kept looking for the complicated answer.

    It turns out, my database file was there all along. The problem was, after opening and reading the CSV files to import into the db, the next time I tried to access the db the app was looking for the db file in the same directory where my CSVs where...and of course, it wasn't finding it.

    So now, after reading a CSV and prior to re-querying the db, I use Directory.SetCurrentDirectory() to reset where the app looks for its db.

    Thanks for the help, I had been stumped by this for a week.

    -Jose
    Monday, September 11, 2006 6:26 PM
  • this one has had me scratching my head for a day so I'm glad I haven't spent a week...

     

    I'm using a separate project as a class library with a *.sdf database so it can be re-used for several projects.

     

    I had the exact problem, everything was good until I opened OpenFileDialog(), then things went south after that.

     

    Just a note to your solution... (maybe you do this already)...but you can assign the OpenFileDialog.RestoreDirectory flag to true and then after it closes the original directory will be restored prior to the open dialog....that way you don't need the Directory.SetCurrentDirectory.

     

    fileChooser = new OpenFileDialog();

    fileChooser.RestoreDirectory = true;

     

    gl

     

    • Proposed as answer by Vibhor Agarwal Thursday, April 14, 2011 11:07 AM
    Wednesday, May 23, 2007 2:21 PM
  • Thanks for the solution Jose... I have been trying to figure this strange one out for the past few days.  Good suggestion on setting the RestoreDirectory too rksty.
    Thursday, August 13, 2009 3:31 AM
  • @Jose @rksty

    WHAT A COINCIDENCE. SAME PROBLEM

    Same Problem "file not found".
    Same app structure - SQL Server CE .sdf file, strongly typed datasets, sdf's and datasets in a dll.
    And the time at which the events occurs at dataGridView refresh, in my case its at ListView Refresh.

    But why doesn't it happen when i run through Visual Studio in debug mode??

    I have been developing my application from the past 5 months(no problem) and today when i ran it on another PC, i saw this exception thrown at me. I was using OpenFileDialog and was adding the selected file's details to the database and then refreshing it to the ListView control (getting an exception when running out of VS).
    What amazed me most was that connecting to a single sdf file it was able to connect to at some times, and not at other times.
    I thought it would take another copule of weeks to sort this out. But THANKS to ppl?


    And ya i thought too that the solution wud be a bit complicated but it was simple.
    and with rksty's RestoreDirectory workaround its now just a child's play.


    Vibhor Agarwal
    Thursday, April 14, 2011 11:06 AM
  • @Jose

    Jose I have the same app structure as your app, so can u plz help me these queries.

    App structure - Using VS 2005 (.Net 2.0), WinForms Application, SQL Server 3.0 sdf file., strongly typed datasets, local sdf files(in the same directory as exe)

    1.) I can't add data to table in sdf files, SQL server management studio 2005 express doesnt have an option to add data , however i can create table but not add data.

    2.)If i need to run my app on another PC, what all do i need to install on that PC in addition to .NET Framework 2.0


    Vibhor Agarwal
    Thursday, April 14, 2011 11:20 AM