SQL CE 3.5&的EntityFramework [英] SQL CE 3.5 & EntityFramework
问题描述
这是一个用于构建连接字符串的方法
I have an sqlce 3.5 local db file in my VS2010 solution used with an EF4 Model. I need to protect my db with a password but do not serialize it in app.config. I also need to set up the maximum database file size to it's maximum allowed value which is 4091 MB when I try to set the connectionString in code, I can't find a way to set the 'Max Database Size=4091'.
Here is a method that I use to build the connection string
有没有人知道我该怎么做?
非常感谢
private string GetConnectionString() {
// Specify the provider name, server and database.
string providerName = "System.Data.SqlServerCe.3.5";
string dataSource = @"|DataDirectory|\Database\dbFileName.sdf";
string password = "mypassword";
// Initialize the connection string builder for the underlying provider.
SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder();
// Set the properties for the data source.
sqlBuilder.DataSource = dataSource;
sqlBuilder.Password = password;
// Build the SqlConnection connection string.
string providerString = sqlBuilder.ToString();
// Initialize the EntityConnectionStringBuilder.
EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();
//Set the provider name.
entityBuilder.Provider = providerName;
// Set the provider-specific connection string.
entityBuilder.ProviderConnectionString = providerString;
// Set the Metadata location.
entityBuilder.Metadata = @"res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl";
return entityBuilder.ToString();
}
任何其他方法来获取:
-
密码保护+密码设置代码
Any other way to get:
最大数据库文件= 4091 MB
Password protection + password set up in code
推荐答案
当我使用DbContext构造函数并尝试使用不同的连接字符串时,我遇到相同的错误。如果我使用SqlCeConnection,类似的连接字符串工作正常。这个工作很好
I am getting the same error when I use DbContext constructor and have tried using different connection strings. A similar connection string works fine if I use SqlCeConnection. This works fine
SQL_CONNECTION_STRING = String.Format("password={0};Persist Security Info=True;Data Source={1};Max Database Size=1024", scsb.Password, ccdaSetup.DataSource);
这篇关于SQL CE 3.5&的EntityFramework的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!