0

我有一个用 ASP.NET 网页编写的个人网站,带有一个小型 SQL Server Compact Edition 数据库。这对我来说很方便,因为数据库存储为文件 (.sdf),当我添加、修改或删除任何记录并在本地测试时,我可以在 WebMatrix 中使用 Publish... 并复制 .sdf 文件超过。

这很好用,除了我在访问 .sdf 文件时收到的随机错误消息。

我得到... There is a file sharing violation. A different process might be using the file.

有时页面刷新会解决它,有时我必须刷新页面几次。我想将数据库迁移到 SQL Server 数据库会修复它,但我真的不想这样做。这是最好的选择吗?

这是该网站的链接,也许您会遇到错误:http ://www.garethlewisweb.com

有什么我必须在代码中更改的地方,还是我需要要求我的托管公司更改某些内容。我在这方面真的没有太多经验。

谢谢!

更新

这是我的代码

_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";
}

默认.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

不是这个特定问题的真正答案,但迁移到 SQL Server 解决了这个问题。

于 2012-07-05T08:29:24.767 回答
0

当我们添加 Mode=Read Only; 连接字符串中的 Temp Path=c:/Temp 然后修复。

  <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>

它对我们有用!

于 2014-12-17T18:55:59.017 回答