0

My environment Windows 8 Pro with Visual Studio 2010 Ultimate with WP 7.1.1 SDK installed.

I have a WP 7.1.1 application with a SQL CE database. There are 2 databases, the one that comes with the initial package and another stored in Isolated Storage. On Application_Launching the code compares the version of both databases and if the one from the package is greater it replaces the one from Isolated Storage. On the first run of the app with the simulator closed, the app starts fine and copies the database to isolate storage. On the second run The following code:

using (SportsDataContext db = new SportsDataContext(DBConnectionString))
{
  var setting = db.Settings.Where(s => s.SettingID == (Int16)Settings.DatabaseVersion).SingleOrDefault();
  if (setting == null)
    return false;
  newVersion = setting.Value;
}

Throws the exception:

Access to the database file is not allowed. [ 1981,File name = \Applications\Install\{GUID}\Install\{FileName}.sdf,SeCreateFile ]

Also, leaving the emulator running and uninstalling the app and re running it makes it work.

UPDATE The reason it works on the first run is because the code above is not executed (on purpose). Running it again makes the code above run and bomb.

This used to work fine before on Windows 7 and without VS 2012. What might be causing the problem?

UPDATE I reverted all my changes back prior to making any changes with my new Windows 8 setup and it works as expected. As soon as I open the sdf file with VS 2010 using Server Explorer and modify it I get the same problem when debugging the app. Weird!

Jonas Stawski
  • 6,682
  • 6
  • 61
  • 106
  • How do you compare the version of the two databases? With a query? – Kevin Gosse Sep 17 '12 at 17:37
  • Yes, I store it in a table within the database – Jonas Stawski Sep 17 '12 at 17:43
  • Can you show the code you're using to copy the file to the isolated storage? Maybe you're leaving a handle open, thus locking the file. – Kevin Gosse Sep 17 '12 at 18:11
  • Using the same code specified in this url http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh286411(v=vs.92).aspx under To copy the reference database to isolated storage. Also, this code always worked fine under Windows 7 without VS 2012 and SQL Server 2012 installed. Maybe the fact that SQL Compact 4.0 is installed has something to do with this? – Jonas Stawski Sep 17 '12 at 18:18
  • I updated my question with more info! – Jonas Stawski Sep 17 '12 at 18:43

1 Answers1

0

Currently Mango supports 3.5 CE, install SQL CE 3.5 from here http://www.microsoft.com/en-us/download/details.aspx?id=12264 and that should do the trick

Sharjeel Ahmed
  • 2,051
  • 2
  • 17
  • 25