ערוך

שתף באמצעות


OleDbConnectionStringBuilder.OleDbServices Property

Definition

Gets or sets the value to be passed for the OLE DB Services key within the connection string.

public:
 property int OleDbServices { int get(); void set(int value); };
[System.ComponentModel.TypeConverter(typeof(System.Data.OleDb.OleDbConnectionStringBuilder+OleDbServicesConverter))]
public int OleDbServices { get; set; }
[<System.ComponentModel.TypeConverter(typeof(System.Data.OleDb.OleDbConnectionStringBuilder+OleDbServicesConverter))>]
member this.OleDbServices : int with get, set
Public Property OleDbServices As Integer

Property Value

The value corresponding to the OLE DB Services key within the connection string. By default, the value is -13.

Attributes

Examples

The following example works with the OleDbServices 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 OLE DB Services key. This step demonstrates that setting the value from the connection string modifies the OleDbServices property, as well.

using System.Data.OleDb;

class Program
{
    // These constants correspond to values in the
    // OLE DB SDK. You can use these values to
    // turn features on and off.
    private const int DBPROPVAL_OS_AGR_AFTERSESSION = 8;
    private const int DBPROPVAL_OS_AGR_RESOURCEPOOLING = 1;
    private const int DBPROPVAL_OS_AGR_TXNENLISTMENT = 2;
    private const int DBPROPVAL_OS_AGR_CLIENTCURSOR = 4;
    private const int DBPROPVAL_OS_ENABLEALL = -1;
    private const int DBPROPVAL_OS_DISABLEALL = 0;

    static void Main()
    {
        OleDbConnectionStringBuilder builder =
            new OleDbConnectionStringBuilder();
        // Turn on all services except resource pooling.
        builder.OleDbServices =
            DBPROPVAL_OS_ENABLEALL &
            ~DBPROPVAL_OS_AGR_RESOURCEPOOLING;

        builder.Provider = "sqloledb";
        builder.DataSource = "(local)";
        builder["Initial Catalog"] = "AdventureWorks";
        builder["Integrated Security"] = "SSPI";

        // 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 OleDbServices property before
        // and after assigning a connection string value.
        Console.WriteLine("Default : " + builder.OleDbServices);
        builder.ConnectionString = savedConnectionString;
        Console.WriteLine("Modified: " + builder.OleDbServices);

        Console.WriteLine("Press Enter to finish.");
        Console.ReadLine();
    }
}
Imports System.Data.OleDb    

Module Module1
  ' These constants correspond to values in the 
  ' OLE DB SDK. You can use these values to 
  ' turn features on and off.
  Private Const DBPROPVAL_OS_AGR_AFTERSESSION As Integer = 8
  Private Const DBPROPVAL_OS_AGR_RESOURCEPOOLING As Integer = 1
  Private Const DBPROPVAL_OS_AGR_TXNENLISTMENT As Integer = 2
  Private Const DBPROPVAL_OS_AGR_CLIENTCURSOR As Integer = 4
  Private Const DBPROPVAL_OS_ENABLEALL As Integer = -1
  Private Const DBPROPVAL_OS_DISABLEALL As Integer = 0

  Sub Main()
    Dim builder As New OleDbConnectionStringBuilder()
    ' Turn on all services except resource pooling.
    builder.OleDbServices = DBPROPVAL_OS_ENABLEALL _
     And Not DBPROPVAL_OS_AGR_RESOURCEPOOLING

    builder.Provider = "sqloledb"
    builder.DataSource = "(local)"
    builder("Initial Catalog") = "AdventureWorks"
    builder("Integrated Security") = "SSPI"

    ' 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 OleDbServices property before
    ' and after assigning a connection string value.
    Console.WriteLine("Default : " & builder.OleDbServices)
    builder.ConnectionString = savedConnectionString
    Console.WriteLine("Modified: " & builder.OleDbServices)

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

Remarks

The OLE DB Services key within the connection string defines a combination of values that let developers enable or disable OLE DB services. The property contains a bitwise combination of values, described in the OLE DB documentation. For more information about appropriate values for this property, see the OLE DB Programmer's Reference, in particular, "Overriding Provider Service Defaults." The default value for this property is -13. This corresponds to a request for resource pooling, automatic transaction enlistment, session-level aggregation, and no client cursor engine.

Applies to

See also