简体   繁体   English

如果我的连接字符串包含max database size关键字,为什么SQL Server Compact Edition无法打开现有的SDF文件?

[英]Why can't SQL Server Compact Edition open an existing SDF file if my connection string contains the max database size keyword?

I keep seeing this exception: 我一直看到这个异常:

ex = {"Keyword not supported: 'max database size'."} ex = {“不支持关键字:“最大数据库大小”。”}

When I try running the following code (exception is thrown on the LINQ query line): 当我尝试运行以下代码时(在LINQ查询行上引发了异常):

LogContext l = new LogContext(connectionString);
var v = from log in l.Logs select log;
count += v.Count();

The LogContext class looks like this: LogContext类如下所示:

public class LogContext : DbContext
{
    public LogContext()
        : base()
    {
    }
    public LogContext(string connectionString)
        : base(connectionString)
    {
    }
    public DbSet<LogRecord> Logs { get; set; }
}

My connection string contains the Max Database Size property. 我的连接字符串包含“ Max Database Size属性。 Is there a reason why its throwing this exception? 它引发此异常有原因吗? Does SQL Server Compact Edition use the Max Database Size property only once for creating the database and stores this information in the local file or something, such that I can't connect to this file when I specify this property thereafter? SQL Server Compact Edition是否仅使用一次“ Max Database Size属性来创建数据库,并将此信息存储在本地文件或其他内容中,这样以后在指定此属性后便无法连接到该文件? Because this all works when I create new databases. 因为当我创建新数据库时,所有这些都有效。

Setting the DefaultConnectionFactory seemed to work for me: 设置DefaultConnectionFactory似乎对我有用:

Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0"); Database.DefaultConnectionFactory =新的SqlCeConnectionFactory(“ System.Data.SqlServerCe.4.0”);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 检查 Sql Server Compact Database(.sdf) 是否包含未连接的内容 - Check if Sql Server Compact Database(.sdf) contains something without connecting 无法提交对SQL Server Compact Edition数据库的更改 - Can't commit changes to SQL Server Compact Edition database 以编程方式确定SQL Server Compact sdf文件的大小 - Programmatically determine the size of a SQL Server Compact sdf file 我可以访问保存在同一网络中其他计算机上的sdf(SQL Server Compact数据库文件)吗? - Can I access sdf (SQL Server Compact database file) kept at some other computer on the same network? 增加 sql compact 3.5 .sdf 文件的大小 - Increase the size of sql compact 3.5 .sdf file 修改SQL Server Compact Edition的默认连接字符串 - Modify default connection string for SQL Server Compact Edition 使用sdf数据库(SQL Server Compact 3.5数据库文件)而不安装Microsoft sql server C# - Use sdf database(SQL Server Compact 3.5 database file) without installing Microsoft sql server C# 在ReportViewer .Net 4.0中使用Sql Server Compact Edition数据库文件 - Use Sql Server Compact Edition Database File in ReportViewer .Net 4.0 为什么我不能用C#将数据插入本地数据库(SQL Compact Edition)? - Why can't I insert data into local database (SQL Compact Edition) with C#? 无法在SQL Server Compact Edition中删除有条件的数据 - Can't delete data with condition in SQL Server Compact Edition
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM