Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the SQL Server Compact file?

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.

like image 472
Larsenal Avatar asked Mar 10 '26 17:03

Larsenal


1 Answers

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.

like image 161
mtazva Avatar answered Mar 12 '26 06:03

mtazva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!