OleDbConnectionStringBuilder.PersistSecurityInfo Property


Gets or sets a Boolean value that indicates whether security-sensitive information, such as the password, is returned as part of the connection if the connection is open or has ever been in an open state.

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

public bool PersistSecurityInfo { get; set; }

Property Value

Type: System.Boolean

The value of the PersistSecurityInfo property, or false if none has been supplied.

This property corresponds to the "Persist Security Info" key within the connection string.

The following example works with the PersistSecurityInfo property in two ways. First, it assigns a value directly to the property, demonstrating the effect this action has on the resulting connection string. Then, the example clears the OleDbConnectionStringBuilder and assigns a complete connection string that contains a value for the "Persist Security Info" key. This step demonstrates that setting the value from the connection string modifies the PersistSecurityInfo property, as well.

using System.Data.OleDb;

class Program
    static void Main()
        OleDbConnectionStringBuilder builder =
            new OleDbConnectionStringBuilder();
        builder.PersistSecurityInfo = true;
        builder.Provider = "Microsoft.Jet.Oledb.4.0";
        builder.DataSource = @"C:\Sample.mdb";

        // Store the connection string.
        string savedConnectionString = builder.ConnectionString;

        // Reset the object. This resets all the properties to their
        // default values.

        // Investigate the PersistSecurityInfo property before
        // and after assigning a connection string value.
        Console.WriteLine("Default : " + builder.PersistSecurityInfo);
        builder.ConnectionString = savedConnectionString;
        Console.WriteLine("Modified: " + builder.PersistSecurityInfo);

        Console.WriteLine("Press Enter to finish.");

.NET Framework
Available since 2.0
Return to top