OleDbConnectionStringBuilder.OleDbServices 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定要傳遞的值,對象為連接字串內的 OLE DB 服務索引鍵。
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。 這會對應至資源分享、自動交易登記、工作階段層級匯總,以及沒有客戶端數據指標引擎的要求。