GetDatabaseInfo 方法
傳回索引鍵值組,其中含有連接之資料庫的地區設定、加密模式及區分大小寫設定的相關資訊。
命名空間: System.Data.SqlServerCe
組件: System.Data.SqlServerCe (在 System.Data.SqlServerCe.dll 中)
語法
'宣告
Public Function GetDatabaseInfo As List(Of KeyValuePair(Of String, String))
'用途
Dim instance As SqlCeConnection
Dim returnValue As List(Of KeyValuePair(Of String, String))
returnValue = instance.GetDatabaseInfo()
public List<KeyValuePair<string, string>> GetDatabaseInfo()
public:
List<KeyValuePair<String^, String^>>^ GetDatabaseInfo()
member GetDatabaseInfo : unit -> List<KeyValuePair<string, string>>
public function GetDatabaseInfo() : List<KeyValuePair<String, String>>
傳回值
型別:System.Collections.Generic. . :: . .List< (Of < ( <'KeyValuePair< (Of < ( <'String, String> ) > ) >> ) > ) >
地區設定、加密模式之區分大小寫之名稱值組的排序清單。
備註
加密模式值可能與使用者指定的不同。以在 PPC2003 裝置上建立的資料庫而言,傳回的「加密模式」是 PPC2003 Compatibility。使用者可能已將加密模式指定為 Platform default 或 PPC2003 compatibility。
上述行為之所以會發生,是因為在 PPC2003 裝置中,Platform default 模式是對應至 PPC2003 compatibility,而在其他裝置和/或桌上型電腦中,則是對應至 Engine Default。
範例
下列範例會使用 GetDatabaseInfo 擷取 Northwind.sdf 的資料庫屬性。SqlCeConnection 會傳遞連接字串,然後開啟與資料庫的連接。連接開啟後,GetDatabaseInfo 的內容就會儲存在 KeyValuePair 中並顯示在主控台上。
Dim connStr As String = Nothing
Dim databasePath As String = Nothing
Dim sqlconn As SqlCeConnection = Nothing
Try
'Defining database parameters
databasePath = "C:\Program Files\Microsoft SQL Server Compact Edition\v3.5\Samples\Northwind.sdf"
'If the database already exists, the existing encryption mode will supercede the supplied mode
connStr = "Data Source=" & databasePath & ";Encryption Mode = 'ppc2003 compatibility';Password='password'"
'Connecting to the database and opening the connection
sqlconn = New SqlCeConnection(connStr)
sqlconn.Open()
'Retrieving the database information
Dim dbinfo As List(Of KeyValuePair(Of String, String)) = sqlconn.GetDatabaseInfo
Console.WriteLine("GetDatabaseInfo() results:")
Dim kvp As KeyValuePair(Of String, String)
For Each kvp In dbinfo
Console.WriteLine(kvp)
Next
Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
'Dispose the connection's resources
sqlconn.Dispose()
Console.WriteLine(vbNewLine & vbNewLine & vbNewLine & "Press any key to continue...")
Console.Read()
End Try
string connStr = null;
string databasePath = null;
SqlCeConnection sqlconn = null;
try
{
//Defining database parameters
databasePath = @"C:\Program Files\Microsoft SQL Server Compact Edition\v3.5\Samples\Northwind.sdf";
//If the database already exists, the existing encryption mode will supercede the supplied mode
connStr = "Data Source=" + databasePath + ";Encryption Mode = 'ppc2003 compatibility';Password='sa'";
//Connecting to the database and opening the connection
sqlconn = new SqlCeConnection(connStr);
sqlconn.Open();
//Retrieving the database information
List<KeyValuePair<string, string>> dbinfo = sqlconn.GetDatabaseInfo();
Console.WriteLine("GetDatabaseInfo() results:");
foreach (KeyValuePair<string, string> kvp in dbinfo)
{
Console.WriteLine(kvp);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
//Dispose the connection's resources
sqlconn.Dispose();
Console.WriteLine("\n\n\nPress any key to continue...");
Console.Read();
}