0

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...]
4

3 に答える 3

2

Well, you know- that is like trying to wash dishes in an oven. It won't work.

Basically - most likely you try to create multiple instances of SQL Server CE and then use the same DB and guess what - the old one still has the exclusive lock.

In general, you CAN NOT USE SQL CE ON A WEBSITE. It is not made for concurrent access, and even if you are one of the few, that is like asking for trouble. Google comes around, a fiend comes around, and occaionally your browser comes around with 2 requests that overlap and boom - dead.

You do not show any code, so I can only guess what causes the problem, but the documentation for CE is QUITE strict - it is NOT for multi threaded scenarios.

于 2012-06-19T18:38:27.830 に答える
0

Not really an answer to this specific problem, but the migration to SQL Server solved this issue.

于 2012-07-05T08:29:24.767 に答える
0

When we added Mode=Read Only; Temp Path=c:/Temp in the connection string then it fixed.

  <connectionStrings>
      <add name="XYZ" providerName="System.Data.SqlServerCe.4.0" connectionString="Data Source=|DataDirectory|\XYZ.sdf;Max Database Size = 4091;Enlist=false;encryption mode=engine default;password=!secret!;Mode = Read Only;Temp Path=c:/temp" />
  </connectionStrings>

It worked for us !

于 2014-12-17T18:55:59.017 に答える