OleDbConnectionStringBuilder.OleDbServices 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置要为连接字符串内的 OLE DB Services 键传递的值。
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
属性值
与连接字符串中的 OLE DB Services 键对应的值。 默认情况下,该值为 -13。
- 属性
示例
以下示例通过两种方式使用 OleDbServices 属性。 首先,它将值直接分配给 属性,演示此操作对生成的连接字符串的影响。 然后,该示例清除 OleDbConnectionStringBuilder 并分配包含 OLE DB Services 键值的完整连接字符串。 此步骤演示设置来自 连接字符串的值也会OleDbServices修改 属性。
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
注解
连接字符串中的 OLE DB Services 键定义允许开发人员启用或禁用 OLE DB 服务的值组合。 属性包含值的按位组合,如 OLE DB 文档中所述。 有关此属性的相应值的详细信息,请参阅 OLE DB 程序员参考,特别是“替代提供程序服务默认值”。此属性的默认值为 -13。 这对应于资源池、自动事务登记、会话级聚合和无客户端游标引擎的请求。