使用 SQL Server CE 4.0 的 Asp.Net 应用程序导致与多个客户端共享异常
我有一个 ASP.Net 4.0 网站,它使用 SQL Server CE 和 EF 代码优先作为其数据存储。当 2 个或更多用户访问该网站时,我大约每隔 5 或 6 次就会间歇性地收到以下异常。
存在文件共享冲突。可能正在使用不同的过程 文件。 [D:\目录...\文件.sdf]。
在整个代码中,每次需要时,我都会创建、使用并及时处置 DbContext
。尽管这是默认设置,但我已将 File Mode = Read Write
添加到连接字符串中。
任何想法我可能做错了什么。
I have an ASP.Net 4.0 website which uses SQL Server CE and EF code-first for its data store. When 2 or more users are on the site I intermittently get the following exception about every 5th or 6th time.
There is a file sharing violation. A different process might be using
the file. [D:\directory...\file.sdf].
Throughout the code I create, use, and promptly dispose of the DbContext
each time one is needed. Even though it is the default, I have added File Mode = Read Write
to the connection string.
Any ideas what I might be doing wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我明白发生了什么。我找到了一个链接(不幸的是我不记得在哪里),其中提到 GoDaddy 共享托管使用负载均衡器和多个服务器来为站点提供服务。尽管数据库文件显示在使用驱动器号安装的驱动器上,但显然它必须位于所有网络服务器共享的文件服务器上。
多个客户端通过网络使用 SQL CE 是不受支持的配置。当我从 SQL Compact 升级到 GoDaddy 提供的 SQL Server 实例时,这个问题(以及我上面没有提到的另一个数据一致性问题)就消失了。
我有点惊讶的是,当我用谷歌搜索时没有发现这个问题。 Microsoft 正在将 SQL Compact 营销为小型网站的良好后端。如果我是对的,这似乎是这方面的重大责任。
I think I figure out what happened. I found a link (unfortunately I do not recall where), that mentions that Go Daddy shared hosting uses a load balancer and multiple servers to serve the site. Even though the database file shows up on a drive mounted with a drive letter, clearly it must be located on a file server that all the webservers share.
Using SQL CE by multiple clients over a network is a nonsupported configuration. When I upgraded from SQL Compact to a SQL Server Instance provided by Go Daddy, the problem (and another data consistency problem I did not mention above) went away.
I am a little surprised that I did not find this problem when I googled it. Microsoft is pmarketing SQL Compact as a good back end for small website. If I am correct, this seems to be a significant liability in that regard.