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
Public Function GetDatabaseInfo As List(Of KeyValuePair(Of String, String))
public List<KeyValuePair<string,string>> GetDatabaseInfo ()
public:
List<KeyValuePair<String^, String^>>^ GetDatabaseInfo ()
public List<KeyValuePair<String,String>> GetDatabaseInfo ()
public function GetDatabaseInfo () : List<KeyValuePair<String,String>>

Return Value

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.

Example

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

Thread Safety

Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Platforms

Development Platforms

Windows Vista, Windows Mobile 5.0, Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Mobile 2003 for Pocket PC, Windows CE 5.0
Version Information
.NET Framework and NET Compact Framework
Supported in 3.5
.NET Framework
Supported in 3.0
.NET Compact Framework and .Net Framework
Supported in 2.0

See Also

Reference

SqlCeConnection Class
SqlCeConnection Members
System.Data.SqlServerCe Namespace