I have a personal website written in ASP.NET Web Pages, with a small SQL Server Compact Edition database. This is handy for me because the database is stored as a file (.sdf), and when I add, modify or delete any records and test it out locally, I can just use Publish... in WebMatrix and copy the .sdf file over.
This works great except for a random error message I get when it accesses the .sdf file.
I get...
There is a file sharing violation. A different process might be using the file.
Sometimes a page refresh will fix it, sometimes I have to refresh the page a couple of times. I suppose migrating the database to a SQL Server database will fix it, but I don't really want to do that. Is that the best option though?
Here's a link to the site, maybe you'll hit the error: http://www.garethlewisweb.com
Is there something I have to change in the code, or will I need to ask my hosting company to change something. I don't really have a lot of experience in this area.
Thanks!
Update
Here's my code
_AppStart.cshtml
@{
WebSecurity.InitializeDatabaseConnection("GarethLewisWeb", "UserProfile", "UserId", "Email", true);
// WebMail.SmtpServer = "mailserver.example.com";
// WebMail.EnableSsl = true;
// WebMail.UserName = "username@example.com";
// WebMail.Password = "your-password";
// WebMail.From = "your-name-here@example.com";
}
Default.cshtml
@{
Layout = "~/Shared/_SiteLayout.cshtml";
Page.Title = "Home";
var db = Database.Open("GarethLewisWeb");
var featuredPhotoSQL = " SELECT col " +
" FROM tablename ";
var featuredPhoto = db.QuerySingle(featuredPhotoSQL);
}
[Lots of HTML and C# code here...]