Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 3.0
Class Library
SqlCeEngine Class
SqlCeEngine Methods
 Compact Method
Collapse All/Expand All Collapse All
This page is specific to
.NET Framework 3.0

Other versions are also available for the following:
SqlCeEngine.Compact Method
Reclaims wasted space in the SQL Server Compact Edition database by creating a new database file from the existing file. This method is also used to change the collating order, encryption, or password settings of the database.

Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll)

Visual Basic (Declaration)
Public Sub Compact ( _
    connectionString As String _
)
Visual Basic (Usage)
Dim instance As SqlCeEngine
Dim connectionString As String

instance.Compact(connectionString)
C#
public void Compact (
    string connectionString
)
C++
public:
void Compact (
    String^ connectionString
)
J#
public void Compact (
    String connectionString
)
JScript
public function Compact (
    connectionString : String
)
XAML
Not applicable.

Parameters

connectionString

The connection string to the destination database.

The connection string specifies a connection to the destination database that will be created by this method.

An exception is thrown if the specified database already exists or if another file with the same name already exists. .

If you pass an empty string for the connection string, the new database file overwrites the old database file and maintains the same name.

The following example demonstrates how to compact a SQL Server Compact Edition database.

Visual Basic
Dim engine As New SqlCeEngine("Data Source = AdventureWorks.sdf")

' Specify null destination connection string for in-place compaction
'
engine.Compact(Nothing)

' Specify connection string for new database options; The following 
' tokens are valid:
'      - Password
'      - LCID
'      - Encrypt
' 
' All other SqlCeConnection.ConnectionString tokens are ignored
'
engine.Compact("Data Source=; Password =a@3!7f$dQ;")
C#
SqlCeEngine engine = new SqlCeEngine("Data Source = AdventureWorks.sdf");

// Specify null destination connection string for in-place compaction
//
engine.Compact(null);

// Specify connection string for new database options; The following 
// tokens are valid:
//      - Password
//      - LCID
//      - Encrypt
// 
// All other SqlCeConnection.ConnectionString tokens are ignored
//
engine.Compact("Data Source=; Password =a@3!7f$dQ;");

Windows CE, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows XP Professional x64 Edition, Windows XP SP2

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

.NET Compact Framework

Supported in: 2.0, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker