共用方式為


SqlCeConnection.GetDatabaseInfo 方法

傳回索引鍵值組,其中含有連接之資料庫的地區設定、加密模式及區分大小寫設定的相關資訊。

命名空間:  System.Data.SqlServerCe
組件:  System.Data.SqlServerCe (在 System.Data.SqlServerCe.dll 中)

語法

'宣告
<SecurityCriticalAttribute> _
<SecurityTreatAsSafeAttribute> _
<SecurityPermissionAttribute(SecurityAction.Assert, UnmanagedCode := True)> _
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()
[SecurityCriticalAttribute]
[SecurityTreatAsSafeAttribute]
[SecurityPermissionAttribute(SecurityAction.Assert, UnmanagedCode = true)]
public List<KeyValuePair<string, string>> GetDatabaseInfo()
[SecurityCriticalAttribute]
[SecurityTreatAsSafeAttribute]
[SecurityPermissionAttribute(SecurityAction::Assert, UnmanagedCode = true)]
public:
List<KeyValuePair<String^, String^>>^ GetDatabaseInfo()
[<SecurityCriticalAttribute>]
[<SecurityTreatAsSafeAttribute>]
[<SecurityPermissionAttribute(SecurityAction.Assert, UnmanagedCode = true)>]
member GetDatabaseInfo : unit -> List<KeyValuePair<string, string>> 
public function GetDatabaseInfo() : List<KeyValuePair<String, String>>

傳回值

型別:System.Collections.Generic.List<KeyValuePair<String, String>>
地區設定、加密模式之區分大小寫之名稱值組的排序清單。

備註

如需有關加密選項、平台預設值和引擎預設值的詳細資訊,請參閱<加密資料庫>。

範例

下列範例會使用 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();
}

請參閱

參考

SqlCeConnection 類別

System.Data.SqlServerCe 命名空間