当前位置: 首页>>代码示例>>C#>>正文


C# SqlCeEngine.Compact方法代码示例

本文整理汇总了C#中SqlCeEngine.Compact方法的典型用法代码示例。如果您正苦于以下问题:C# SqlCeEngine.Compact方法的具体用法?C# SqlCeEngine.Compact怎么用?C# SqlCeEngine.Compact使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SqlCeEngine的用法示例。


在下文中一共展示了SqlCeEngine.Compact方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CompactDatabase

 public void CompactDatabase(string connectionString)
 {
     using (SqlCeEngine engine = new SqlCeEngine(connectionString))
     {
         engine.Compact(null);
     }
 }
开发者ID:inickvel,项目名称:SqlCeToolbox,代码行数:7,代码来源:SqlCeHelper.cs

示例2: Compact

 /// <summary>
 /// Reclaims wasted space in the database and recalculates identity column values. Applies only to SQL CE.
 /// </summary>
 internal static void Compact()
 {
     using (SqlCeEngine engine = new SqlCeEngine(Util.ConnectionString))
     {
         engine.Compact(null);
     }
 }
开发者ID:xusun,项目名称:GalleryServerPro,代码行数:10,代码来源:DataUtility.cs

示例3: CopyLM

        /// <summary>
        /// Copies the LM.
        /// </summary>
        /// <returns></returns>
        /// <remarks>Documented by Dev07, 2009-05-20</remarks>
        public static bool CopyLM(string source, string destination)
        {
            try
            {
                string filename = destination;
                if (File.Exists(filename))
                {
                    int i = 0;
                    while (File.Exists(filename.Replace(".mlm", "_" + i + ".mlm"))) i++;
                    filename = filename.Replace(".mlm", "_" + i + ".mlm");
                }

                string sourceConString = MSSQLCEConn.GetFullConnectionString(source);
                string desConString = MSSQLCEConn.GetFullConnectionString(filename);
                SqlCeEngine engine = new SqlCeEngine(sourceConString);
                engine.Compact(desConString);
                engine.Dispose();
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.ToString());
                return false;
            }
            return true;
        }
开发者ID:Stoner19,项目名称:Memory-Lifter,代码行数:30,代码来源:Library.cs

示例4: compactDatabase

        // Calls SQLCE's compactor
        public void compactDatabase()
        {
            string connString = @"Data Source = " + dbPath; // Create connection string for SQLCE DB
            SqlCeEngine engine = new SqlCeEngine(connString); // Instantiate engine object

            // Do the compaction
            engine.Compact(null);
            // We then verify the database, just incase.
            if (!engine.Verify())
            {
                throw new Exception("Database corrupt");
            }
        }
开发者ID:Sunstrike,项目名称:ASLib,代码行数:14,代码来源:ASComicDatabase.cs

示例5: CompactDatabase

 public static void CompactDatabase()
 {
     string src     = ConnectionParamter;
     string dest    = ConnectionParamter+".tmp";
     // Initialize SqlCeEngine object.
     SqlCeEngine engine = new SqlCeEngine("Data Source = " + src);
     try {
        //engine.Repair("Data Source = " + src, RepairOption.DeleteCorruptedRows);
         engine.Compact("Data Source = " + dest);
         engine.Dispose();
         File.Delete(src);
         File.Move(dest, src);
     } catch(SqlCeException e) {
         //Use your own error handling routine.
         //ShowErrors(e);
         CommonUtils.LogError(e.Message,e);
     } finally {
         //Dispose of the SqlCeEngine object.
         engine.Dispose();
     }
 }
开发者ID:mzkabbani,项目名称:cSharpProjects,代码行数:21,代码来源:BackEndUtils.cs

示例6: Compact

        /// <summary>
        /// Упаковать БД
        /// </summary>
        public static bool Compact()
        {
            if (string.IsNullOrEmpty(Conn.ConnectionString))
            {
                return false;
            }
            else
            {
                bool wasConnected = Connected;

                try
                {
                    if (wasConnected)
                        Conn.Close();

                    SqlCeEngine engine = new SqlCeEngine(Conn.ConnectionString);
                    engine.Compact(string.Empty);
                }
                finally
                {
                    if (wasConnected)
                        Conn.Open();
                }

                return true;
            }
        }
开发者ID:iyus,项目名称:scada,代码行数:30,代码来源:AppData.cs

示例7: ImportData


//.........这里部分代码省略.........
            try
            {
                tran = cn.BeginTransaction();

                ClearData(importMembershipData, importGalleryData, cn, tran);

                using (DataSet ds = GenerateDataSet(galleryData))
                {
                    if (importMembershipData)
                    {
                        InsertApplications(ds, cn, tran);

                        InsertRoles(ds, cn, tran);

                        InsertUsers(ds, cn, tran);

                        InsertMembership(ds, cn, tran);

                        InsertUsersInRoles(ds, cn, tran);

                        InsertProfiles(ds, cn, tran);
                    }

                    if (importGalleryData)
                    {
                        InsertGalleries(ds, cn, tran);
                        Pause();

                        InsertAlbums(ds, cn, tran);
                        Pause();

                        InsertGalleryRoles(ds, cn, tran);
                        Pause();

                        InsertRolesAlbums(ds, cn, tran);
                        Pause();

                        InsertMediaObjects(ds, cn, tran);
                        Pause();

                        InsertMediaObjectMetadata(ds, cn, tran);
                        Pause();

                        InsertAppErrors(ds, cn, tran);
                        Pause();

                        InsertAppSettings(ds, cn, tran);
                        Pause();

                        InsertGalleryControlSettings(ds, cn, tran);
                        Pause();

                        InsertGallerySettings(ds, cn, tran);
                        Pause();

                        InsertBrowserTemplates(ds, cn, tran);
                        Pause();

                        InsertMimeTypes(ds, cn, tran);
                        Pause();

                        InsertMimeTypeGalleries(ds, cn, tran);
                        Pause();

                        InsertGalleryProfiles(ds, cn, tran);
                        Pause();
                    }
                }

                tran.Commit();
            }
            catch
            {
                if (tran != null)
                    tran.Rollback();

                throw;
            }
            finally
            {
                if (tran != null)
                    tran.Dispose();

                cn.Close();
            }

            try
            {
                SqlCeEngine engine = new SqlCeEngine(Util.ConnectionString);
                engine.Compact(null);
            }
            catch (SqlCeException)
            {
                // During testing it was observed that calling Compact could result in the error "Could not load database compaction library".
                // But if we pause and try again it succeeds.
                Pause();
                SqlCeEngine engineSecondTry = new SqlCeEngine(Util.ConnectionString);
                engineSecondTry.Compact(null);
            }
        }
开发者ID:xusun,项目名称:GalleryServerPro,代码行数:101,代码来源:DataUtility.cs

示例8: ChangeDatabasePassword

        public string ChangeDatabasePassword(string connectionString, string password)
        {
            if (password == null)
            {
                password = string.Empty;
            }
            using (SqlCeEngine engine = new SqlCeEngine(connectionString))
            {
                engine.Compact(string.Format("Data Source=;Password={0}", password));
            }
#if V40
            var builder = new SqlCeConnectionStringBuilder(connectionString);
            builder.Password = password;
            return builder.ConnectionString;
#else
            return string.Empty;
#endif
        }
开发者ID:inickvel,项目名称:SqlCeToolbox,代码行数:18,代码来源:SqlCeHelper.cs

示例9: CompactSqlCeDb

        /// <summary>
        /// Compacts the SQL CE database. No action is taken for other databases. Besides compacting the database, the
        /// process performs a critical task of resetting the identity columns of all tables. Without this step the app
        /// is at risk of generating the error 'A duplicate value cannot be inserted into a unique index' during a subsequent
        /// insert.
        /// </summary>
        /// <param name="backupFile">The backup file.</param>
        /// <exception cref="CannotCompactSqlCeException">Thrown when the database could not be compacted.</exception>
        private static void CompactSqlCeDb(IBackupFile backupFile)
        {
            if (backupFile.GalleryDataStore != ProviderDataStore.SqlCe)
                return;

            try
            {
                var engine = new SqlCeEngine(backupFile.ConnectionString);
                engine.Compact(null);
            }
            catch (SqlCeException)
            {
                // During testing it was observed that calling Compact could result in the error "Could not load database compaction library".
                // But if we pause and try again it succeeds.
                Pause();
                var engineSecondTry = new SqlCeEngine(backupFile.ConnectionString);
                try
                {
                    engineSecondTry.Compact(null);
                }
                catch (SqlCeException ex)
                {
                    throw new CannotCompactSqlCeException("The database was successfully restored, but it could not be compacted. Navigate to the Site Settings page and manually perform a compaction. Error: " + ex.Message, ex);
                }
            }
        }
开发者ID:Jiyuu,项目名称:galleryserverpro,代码行数:34,代码来源:BackupFileController.cs

示例10: CompactDb

        private void CompactDb()
        {
            try
            {
                main.database.CloseConnection();
                SendMessage("Compacting DB.. vent litt" + Environment.NewLine + "(Dette kan ta en stund)");
                this.Update();
                Log.n("Compacting DB.. vent litt");

                SqlCeEngine eng = new SqlCeEngine(FormMain.SqlConStr);
                eng.Compact(FormMain.SqlConStr);
                //eng.Compact("Data Source=" + Path.Combine(FormMain.settingsPath, @"\db_compacting.sdf"));

                main.database.OpenConnection();

                DBsize();

                Log.n("Compacting av " + FormMain.fileDatabase + " fullført.", Color.Green);
                SendMessage("Ferdig.", Color.Green);

            }
            catch (Exception ex)
            {
                SendMessage("Feil!", Color.Red);
                FormError errorMsg = new FormError("Feil oppstod under database optimalisering", ex);
                errorMsg.ShowDialog(this);
            }
        }
开发者ID:tborgund,项目名称:kgsa,代码行数:28,代码来源:FormSettings.cs

示例11: Compact

        /// <summary>
        /// Reclaims wasted space in the database and recalculates identity column values.
        /// </summary>
        public void Compact()
        {
            using (var engine = new SqlCeEngine(ConnectionString))
            {
                engine.Compact(null);
            }

            // Same thing using Reflection:
            //object sqlCeEngine = null;
            //try
            //{
            //	sqlCeEngine = SqlCeEngineType.InvokeMember(null, BindingFlags.CreateInstance, null, null, new object[] { ConnectionString });

            //	SqlCeEngineType.InvokeMember("Compact", BindingFlags.InvokeMethod, null, sqlCeEngine, new object[] { null });
            //}
            //catch (TargetInvocationException ex)
            //{
            //	AppEventController.LogError(ex.InnerException ?? ex);
            //	throw;
            //}
            //finally
            //{
            //	if (sqlCeEngine != null)
            //		SqlCeEngineType.InvokeMember("Dispose", BindingFlags.InvokeMethod, null, sqlCeEngine, null);
            //}
        }
开发者ID:Jiyuu,项目名称:galleryserverpro,代码行数:29,代码来源:SqlCeController.cs


注:本文中的SqlCeEngine.Compact方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。