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


C# SqlCeEngine.Shrink方法代码示例

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


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

示例1: ShrinkDatabase

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

示例2: StartInternal

        protected override void StartInternal()
        {
            Environment.CurrentDirectory = AppConfig.InstallationPath;

            using (SqlCeEngine eng = new SqlCeEngine("Data Source = Persistence.sdf"))
            {
                eng.Shrink();
            }

            string address = "net.pipe://localhost/PersistenceService.svc";

            NetNamedPipeBinding binding = new NetNamedPipeBinding();
            binding.MaxReceivedMessageSize = int.MaxValue;
            binding.ReaderQuotas.MaxStringContentLength = int.MaxValue;

            _host = new ServiceHost(typeof(PersistenceServiceImpl));
            _host.AddServiceEndpoint(typeof(IPersistenceService), binding, address);

            _host.Open();
        }
开发者ID:rraguso,项目名称:protone-suite,代码行数:20,代码来源:ServiceHelper.cs

示例3: Shrink

        public bool Shrink()
        {
            bool curReturn = true;
            System.Data.SqlServerCe.SqlCeEngine mySqlEngine = new SqlCeEngine();

            try {
                String curSqlStmt = "";
                mySqlEngine.LocalConnectionString = Properties.Settings.Default.waterskiConnectionStringApp;
                mySqlEngine.Shrink();
                MessageBox.Show( "Compression complete for connection \n" + mySqlEngine.LocalConnectionString );

            } catch ( Exception ex ) {
                curReturn = false;
                MessageBox.Show( "Error attempting to shrink database"
                    + "Database connection: " + mySqlEngine.LocalConnectionString
                    + "\n\nError: " + ex.Message );
            }

            return curReturn;
        }
开发者ID:WaterskiScoring,项目名称:WaterskiScoringSystem,代码行数:20,代码来源:ShrinkDatabase.cs

示例4: execCommandFile

        public bool execCommandFile()
        {
            bool curReturn = true;
            int curDelimIdx;
            decimal curDatabaseVersion = 9999.00M;
            String inputBuffer, curSqlStmt = "";
            StringBuilder curInputCmd = new StringBuilder( "" );
            ImportData curImportData = new ImportData();
            StreamReader myReader;
            myProgressInfo = new ProgressWindow();

            #region Process all commands in the input file
            myReader = getImportFile();
            if ( myReader != null ) {
                int curInputLineCount = 0;
                try {
                    while ( ( inputBuffer = myReader.ReadLine() ) != null ) {
                        curInputLineCount++;
                        myProgressInfo.setProgressValue( curInputLineCount );

                        if ( inputBuffer.TrimStart( ' ' ).StartsWith( "## " ) ) {
                            curDatabaseVersion = Convert.ToDecimal( inputBuffer.Substring( 4 ) );
                        }
                        if ( inputBuffer.TrimStart( ' ' ).StartsWith( "//" ) || inputBuffer.TrimStart( ' ' ).StartsWith( "##" ) ) {
                        } else {
                            if ( curDatabaseVersion > myDatabaseVersion ) {
                                curDelimIdx = inputBuffer.IndexOf( ';' );
                                if ( curDelimIdx >= 0 ) {
                                    if ( curDelimIdx > 0 ) {
                                        curInputCmd.Append( inputBuffer.Substring( 0, curDelimIdx ) );
                                    }
                                    curSqlStmt = curInputCmd.ToString();
                                    curSqlStmt.TrimStart( ' ' );
                                    if ( curSqlStmt.Trim().ToUpper().StartsWith( "DROP " ) ) {
                                        execDropTable( replaceLinefeed( curSqlStmt ) );
                                    } else if ( curSqlStmt.Trim().ToUpper().StartsWith( "CREATE " ) ) {
                                        execCreateTable( replaceLinefeed( curSqlStmt ) );
                                        curInputCmd = new StringBuilder( "" );
                                    } else {
                                        execSchemaCmd( replaceLinefeed( curSqlStmt ) );
                                    }
                                    curInputCmd = new StringBuilder( "" );

                                } else {
                                    curInputCmd.Append( inputBuffer );
                                }
                            }
                        }
                    }
                    curSqlStmt = "";
                    System.Data.SqlServerCe.SqlCeEngine mySqlEngine = new SqlCeEngine();
                    mySqlEngine.LocalConnectionString = Properties.Settings.Default.waterskiConnectionStringApp;
                    mySqlEngine.Shrink();

                } catch ( Exception ex ) {
                    curReturn = false;
                    String ExcpMsg = ex.Message;
                    if ( mySqlStmt != null ) {
                        ExcpMsg += "\n" + curSqlStmt;
                    }
                    MessageBox.Show( "Error attempting to update database schema" + "\n\nError: " + ExcpMsg );
                }
            }
            #endregion

            myProgressInfo.Close();
            return curReturn;
        }
开发者ID:WaterskiScoring,项目名称:WaterskiScoringSystem,代码行数:68,代码来源:DatabaseTools.cs

示例5: updateSchema

        private bool updateSchema(String inFileRef)
        {
            bool curReturnValue = true;
            int curDelimIdx;
            String inputBuffer, curSqlStmt = "";
            StringBuilder curInputCmd = new StringBuilder( "" );
            ImportData curImportData = new ImportData();
            StreamReader myReader;
            myProgressInfo = new ProgressWindow();

            try {
                #region Process all commands in the input file
                myReader = getImportFile( inFileRef );
                if ( myReader != null ) {
                    int curInputLineCount = 0;
                    try {
                        MessageBox.Show( "Your database is about to be upgraded.  Please click OK or continue to any dialogs." );

                        while ( ( inputBuffer = myReader.ReadLine() ) != null ) {
                            curInputLineCount++;
                            myProgressInfo.setProgressValue( curInputLineCount );

                            if ( inputBuffer.TrimStart( ' ' ).StartsWith( "//" ) ) {
                            } else {
                                curDelimIdx = inputBuffer.IndexOf( ';' );
                                if ( curDelimIdx >= 0 ) {
                                    if ( curDelimIdx > 0 ) {
                                        curInputCmd.Append( inputBuffer.Substring( 0, curDelimIdx ) );
                                    }
                                    curSqlStmt = curInputCmd.ToString();
                                    curSqlStmt.TrimStart( ' ' );
                                    if ( curSqlStmt.Trim().ToUpper().StartsWith( "DROP " ) ) {
                                        execDropTable( replaceLinefeed(curSqlStmt) );
                                    } else if ( curSqlStmt.Trim().ToUpper().StartsWith( "CREATE " ) ) {
                                        execCreateTable( replaceLinefeed(curSqlStmt) );
                                        curInputCmd = new StringBuilder( "" );
                                    } else {
                                        execSchemaCmd( replaceLinefeed(curSqlStmt) );
                                    }
                                    curInputCmd = new StringBuilder( "" );

                                } else {
                                    curInputCmd.Append( inputBuffer );
                                }
                            }

                        }
                        curSqlStmt = "";
                        System.Data.SqlServerCe.SqlCeEngine mySqlEngine = new SqlCeEngine();
                        mySqlEngine.LocalConnectionString = Properties.Settings.Default.waterskiConnectionStringApp;
                        mySqlEngine.Shrink();

                    } catch ( Exception ex ) {
                        curReturnValue = false;
                        String ExcpMsg = ex.Message;
                        if ( mySqlStmt != null ) {
                            ExcpMsg += "\n" + curSqlStmt;
                        }
                        MessageBox.Show( "Error attempting to update database schema" + "\n\nError: " + ExcpMsg );
                    }
                }
                #endregion

            } catch ( Exception ex ) {
                curReturnValue = false;
                String ExcpMsg = ex.Message;
                if ( mySqlStmt != null ) {
                    ExcpMsg += "\n" + mySqlStmt.CommandText;
                }
                MessageBox.Show( "Error attempting to update database schema" + "\n\nError: " + ExcpMsg );
            }
            myProgressInfo.Close();

            return curReturnValue;
        }
开发者ID:WaterskiScoring,项目名称:WaterskiScoringSystem,代码行数:75,代码来源:UpgradeDatabase.cs

示例6: DatabaseHandler

        /// <summary>
        /// Database saving handler
        /// </summary>
        /// <param name="repeatedly">should it go indefinatly? just for background thread</param>
        private static void DatabaseHandler(bool repeatedly)
        {
            DateTime lastcheck = DateTime.MinValue;
            while (true)
            {
                //store all audit records
                using (DNSAdminEntities db = new DNSAdminEntities())
                {
                    AuditRecord auditrec = null;
                    while (auditrecords.TryDequeue(out auditrec))
                    {
                        db.AuditRecords.AddObject(auditrec);
                    }
                    db.SaveChanges();
                    db.AcceptAllChanges();
                }

                //check 10 minutes passed
                if ((DateTime.UtcNow - lastcheck).TotalMinutes > 10)
                {
                    lastcheck = DateTime.UtcNow;
                    //remove old records
                    int removeitems = 0;
                    using (DNSAdminEntities db = new DNSAdminEntities())
                    {
                        var deletelist = db.AuditRecords.OrderByDescending(i => i.TimestampUTC).ToList().Skip(AuditMediaDBMaximumRecords).ToList();
                        removeitems = deletelist.Count();
                        foreach (var item in deletelist)
                            db.DeleteObject(item);
                        db.SaveChanges();
                        db.AcceptAllChanges();
                    }
                    //if any records removed, compact database
                    if (removeitems > 0)
                    {
                        using (SqlCeEngine engine = new SqlCeEngine("Data Source = |DataDirectory|\\DNSAdmin.sdf"))
                        {
                            engine.Shrink();
                        }
                    }
                }

                if (repeatedly)
                    Thread.Sleep(5000);
                else
                    break;
            }
        }
开发者ID:drorgl,项目名称:MSDNSWebAdmin,代码行数:52,代码来源:Audit.cs


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