3

I have an ASP.NET MVC project that uses a SQL Server Compact database. I have the following connection string for my FoobarContext:

<add name="FoobarContext"
 connectionString="Data Source=|DataDirectory|Foobar.sdf"
 providerName="System.Data.SqlServerCe.4.0"/>

I fired up the project and it appears to persist data as expected. However, I can't find a file named 'Foobar.sdf' anywhere. What am I missing?

Update: It wasn't taking my connection string. Setting a breakpoint and inspecting the context, I found its ConnectionString was actually the following:

Data Source=.\\SQLEXPRESS;Initial Catalog=MvcApplication3.Infrastructure.Data.FoobarContext;Integrated Security=True;MultipleActiveResultSets=True

Mystery solved.

Larsenal
  • 49,878
  • 43
  • 152
  • 220

3 Answers3

3

It definitely should be ~/App_Data by default, but you can try running AppDomain.CurrentDomain.GetData("DataDirectory") to see where ASP.Net thinks the directory exists.

If this reveals nothing of interest, you may want to make sure your windows explorer is set to show hidden files, just in case that's why you don't see the file.

mtazva
  • 1,005
  • 9
  • 13
0

It should be in a folder called App_Data off the root of your MVC project.

Nathan Fisher
  • 7,961
  • 3
  • 47
  • 68
  • 1
    That's what I expected, but there's no sdf file. There is a file named 'ASPNETDB.MDF' and a file named 'aspnetdb_log.ldf'. – Larsenal Sep 08 '11 at 04:43
  • this question should help you out http://stackoverflow.com/questions/1268738/asp-net-mvc-find-absolute-path-to-the-app-data-folder-from-controller – Nathan Fisher Sep 08 '11 at 04:53
  • I'm able to find the App_Data folder on disk just fine. Just can't find the expected sdf file. – Larsenal Sep 08 '11 at 05:02
  • Thats cool, I knew what you meant, I thought that if you could display the App_Data path that the application is using it might give you a clue as to where the file is – Nathan Fisher Sep 08 '11 at 05:48
  • Alternativly put a breakpoint on the context and have a look a the connectionstring to see if that gives you any clues as to the location – Nathan Fisher Sep 08 '11 at 06:26
  • Looking at your update. it looks as though your using Sql Server express rather than Sql Ce – Nathan Fisher Sep 08 '11 at 15:15
  • I wasn't intending to use SQL Server Express. I had put the connection string in the "debug" version of the web.config, and apparently did that incorrectly. So the framework apparently fell back to using SQL Server Express locally. Graceful, but strange. – Larsenal Sep 08 '11 at 15:33
0

you should be stingy on the app folder in your project, the database file you'll find inside.

Regards