SqlCredential クラス

定義

SqlCredential は SQL Server 認証を使用してログイン試行のパスワードを指定するより安全な方法を提供します。

SqlCredential は SQL Server の認証に使用するユーザー ID とパスワードで構成されます。 SqlCredential オブジェクトのパスワードは、SecureString 型です。

SqlCredential は継承できません。

Windows 認証 (Integrated Security = true) は、SQL Server データベースにログインする最も安全な方法のままです。

public ref class SqlCredential sealed
public sealed class SqlCredential
type SqlCredential = class
Public NotInheritable Class SqlCredential
継承
SqlCredential

注釈

を使用して Credential 、接続の SqlCredential オブジェクトを取得または設定します。 オブジェクトを使用してユーザーのパスワードを変更するには、 をSqlCredential使用ChangePasswordします。 オブジェクトが接続プールのSqlCredential動作にどのように影響するかについては、「SQL Server接続プール (ADO.NET)」を参照してください。

InvalidOperationException次のいずれかの接続文字列キーワードとの接続で null SqlCredential 以外のオブジェクトが使用されている場合、例外が発生します。

  • Integrated Security = true

  • Password

  • User ID

  • Context Connection = true

次の例では、 を使用してCredentialSQL Server データベースに接続します。

// change connection string in the APP.CONFIG file  
<connectionStrings>  
  <add name="MyConnString"  
       connectionString="Initial Catalog=myDB;Server=myServer"  
       providerName="System.Data.SqlClient" />  
</connectionStrings>  

// then use the following snippet:  
using System.Configuration;  

System.Windows.Controls.TextBox txtUserId = new System.Windows.Controls.TextBox();  
System.Windows.Controls.PasswordBox txtPwd = new System.Windows.Controls.PasswordBox();  

Configuration config = Configuration.WebConfigurationManager.OpenWebConfiguration(Null);  
ConnectionStringSettings connString = config.ConnectionStrings.ConnectionString["MyConnString"];  

using (SqlConnection conn = new SqlConnection(connString.ConnectionString))  
{  
SecureString pwd = txtPwd.SecurePassword;  
pwd.MakeReadOnly();  
SqlCredential cred = new SqlCredential(txtUserId.Text, pwd);  
conn.Credential = cred;  
conn.Open();  

コンストラクター

SqlCredential(String, SecureString)

SqlCredential 型のオブジェクトを作成します。

プロパティ

Password

SqlCredential オブジェクトのパスワード コンポーネントを取得します。

UserId

SqlCredential オブジェクトのユーザー ID コンポーネントを取得します。

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象

こちらもご覧ください