Monday, February 20, 2012

Microsoft SQL Server Compact - connection string parameters

SqlCeConnection.ConnectionString Property
http://msdn.microsoft.com/en-us/library/system.data.sqlserverce.sqlceconnection.connectionstring(v=vs.100).aspx

using System;
using System.Data.Entity;
using System.IO;
using System.Data.Entity.Infrastructure;
  
namespace WindowsFormsApplication1
{
    public class DatabaseContext : System.Data.Entity.DbContext
    {
        public DatabaseContext() : base(DatabaseContext.ConnectionString)
        {
            Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");
        }
  
        public static string ConnectionString
        {
            get
            {
                return String.Format(@"Data Source={0}\database.sdf;Max Database Size={1};Max Buffer Size={2}", 
                                    Path.GetTempPath(), 1024, 16384);
            }
        }
  
        [...]
    }
}

No comments :

Post a Comment