使用只读连接打开SqlCeException数据库

时间:2022-09-11 17:14:47

We store a template for building SQL Server CE connection strings in our web.config and use string.format to set the data source and temp path values.

我们在web.config中存储用于构建SQL Server CE连接字符串的模板,并使用string.format设置数据源和临时路径值。

In the web.config, the template for the DB connection string is:

在web.config中,数据库连接字符串的模板是:

"Data Source={0}; Temp Path={1}; Mode=Read Only" 

In the web.release.config, we use to build deployment packages, the template for the DB connection string is:

在web.release.config中,我们使用构建部署包,数据库连接字符串的模板是:

Data Source={0}; Temp Path={1} 

Now we only use the SQL Server CE database for read only operations. So, being a smartypants, I thought I would remove the connection string transform in the web.release.config and just always use the read only connection string from the web.config.

现在我们只使用SQL Server CE数据库进行只读操作。因此,作为一个smartypants,我想我会删除web.release.config中的连接字符串转换,并始终使用web.config中的只读连接字符串。

This worked fine for the database I was testing. But the same code running with a different SQL Server CE database fails with the following exception:

这对我正在测试的数据库工作得很好。但是,使用不同SQL Server CE数据库运行的相同代码失败,并出现以下异常:

Exception 'System.Data.SqlServerCe.SqlCeException' with message 'The database is opened with a read-only connection. Can't perform post-initialization operations like re-building indexes and upgrading public tracking. Please re-open with a read-write connection. [ Database name = D:\inetpub\wwwroot\MyApp\App_Data\Storage.sdf ]'

异常'System.Data.SqlServerCe.SqlCeException',带有消息'使用只读连接打开数据库。无法执行后期初始化操作,如重建索引和升级公共跟踪。请使用读写连接重新打开。 [数据库名称= D:\ inetpub \ wwwroot \ MyApp \ App_Data \ Storage.sdf]'

We are using the System.Data.SqlServerCe.4.0 provider

我们正在使用System.Data.SqlServerCe.4.0提供程序

Why in my release build that is deployed to a server does read only access fail for some SQL Server CE databases but not others? It is the same code, just pointing at a different .SDF file. The .SDF files have the same schema, just different data.

为什么在我的部署到服务器的发布版本中,对于某些SQL Server CE数据库而不是其他SQL Server CE数据库,只读访问失败?它是相同的代码,只是指向不同的.SDF文件。 .SDF文件具有相同的模式,只是不同的数据。

Is the driver trying to rebuild indexes because the .SDF file is in some older format? Should we never use a readonly connection in production? Is that why the original code had the transform? why do they all work with a readonly connection on my Windows 7 workstation?

驱动程序是否尝试重建索引,因为.SDF文件是某种较旧的格式?我们是否应该在生产中使用只读连接?这就是为什么原始代码有变换的原因?为什么他们都在我的Windows 7工作站上使用只读连接?

1 个解决方案

#1


0  

You should always specify a temp path, as moving databases between OS platforms/versions can require index rebuilds.

您应该始终指定临时路径,因为在OS平台/版本之间移动数据库可能需要索引重建。

See my blog post post here: http://erikej.blogspot.dk/2009/08/running-sql-compact-from-cd-rom-read.html for more detailed info.

有关更多详细信息,请参阅我的博客文章:http://erikej.blogspot.dk/2009/08/running-sql-compact-from-cd-rom-read.html。

#1


0  

You should always specify a temp path, as moving databases between OS platforms/versions can require index rebuilds.

您应该始终指定临时路径,因为在OS平台/版本之间移动数据库可能需要索引重建。

See my blog post post here: http://erikej.blogspot.dk/2009/08/running-sql-compact-from-cd-rom-read.html for more detailed info.

有关更多详细信息,请参阅我的博客文章:http://erikej.blogspot.dk/2009/08/running-sql-compact-from-cd-rom-read.html。