本文整理汇总了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();
}
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}