SqlServerCe 4.0“数据库已由不同用户打开”错误
我正在使用位于 Asp.Net 应用程序的 /App_Data/ 文件夹中的 SqlServerCe 4.0 数据库 - 在本例中由 IISExpress 通过 WebMatrix 托管。还可以通过 Microsoft WebMatrix 扩展访问该数据库 - 该扩展在 WebMatrix.exe 进程中运行。只要 WebMatrix 扩展或 Asp.Net 应用程序都是第一个访问的,则都可以正常访问数据库 - 如果访问应用程序是第二个打开连接的应用程序,则会返回以下错误:
Database already opened by a different user. [ Db name = ... ] : at System.Data.SqlServerCe.SqlCeConnection.ProcessResults(Int32 hr)
at System.Data.SqlServerCe.SqlCeConnection.Open(Boolean silent)
at System.Data.SqlServerCe.SqlCeConnection.Open()
The code opening the来自 WebMatrix 扩展的连接是:
SqlCeConnection conn = new SqlCeConnection("DataSource=" + dbPath + "\\App_Data\\db.sdf");
conn.Open();
SqlCeCommand cmd = new SqlCeCommand("select ...", conn);
SqlCeDataReader r = cmd.ExecuteReader();
在 conn.Open() 行上抛出异常。
我正在运行最新的SqlServerCe 4.0位,并尝试以管理员身份运行WebMatrix,但结果与上面一致。这方面的搜索结果很少。
——保罗
I am working with a SqlServerCe 4.0 database located in an Asp.Net app's /App_Data/ folder - in this case hosted by IISExpress via WebMatrix. The database is also accessed from a Microsoft WebMatrix Extension - which runs in the WebMatrix.exe process. Either the WebMatrix Extension or the Asp.Net app can access the database just fine as long as each is the first to access - in the case the accessing app is the second to open a connection, the following error is returned:
Database already opened by a different user. [ Db name = ... ] : at System.Data.SqlServerCe.SqlCeConnection.ProcessResults(Int32 hr)
at System.Data.SqlServerCe.SqlCeConnection.Open(Boolean silent)
at System.Data.SqlServerCe.SqlCeConnection.Open()
The code opening the connection from the WebMatrix Extension is:
SqlCeConnection conn = new SqlCeConnection("DataSource=" + dbPath + "\\App_Data\\db.sdf");
conn.Open();
SqlCeCommand cmd = new SqlCeCommand("select ...", conn);
SqlCeDataReader r = cmd.ExecuteReader();
Which throws the exception on the conn.Open() line.
I am running the latest SqlServerCe 4.0 bits and have tried running WebMatrix as Administrator, but the result is consistent with the above. There is precious little in terms of search results for this.
-Paul
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论