Condividi tramite


SqlCeEngine.Compact Method

Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

Reclaims wasted space in the SQL Server CE database. The Compact method is also used to change the collating order, encryption, or password of the SQL Server CE database. For more information, see the SQL Server CE Books Online.

  [Visual Basic]
  Public Sub Compact( _
   ByVal 
  destConnect
   As String _
)
[C#]
public void Compact(string destConnect
);
[C++]
public: void Compact(String* destConnect
);
[JScript]
public function Compact(
   destConnect : String);

Parameters

  • destConnect
    destination connection string

Remarks

The connection string destConnect specifies a connection to the destination database to be created by the Compact method. If the database specified already exists, or another file with the same name already exists, the .NET Compact Framework data provider for SQL Server CE will throw an exception.

Example

[Visual Basic, C#] The following example shows how to compact a SQL Server CE database.

  [Visual Basic] 
Dim src  As String = "Northwind.sdf"
Dim dest As String = "Northwind.sdf.tmp"
      
Dim engine As New SqlCeEngine("Data Source = " + src)
engine.Compact(("Data Source = " + dest))
engine.Dispose()
      
File.Delete(src)
File.Move(dest, src)

[C#] 
string src     = "Northwind.sdf";
string dest    = "Northwind.sdf.tmp";
 
SqlCeEngine engine = new SqlCeEngine("Data Source = " + src);
engine.Compact("Data Source = " + dest);
engine.Dispose();

File.Delete(src);
File.Move(dest, src); 

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: .NET Compact Framework

.NET Framework Security:

See Also

SqlCeEngine Class | SqlCeEngine Members | System.Data.SqlServerCe Namespace

Syntax based on .NET Framework version 1.1.
Documentation version 1.1.1.

Send comments on this topic.

© Microsoft Corporation. All rights reserved.