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