共用方式為


如何:使用 ADO.NET 指定暫存資料庫的位置 (以程式設計的方式)

您可以使用 Microsoft .NET Compact Framework Data Provider for SQL Server Compact 4.0 來明確指定暫存資料庫的位置和大小。若要這樣做,請將 temp file directory 和 temp file max size 屬性加入至連接字串,如下所示︰

"temp file directory = temp_database_location; temp file max size=128;"

注意

指定的暫存資料庫位置必須是已經存在。

範例

下列範例顯示如何在 SqlCeConnection 物件的連接字串中傳遞暫存資料庫位置。

SqlCeConnection conn = new SqlCeConnection();
conn.ConnectionString = @"Persist Security Info = False;
   Temp File Directory = '\TempDB\'; Temp File Max Size = 256;
   Data Source = 'SalesData.sdf';
   Password = '<enterStrongPasswordHere>'; File Mode = 'shared read';
   Max Database Size = 256; Max Buffer Size = 1024";
conn.Open();
Dim conn As New SqlCeConnection()
conn.ConnectionString = "Persist Security Info = False;" & _
   "Temp File Directory = '\TempDB\'; Temp File Max Size = 256;" & _
   "Data Source = 'SalesData.sdf';" & _
   "Password = '<enterStrongPasswordHere>'; File Mode = 'shared read';" & _
   "Max Database Size = 256; Max Buffer Size = 1024"
conn.Open()