Share via


OracleConnectionStringBuilder.IntegratedSecurity 屬性

定義

取得或設定值,指示是否在連接中指定「使用者 ID」和「密碼」(false 時) 或目前 Windows 帳戶認證是否用於驗證 (true 時)。

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

屬性值

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

範例

下列範例會轉換現有的連接字串,將其從使用 Windows 驗證轉換成使用整合式安全性。 此範例運作的方式是從連接字串中移除使用者名稱和密碼,然後設定 IntegratedSecurity 物件的 OracleConnectionStringBuilder 屬性。

注意

這個範例包含了密碼,可示範 OracleConnectionStringBuilder 如何搭配連接字串使用。 我們建議在您的應用程式中使用 Windows 驗證。 如果您必須使用密碼,請勿在您的應用程式中包含硬式編碼的密碼。

// You may need to set a reference to the System.Data.OracleClient
// assembly before you can run this sample.
using System.Data.OracleClient;

class Program
{
    static void Main()
    {
        try
        {
            string connectString =
                "Data Source=OracleSample;User ID=Mary;Password=*****;";

            OracleConnectionStringBuilder builder =
                new OracleConnectionStringBuilder(connectString);
            Console.WriteLine("Original: " + builder.ConnectionString);

            // Use the Remove method
            // in order to reset the user ID and password back to their
            // default (empty string) values. Simply setting the
            // associated property values to an empty string will not
            // remove them from the connection string; you must
            // call the Remove method.
            builder.Remove("User ID");
            builder.Remove("Password");

            // Turn on integrated security.
            builder.IntegratedSecurity = true;

            Console.WriteLine("Modified: " + builder.ConnectionString);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

        Console.WriteLine("Press any key to finish.");
        Console.ReadLine();
    }
}
' You may need to set a reference to the System.Data.OracleClient
' assembly before you can run this example. 
Imports System.Data.OracleClient

Module Module1

  Sub Main()
    Try
      Dim connectString As String = _
       "Data Source=OracleSample;User ID=Mary;Password=*****;"

      Dim builder As New OracleConnectionStringBuilder(connectString)
      Console.WriteLine("Original: " & builder.ConnectionString)

      ' Use the Remove method
      ' in order to reset the user ID and password back to their
      ' default (empty string) values. Simply setting the 
      ' associated property values to an empty string will not
      ' remove them from the connection string; you must
      ' call the Remove method.
      builder.Remove("User ID")
      builder.Remove("Password")

      ' Turn on integrated security.
      builder.IntegratedSecurity = True

      Console.WriteLine("Modified: " & builder.ConnectionString)

    Catch ex As Exception
      Console.WriteLine(ex.Message)
    End Try

    Console.WriteLine("Press any key to finish.")
    Console.ReadLine()
  End Sub
End Module

備註

此屬性會對應至 連接字串 內的「整合式安全性」金鑰。

適用於

另請參閱