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

Return Value

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

Remarks

The encryption mode values may not be the same as specified by the user. For a database created on a PPC2003 device, Encryption Mode returned is PPC2003 Compatibility. The user might have specified either Platform default or PPC2003 compatibility as the encryption mode.

The above behavior is because in the PPC2003 devices Platform default mode maps to PPC2003 compatibility and for other devices and/or desktop it maps to Engine Default.

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

SqlCeConnection Members

System.Data.SqlServerCe Namespace