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 命名空间