방법: 데이터베이스 압축(프로그래밍 방식)

이 항목에서는 SqlServerCe.Engine 개체의 Compact 메서드를 사용하여 Microsoft SQL Server 2005 Compact Edition(SQL Server Compact Edition) 데이터베이스를 압축하는 방법에 대해 설명합니다. SqlServerCe 네임스페이스 사용에 대한 자세한 내용은 SqlServerCe 네임스페이스 참조 설명서를 참조하십시오.

SQL Server Compact Edition 데이터베이스를 압축하려면 다음과 같이 하십시오.

  1. Engine 개체를 생성하고 압축할 기존 데이터베이스에 대한 연결 문자열을 전달합니다.

    SqlCeEngine engine = new SqlCeEngine("Data Source = AdWks.sdf");
    
  2. Compact 메서드를 호출합니다. Compact 메서드를 호출할 때 암호 보호 또는 암호화를 추가하는 등 새 데이터베이스 속성을 지정할 수도 있습니다.

    engine.Compact("Data Source=; Password = a@3!7f$dQ;");
    

다음 예에서는 기존 SQL Server Compact Edition 데이터베이스를 압축한 후 데이터베이스 속성을 변경하는 방법을 보여 줍니다.

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;");
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;")

참고 항목

개념

데이터베이스 유지 관리(SQL Server Compact Edition)
일반 데이터베이스 작업(SQL Server Compact Edition)

도움말 및 정보

SQL Server Compact Edition 지원 정보 보기