共用方式為


OleDbConnectionStringBuilder.PersistSecurityInfo 屬性

定義

取得或設定布林 (Boolean) 值,指示如果連接開啟或曾經處於開啟狀態,是否會將安全性相關資訊 (如密碼) 當做連接的一部分傳回。

public:
 property bool PersistSecurityInfo { bool get(); void set(bool value); };
public bool PersistSecurityInfo { get; set; }
member this.PersistSecurityInfo : bool with get, set
Public Property PersistSecurityInfo As Boolean

屬性值

PersistSecurityInfo 屬性的值,如未提供任何值,則為 false

範例

下列範例會以兩種方式與 屬性搭配 PersistSecurityInfo 使用。 首先,它會將值直接指派給 屬性,示範此動作對產生的 連接字串 的影響。 然後,此範例會OleDbConnectionStringBuilder清除 並指派完整的 連接字串,其中包含「保存安全性資訊」金鑰的值。 此步驟示範如何設定來自 連接字串 的值也會修改 PersistSecurityInfo 屬性。

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;
        Console.WriteLine(savedConnectionString);

        // Reset the object. This resets all the properties to their
        // default values.
        builder.Clear();

        // 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.");
        Console.ReadLine();
    }
}
Imports System.Data.OleDb    

Module Module1
  Sub Main()
    Dim builder As New OleDbConnectionStringBuilder()
    builder.PersistSecurityInfo = True
    builder.Provider = "Microsoft.Jet.Oledb.4.0"
    builder.DataSource = "C:\Sample.mdb"

    ' Store the connection string.
    Dim savedConnectionString As String = builder.ConnectionString
    Console.WriteLine(savedConnectionString)

    ' Reset the object. This resets all the properties to their
    ' default values.
    builder.Clear()

    ' 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.")
    Console.ReadLine()
  End Sub
End Module

備註

此屬性會對應至 連接字串 內的「保存安全性資訊」金鑰。

適用於

另請參閱