Share via


SqlCeConnection.GetDatabaseInfo Method

Returns a set of Key Value pairs with information about locale, encryption mode, and case-sensitivity setting of the connected database.

Namespace:  System.Data.SqlServerCe
Assembly:  System.Data.SqlServerCe (in System.Data.SqlServerCe.dll)

Syntax

'Declaration
<SecurityCriticalAttribute> _
<SecurityTreatAsSafeAttribute> _
<SecurityPermissionAttribute(SecurityAction.Assert, UnmanagedCode := True)> _
Public Function GetDatabaseInfo As List(Of KeyValuePair(Of String, String))
'Usage
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>>

Return Value

Type: System.Collections.Generic.List<KeyValuePair<String, String>>
Sorted list with the name value pairs of locale, encryption mode, and case sensitivity.

Remarks

For more information about the encryption options, platform default and engine default, see Encrypting a Database

Examples

The following example uses the GetDatabaseInfo to retrieve the database properties of Northwind.sdf. The SqlCeConnection is passed a connection string and then opens a connection to the database. Once the connection is open, the contents of GetDatabaseInfo is stored in a KeyValuePair and displayed on the console.

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();
}

See Also

Reference

SqlCeConnection Class

System.Data.SqlServerCe Namespace