views:

94

answers:

1

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();
    }

Does anyone have any idea how I should do this? Thank you very much

Any other way to get:

  • Password protection + password set up in code

  • Maximum db file = 4091 MB

A: 

Do not use the SqlConnectionStringBuilder, it is designed for SQL Server connections, not for SQL Server Compact. Simply set

string providerString = @"Data Source=|DataDirectory|\Database\dbFileName.sdf;Password=abc;Max Database Size=4091"; 
ErikEJ
I tried this but I have this errorKeyword not supported '|datadirectory|\database\dbfileName.sdf;password'
mfaqir
Should be better now
ErikEJ