SqlConnectionStringBuilder.AsynchronousProcessing プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > SqlConnectionStringBuilder.AsynchronousProcessing プロパティの意味・解説 

SqlConnectionStringBuilder.AsynchronousProcessing プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

この接続文字列使用して作成される接続非同期処理許可されるかどうかを示すブール値を取得または設定します

名前空間: System.Data.SqlClient
アセンブリ: System.Data (system.data.dll 内)
構文構文

Public Property AsynchronousProcessing As
 Boolean
Dim instance As SqlConnectionStringBuilder
Dim value As Boolean

value = instance.AsynchronousProcessing

instance.AsynchronousProcessing = value
public bool AsynchronousProcessing { get;
 set; }
public:
property bool AsynchronousProcessing {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_AsynchronousProcessing ()

/** @property */
public void set_AsynchronousProcessing (boolean
 value)
public function get AsynchronousProcessing
 () : boolean

public function set AsynchronousProcessing
 (value : boolean)

プロパティ
AsynchronousProcessing プロパティの値。何も指定されていない場合false

解説解説
使用例使用例

次の例では、接続文字列取得して、その接続文字列に対して非同期処理必要な設定がされているかどうか確認してます。ここでは、アプリケーション内のプロシージャから文字列取得していますが、実際アプリケーションでは、接続文字列構成ファイルなどから取得するのが一般的です。その後サンプル データベース内の値をバックグラウンド スレッド更新する非同期操作実行します

Imports System.Data.SqlClient
Imports System.Threading


Module Module1
    Sub Main()
        ' Create a SqlConnectionStringBuilder instance, 
        ' and ensure that it is set up for asynchronous processing.
        Dim builder As _
         New SqlConnectionStringBuilder(GetConnectionString())
        ' Asynchronous method calls won't work unless you
        ' have added this option, or have added
        ' the clause "Asynchronous Processing=True"
        ' to the connection string.
        builder.AsynchronousProcessing = True

        Dim commandText As String
 = _
         "UPDATE Production.Product SET ReorderPoint = ReorderPoint
 + 1 " & _
         "WHERE ReorderPoint Is Not Null;" & _
         "WAITFOR DELAY '0:0:3';" & _
         "UPDATE Production.Product SET ReorderPoint = ReorderPoint
 - 1 " & _
         "WHERE ReorderPoint Is Not Null"
        RunCommandAsynchronously(commandText, builder.ConnectionString)

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

    Private Function GetConnectionString()
 As String
        ' To avoid storing the connection string in your code,
        ' you can retrieve it from a configuration file. 
        Return "Data Source=(local);Integrated
 Security=SSPI;" & _
          "Initial Catalog=AdventureWorks"
    End Function

    Private Sub RunCommandAsynchronously( _
     ByVal commandText As String,
 ByVal connectionString As String)

        ' Given command text and connection string, asynchronously execute
        ' the specified command against the connection. For this example
,
        ' the code displays an indicator as it's working, verifying
 the 
        ' asynchronous behavior. 
        Using connection As New SqlConnection(connectionString)
            Try
                Dim count As Integer
 = 0
                Dim command As New
 SqlCommand(commandText, connection)
                connection.Open()
                Dim result As IAsyncResult
 = command.BeginExecuteNonQuery()
                While Not result.IsCompleted
                    Console.WriteLine("Waiting {0}.",
 count)
                    ' Wait for 1/10 second, so the counter
                    ' doesn't consume all available resources 
                    ' on the main thread.
                    Threading.Thread.Sleep(100)
                    count += 1
                End While
                Console.WriteLine("Command complete. Affected
 {0} rows.", _
                    command.EndExecuteNonQuery(result))
            Catch ex As SqlException
                Console.WriteLine( _
                "Error {0}: System.Data.SqlClient.SqlConnectionStringBuilder",
 _
                ex.Number, ex.Message)
            Catch ex As InvalidOperationException
                Console.WriteLine("Error: {0}", ex.Message)
            Catch ex As Exception
                ' You might want to pass these errors
                ' back out to the caller.
                Console.WriteLine("Error: {0}", ex.Message)
            End Try
        End Using
    End Sub
End Module
using System.Data.SqlClient;
using System.Threading;

class Program
{
    static void Main()
    {
        // Create a SqlConnectionStringBuilder instance, 
        // and ensure that it is set up for asynchronous processing.
        SqlConnectionStringBuilder builder =
            new SqlConnectionStringBuilder(GetConnectionString());
        // Asynchronous method calls won't work unless you
        // have added this option, or have added
        // the clause "Asynchronous Processing=true"
        // to the connection string.
        builder.AsynchronousProcessing = true;

        string commandText =
            "UPDATE Production.Product SET ReorderPoint = ReorderPoint + 1 "
 +
            "WHERE ReorderPoint IS NOT Null;" +
            "WAITFOR DELAY '0:0:3';" +
            "UPDATE Production.Product SET ReorderPoint = ReorderPoint - 1 "
 +
            "WHERE ReorderPoint IS NOT Null";
        RunCommandAsynchronously(commandText, builder.ConnectionString);

        Console.WriteLine("Press any key to finish.");
        Console.ReadLine();
    }

    private static string
 GetConnectionString()
    {
        // To avoid storing the connection string in your code,
        // you can retrieve it from a configuration file. 
        return "Data Source=(local);Integrated Security=SSPI;"
 +
            "Initial Catalog=AdventureWorks";
    }

    private static void
 RunCommandAsynchronously(string commandText, 
        string connectionString)
    {
        // Given command text and connection string, asynchronously
 execute
        // the specified command against the connection. For this example
,
        // the code displays an indicator as it's working, verifying
 the 
        // asynchronous behavior. 
        using (SqlConnection connection = new
 SqlConnection(connectionString))
        {
            try
            {
                int count = 0;
                SqlCommand command = new SqlCommand(commandText,
 connection);
                connection.Open();
                IAsyncResult result = command.BeginExecuteNonQuery();
                while (!result.IsCompleted)
                {
                    Console.WriteLine("Waiting {0}.", count);
                    // Wait for 1/10 second, so the counter
                    // doesn't consume all available resources 
                    // on the main thread.
                    Thread.Sleep(100);
                    count += 1;
                }
                Console.WriteLine("Command complete. Affected {0} rows."
,
                    command.EndExecuteNonQuery(result));

            }
            catch (SqlException ex)
            {
                Console.WriteLine(
                    "Error {0}: System.Data.SqlClient.SqlConnectionStringBuilder",
 
                    ex.Number, ex.Message);
            }
            catch (InvalidOperationException ex)
            {
                Console.WriteLine("Error: {0}", ex.Message);
            }
            catch (Exception ex)
            {
                // You might want to pass these errors
                // back out to the caller.
                Console.WriteLine("Error: {0}", ex.Message);
            }
        }
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SqlConnectionStringBuilder クラス
SqlConnectionStringBuilder メンバ
System.Data.SqlClient 名前空間
BeginExecuteReader
BeginExecuteNonQuery
BeginExecuteXmlReader
その他の技術情報
接続文字列使用



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

SqlConnectionStringBuilder.AsynchronousProcessing プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



SqlConnectionStringBuilder.AsynchronousProcessing プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS