تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
Source Code "OleDbConnection"
#1
Imports System
Imports System.ComponentModel
Imports System.Data.Common
Imports System.Data.ProviderBase
Imports System.Diagnostics
Imports System.EnterpriseServices
Imports System.Globalization
Imports System.Runtime.ConstrainedExecution
Imports System.Runtime.InteropServices
Imports System.Security
Imports System.Security.Permissions
Imports System.Text
Imports System.Threading
Imports System.Transactions


Namespace System.Data.OleDb
<DefaultEvent("InfoMessage")>
Public Class OleDbConnection
Inherits DbConnection
Implements ICloneable, IDbConnection, IDisposable


Private Shared EventInfoMessage As Object = New Object()


Private Shared _connectionFactory As DbConnectionFactory = OleDbConnectionFactory.SingletonInstance


Friend Shared ExecutePermission As CodeAccessPermission = OleDbConnection.CreateExecutePermission()


Private _userConnectionOptions As DbConnectionOptions


Private _poolGroup As DbConnectionPoolGroup


Private _innerConnection As DbConnectionInternal


Private _closeCount As Integer


Private Shared _objectTypeCount As Integer


Friend ObjectID As Integer = Interlocked.Increment(OleDbConnection._objectTypeCount)


<ResCategory("DataCategory_InfoMessage"), ResDescription("DbConnection_InfoMessage")>
Public Custom Event InfoMessage As OleDbInfoMessageEventHandler
AddHandler
MyBase.Events.[AddHandler](OleDbConnection.EventInfoMessage, value)
End AddHandler
RemoveHandler
MyBase.Events.[RemoveHandler](OleDbConnection.EventInfoMessage, value)
End RemoveHandler
End Event


<DefaultValue(""), Editor("Microsoft.VSDesigner.Data.ADO.Design.OleDbConnectionStringEditor, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), RecommendedAsConfigurable(True), RefreshProperties(RefreshProperties.All), ResCategory("DataCategory_Data"), ResDescription("OleDbConnection_ConnectionString")>
Public Override Property ConnectionString() As String
Get
Return Me.ConnectionString_Get()
End Get
Set(value As String)
Me.ConnectionString_Set(value)
End Set
End Property


Private ReadOnly Property OleDbConnectionStringValue() As OleDbConnectionString
Get
Return CType(Me.ConnectionOptions, OleDbConnectionString)
End Get
End Property


<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ResDescription("OleDbConnection_ConnectionTimeout")>
Public Override ReadOnly Property ConnectionTimeout() As Integer
Get
Dim intPtr As IntPtr
Bid.ScopeEnter(intPtr, "<oledb.OleDbConnection.get_ConnectionTimeout|API> %d#" & vbLf, Me.ObjectID)
Dim result As Integer
Try
Dim obj As Object
If Me.IsOpen Then
obj = Me.GetDataSourceValue(OleDbPropertySetGuid.DBInit, 66)
Else
Dim oleDbConnectionStringValue As OleDbConnectionString = Me.OleDbConnectionStringValue
obj = (If((oleDbConnectionStringValue IsNot Nothing), oleDbConnectionStringValue.ConnectTimeout, 15))
End If
If obj IsNot Nothing Then
result = Convert.ToInt32(obj, CultureInfo.InvariantCulture)
Else
result = 15
End If
Finally
Bid.ScopeLeave(intPtr)
End Try
Return result
End Get
End Property


<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ResDescription("OleDbConnection_Database")>
Public Override ReadOnly Property Database() As String
Get
Dim intPtr As IntPtr
Bid.ScopeEnter(intPtr, "<oledb.OleDbConnection.get_Database|API> %d#" & vbLf, Me.ObjectID)
Dim result As String
Try
Dim oleDbConnectionString As OleDbConnectionString = CType(Me.UserConnectionOptions, OleDbConnectionString)
Dim obj As Object = If((oleDbConnectionString IsNot Nothing), oleDbConnectionString.InitialCatalog, ADP.StrEmpty)
If obj IsNot Nothing AndAlso Not(CStr(obj)).StartsWith("|datadirectory|", StringComparison.OrdinalIgnoreCase) Then
Dim openConnection As OleDbConnectionInternal = Me.GetOpenConnection()
If openConnection IsNot Nothing Then
If openConnection.HasSession Then
obj = Me.GetDataSourceValue(OleDbPropertySetGuid.DataSource, 37)
Else
obj = Me.GetDataSourceValue(OleDbPropertySetGuid.DBInit, 233)
End If
Else
oleDbConnectionString = Me.OleDbConnectionStringValue
obj = (If((oleDbConnectionString IsNot Nothing), oleDbConnectionString.InitialCatalog, ADP.StrEmpty))
End If
End If
result = Convert.ToString(obj, CultureInfo.InvariantCulture)
Finally
Bid.ScopeLeave(intPtr)
End Try
Return result
End Get
End Property


<Browsable(True), ResDescription("OleDbConnection_DataSource")>
Public Override ReadOnly Property DataSource() As String
Get
Dim intPtr As IntPtr
Bid.ScopeEnter(intPtr, "<oledb.OleDbConnection.get_DataSource|API> %d#" & vbLf, Me.ObjectID)
Dim result As String
Try
Dim oleDbConnectionString As OleDbConnectionString = CType(Me.UserConnectionOptions, OleDbConnectionString)
Dim obj As Object = If((oleDbConnectionString IsNot Nothing), oleDbConnectionString.DataSource, ADP.StrEmpty)
If obj IsNot Nothing AndAlso Not(CStr(obj)).StartsWith("|datadirectory|", StringComparison.OrdinalIgnoreCase) Then
If Me.IsOpen Then
obj = Me.GetDataSourceValue(OleDbPropertySetGuid.DBInit, 59)
If obj Is Nothing OrElse (TypeOf obj Is String AndAlso (TryCast(obj, String)).Length = 0) Then
obj = Me.GetDataSourceValue(OleDbPropertySetGuid.DataSourceInfo, 38)
End If
Else
oleDbConnectionString = Me.OleDbConnectionStringValue
obj = (If((oleDbConnectionString IsNot Nothing), oleDbConnectionString.DataSource, ADP.StrEmpty))
End If
End If
result = Convert.ToString(obj, CultureInfo.InvariantCulture)
Finally
Bid.ScopeLeave(intPtr)
End Try
Return result
End Get
End Property


Friend ReadOnly Property IsOpen() As Boolean
Get
Return Nothing IsNot Me.GetOpenConnection()
End Get
End Property


Friend WriteOnly Property LocalTransaction() As OleDbTransaction
Set(value As OleDbTransaction)
Dim openConnection As OleDbConnectionInternal = Me.GetOpenConnection()
If openConnection IsNot Nothing Then
openConnection.LocalTransaction = value
End If
End Set
End Property


<Browsable(True), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ResCategory("DataCategory_Data"), ResDescription("OleDbConnection_Provider")>
Public ReadOnly Property Provider() As String
Get
Bid.Trace("<oledb.OleDbConnection.get_Provider|API> %d#" & vbLf, Me.ObjectID)
Dim oleDbConnectionStringValue As OleDbConnectionString = Me.OleDbConnectionStringValue
Dim text As String = If((oleDbConnectionStringValue IsNot Nothing), oleDbConnectionStringValue.ConvertValueToString("provider", Nothing), Nothing)
If text Is Nothing Then
Return ADP.StrEmpty
End If
Return text
End Get
End Property


Friend ReadOnly Property ProviderInfo() As OleDbConnectionPoolGroupProviderInfo
Get
Return CType(Me.PoolGroup.ProviderInfo, OleDbConnectionPoolGroupProviderInfo)
End Get
End Property


<ResDescription("OleDbConnection_ServerVersion")>
Public Override ReadOnly Property ServerVersion() As String
Get
Return Me.InnerConnection.ServerVersion
End Get
End Property


Friend ReadOnly Property CloseCount() As Integer
Get
Return Me._closeCount
End Get
End Property


Friend ReadOnly Property ConnectionFactory() As DbConnectionFactory
Get
Return OleDbConnection._connectionFactory
End Get
End Property


Friend ReadOnly Property ConnectionOptions() As DbConnectionOptions
Get
Dim poolGroup As DbConnectionPoolGroup = Me.PoolGroup
If poolGroup Is Nothing Then
Return Nothing
End If
Return poolGroup.ConnectionOptions
End Get
End Property


Friend ReadOnly Property InnerConnection() As DbConnectionInternal
Get
Return Me._innerConnection
End Get
End Property


Friend Property PoolGroup() As DbConnectionPoolGroup
Get
Return Me._poolGroup
End Get
Set(value As DbConnectionPoolGroup)
Me._poolGroup = value
End Set
End Property


<Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), ResDescription("DbConnection_State")>
Public Override ReadOnly Property State() As ConnectionState
Get
Return Me.InnerConnection.State
End Get
End Property


Friend ReadOnly Property UserConnectionOptions() As DbConnectionOptions
Get
Return Me._userConnectionOptions
End Get
End Property


Public Sub New(connectionString As String)
Me.[New]()
Me.ConnectionString = connectionString
End Sub


Private Sub New(connection As OleDbConnection)
Me.[New]()
Me.CopyFrom(connection)
End Sub


<EditorBrowsable(EditorBrowsableState.Advanced)>
Public Sub ResetState()
Dim intPtr As IntPtr
Bid.ScopeEnter(intPtr, "<oledb.OleDbCommand.ResetState|API> %d#" & vbLf, Me.ObjectID)
Try
If Me.IsOpen Then
Dim dataSourcePropertyValue As Object = Me.GetDataSourcePropertyValue(OleDbPropertySetGuid.DataSourceInfo, 244)
If TypeOf dataSourcePropertyValue Is Integer Then
Select Case CInt(dataSourcePropertyValue)
Case 0, 2
Me.GetOpenConnection().DoomThisConnection()
Me.NotifyWeakReference(-1)
Me.Close()
End Select
End If
End If
Finally
Bid.ScopeLeave(intPtr)
End Try
End Sub


Friend Function ICommandText() As UnsafeNativeMethods.ICommandText
Return Me.GetOpenConnection().ICommandText()
End Function


Private Function IDBProperties() As IDBPropertiesWrapper
Return Me.GetOpenConnection().IDBProperties()
End Function


Friend Function IOpenRowset() As IOpenRowsetWrapper
Return Me.GetOpenConnection().IOpenRowset()
End Function


Friend Function SqlSupport() As Integer
Return Me.OleDbConnectionStringValue.GetSqlSupport(Me)
End Function


Friend Function SupportMultipleResults() As Boolean
Return Me.OleDbConnectionStringValue.GetSupportMultipleResults(Me)
End Function


Friend Function SupportIRow(cmd As OleDbCommand) As Boolean
Return Me.OleDbConnectionStringValue.GetSupportIRow(Me, cmd)
End Function


Friend Function QuotedIdentifierCase() As Integer
Dim dataSourcePropertyValue As Object = Me.GetDataSourcePropertyValue(OleDbPropertySetGuid.DataSourceInfo, 100)
Dim result As Integer
If TypeOf dataSourcePropertyValue Is Integer Then
result = CInt(dataSourcePropertyValue)
Else
result = -1
End If
Return result
End Function


Public Function BeginTransaction() As OleDbTransaction
Return Me.BeginTransaction(System.Data.IsolationLevel.Unspecified)
End Function


Public Function BeginTransaction(isolationLevel As System.Data.IsolationLevel) As OleDbTransaction
Return CType(Me.InnerConnection.BeginTransaction(isolationLevel), OleDbTransaction)
End Function


Public Override Sub ChangeDatabase(value As String)
OleDbConnection.ExecutePermission.Demand()
Dim intPtr As IntPtr
Bid.ScopeEnter(intPtr, "<oledb.OleDbConnection.ChangeDatabase|API> %d#, value='%ls'" & vbLf, Me.ObjectID, value)
Try
Me.CheckStateOpen("ChangeDatabase")
If value Is Nothing OrElse value.Trim().Length = 0 Then
Throw ADP.EmptyDatabaseName()
End If
Me.SetDataSourcePropertyValue(OleDbPropertySetGuid.DataSource, 37, "current catalog", True, value)
Finally
Bid.ScopeLeave(intPtr)
End Try
End Sub


Friend Sub CheckStateOpen(method As String)
Dim state As ConnectionState = Me.State
If ConnectionState.Open <> state Then
Throw ADP.OpenConnectionRequired(method, state)
End If
End Sub


Function Clone() As Object Implements ICloneable.Clone
Dim oleDbConnection As OleDbConnection = New OleDbConnection(Me)
Bid.Trace("<oledb.OleDbConnection.Clone|API> %d#, clone=%d#" & vbLf, Me.ObjectID, oleDbConnection.ObjectID)
Return oleDbConnection
End Function


Public Override Sub Close()
Me.InnerConnection.CloseConnection(Me, Me.ConnectionFactory)
End Sub


Public Function CreateCommand() As OleDbCommand
Return New OleDbCommand("", Me)
End Function


Private Sub DisposeMe(disposing As Boolean)
If disposing AndAlso MyBase.DesignMode Then
OleDbConnection.ReleaseObjectPool()
End If
End Sub


Public Sub EnlistDistributedTransaction(transaction As ITransaction)
Me.EnlistDistributedTransactionHelper(transaction)
End Sub


Friend Function GetDataSourcePropertyValue(propertySet As Guid, propertyID As Integer) As Object
Dim openConnection As OleDbConnectionInternal = Me.GetOpenConnection()
Return openConnection.GetDataSourcePropertyValue(propertySet, propertyID)
End Function


Friend Function GetDataSourceValue(propertySet As Guid, propertyID As Integer) As Object
Dim obj As Object = Me.GetDataSourcePropertyValue(propertySet, propertyID)
If TypeOf obj Is OleDbPropertyStatus OrElse Convert.IsDBNull(obj) Then
obj = Nothing
End If
Return obj
End Function


Private Function GetOpenConnection() As OleDbConnectionInternal
Dim innerConnection As DbConnectionInternal = Me.InnerConnection
Return TryCast(innerConnection, OleDbConnectionInternal)
End Function


Friend Sub GetLiteralQuotes(method As String, <Out()> ByRef quotePrefix As String, <Out()> ByRef quoteSuffix As String)
Me.CheckStateOpen(method)
Dim providerInfo As OleDbConnectionPoolGroupProviderInfo = Me.ProviderInfo
If providerInfo.HasQuoteFix Then
quotePrefix = providerInfo.QuotePrefix
quoteSuffix = providerInfo.QuoteSuffix
Return
End If
Dim openConnection As OleDbConnectionInternal = Me.GetOpenConnection()
quotePrefix = openConnection.GetLiteralInfo(15)
quoteSuffix = openConnection.GetLiteralInfo(28)
If quotePrefix Is Nothing Then
quotePrefix = ""
End If
If quoteSuffix Is Nothing Then
quoteSuffix = quotePrefix
End If
providerInfo.SetQuoteFix(quotePrefix, quoteSuffix)
End Sub


Public Function GetOleDbSchemaTable(schema As Guid, restrictions As Object()) As DataTable
OleDbConnection.ExecutePermission.Demand()
Dim intPtr As IntPtr
Bid.ScopeEnter(intPtr, "<oledb.OleDbConnection.GetOleDbSchemaTable|API> %d#, schema=%p{GUID}, restrictions" & vbLf, Me.ObjectID, schema)
Dim result As DataTable
Try
Me.CheckStateOpen("GetOleDbSchemaTable")
Dim openConnection As OleDbConnectionInternal = Me.GetOpenConnection()
If OleDbSchemaGuid.DbInfoLiterals = schema Then
If restrictions IsNot Nothing AndAlso restrictions.Length <> 0 Then
Throw ODB.InvalidRestrictionsDbInfoLiteral("restrictions")
End If
result = openConnection.BuildInfoLiterals()
Else
If OleDbSchemaGuid.SchemaGuids = schema Then
If restrictions IsNot Nothing AndAlso restrictions.Length <> 0 Then
Throw ODB.InvalidRestrictionsSchemaGuids("restrictions")
End If
result = openConnection.BuildSchemaGuids()
Else
If OleDbSchemaGuid.DbInfoKeywords = schema Then
If restrictions IsNot Nothing AndAlso restrictions.Length <> 0 Then
Throw ODB.InvalidRestrictionsDbInfoKeywords("restrictions")
End If
result = openConnection.BuildInfoKeywords()
Else
If Not openConnection.SupportSchemaRowset(schema) Then
Using Dim iDBSchemaRowsetWrapper As IDBSchemaRowsetWrapper = openConnection.IDBSchemaRowset()
If iDBSchemaRowsetWrapper.Value Is Nothing Then
Throw ODB.SchemaRowsetsNotSupported(Me.Provider)
End If
End Using
Throw ODB.NotSupportedSchemaTable(schema, Me)
End If
result = openConnection.GetSchemaRowset(schema, restrictions)
End If
End If
End If
Finally
Bid.ScopeLeave(intPtr)
End Try
Return result
End Function


Friend Function GetSchemaRowset(schema As Guid, restrictions As Object()) As DataTable
Return Me.GetOpenConnection().GetSchemaRowset(schema, restrictions)
End Function


Friend Function HasLiveReader(cmd As OleDbCommand) As Boolean
Dim result As Boolean = False
Dim openConnection As OleDbConnectionInternal = Me.GetOpenConnection()
If openConnection IsNot Nothing Then
result = openConnection.HasLiveReader(cmd)
End If
Return result
End Function


Friend Sub OnInfoMessage(errorInfo As UnsafeNativeMethods.IErrorInfo, errorCode As OleDbHResult)
Dim oleDbInfoMessageEventHandler As OleDbInfoMessageEventHandler = CType(MyBase.Events(OleDbConnection.EventInfoMessage), OleDbInfoMessageEventHandler)
If oleDbInfoMessageEventHandler IsNot Nothing Then
Try
Dim exception As OleDbException = OleDbException.CreateException(errorInfo, errorCode, Nothing)
Dim oleDbInfoMessageEventArgs As OleDbInfoMessageEventArgs = New OleDbInfoMessageEventArgs(exception)
If Bid.TraceOn Then
Bid.Trace("<oledb.OledbConnection.OnInfoMessage|API|INFO> %d#, Message='%ls'" & vbLf, Me.ObjectID, oleDbInfoMessageEventArgs.Message)
End If
oleDbInfoMessageEventHandler(Me, oleDbInfoMessageEventArgs)
Catch e As Exception
If Not ADP.IsCatchableOrSecurityExceptionType(e) Then
Throw
End If
ADP.TraceExceptionWithoutRethrow(e)
End Try
End If
End Sub


Public Override Sub Open()
Me.InnerConnection.OpenConnection(Me, Me.ConnectionFactory)
If(2 And (CType(Me.ConnectionOptions, OleDbConnectionString)).OleDbServices) <> 0 AndAlso ADP.NeedManualEnlistment() Then
Me.GetOpenConnection().EnlistTransactionInternal(Transaction.Current, True)
End If
End Sub


Friend Sub SetDataSourcePropertyValue(propertySet As Guid, propertyID As Integer, description As String, required As Boolean, value As Object)
Me.CheckStateOpen("SetProperties")
Using Dim iDBPropertiesWrapper As IDBPropertiesWrapper = Me.IDBProperties()
Using Dim dBPropSet As DBPropSet = DBPropSet.CreateProperty(propertySet, propertyID, required, value)
Bid.Trace("<oledb.IDBProperties.SetProperties|API|OLEDB> %d#" & vbLf, Me.ObjectID)
Dim oleDbHResult As OleDbHResult = iDBPropertiesWrapper.Value.SetProperties(dBPropSet.PropertySetCount, dBPropSet)
Bid.Trace("<oledb.IDBProperties.SetProperties|API|OLEDB|RET> %08X{HRESULT}" & vbLf, oleDbHResult)
If oleDbHResult < OleDbHResult.S_OK Then
Dim ex As Exception = OleDbConnection.ProcessResults(oleDbHResult, Nothing, Me)
If OleDbHResult.DB_E_ERRORSOCCURRED = oleDbHResult Then
Dim stringBuilder As StringBuilder = New StringBuilder()
Dim propertySet2 As tagDBPROP() = dBPropSet.GetPropertySet(0, propertySet)
ODB.PropsetSetFailure(stringBuilder, description, propertySet2(0).dwStatus)
ex = ODB.PropsetSetFailure(stringBuilder.ToString(), ex)
End If
If ex IsNot Nothing Then
Throw ex
End If
Else
SafeNativeMethods.Wrapper.ClearErrorInfo()
End If
End Using
End Using
End Sub


Friend Function SupportSchemaRowset(schema As Guid) As Boolean
Return Me.GetOpenConnection().SupportSchemaRowset(schema)
End Function


Friend Function ValidateTransaction(transaction As OleDbTransaction, method As String) As OleDbTransaction
Return Me.GetOpenConnection().ValidateTransaction(transaction, method)
End Function


Friend Shared Function ProcessResults(hresult As OleDbHResult, connection As OleDbConnection, src As Object) As Exception
If OleDbHResult.S_OK <= hresult AndAlso (connection Is Nothing OrElse connection.Events(OleDbConnection.EventInfoMessage) Is Nothing) Then
SafeNativeMethods.Wrapper.ClearErrorInfo()
Return Nothing
End If
Dim ex As Exception = Nothing
Dim errorInfo As UnsafeNativeMethods.IErrorInfo = Nothing
If UnsafeNativeMethods.GetErrorInfo(0, errorInfo) = OleDbHResult.S_OK AndAlso errorInfo IsNot Nothing Then
If hresult < OleDbHResult.S_OK Then
ex = OleDbException.CreateException(errorInfo, hresult, Nothing)
If OleDbHResult.DB_E_OBJECTOPEN = hresult Then
ex = ADP.OpenReaderExists(ex)
End If
OleDbConnection.ResetState(connection)
Else
If connection IsNot Nothing Then
connection.OnInfoMessage(errorInfo, hresult)
Else
Bid.Trace("<oledb.OledbConnection|WARN|INFO> ErrorInfo available, but not connection %08X{HRESULT}" & vbLf, hresult)
End If
End If
Marshal.ReleaseComObject(errorInfo)
Else
If OleDbHResult.S_OK < hresult Then
Bid.Trace("<oledb.OledbConnection|ERR|INFO> ErrorInfo not available %08X{HRESULT}" & vbLf, hresult)
Else
If hresult < OleDbHResult.S_OK Then
ex = ODB.NoErrorInformation(If((connection IsNot Nothing), connection.Provider, Nothing), hresult, Nothing)
OleDbConnection.ResetState(connection)
End If
End If
End If
If ex IsNot Nothing Then
ADP.TraceExceptionAsReturnValue(ex)
End If
Return ex
End Function


Public Shared Sub ReleaseObjectPool()
New OleDbPermission(PermissionState.Unrestricted).Demand()
Dim intPtr As IntPtr
Bid.ScopeEnter(intPtr, "<oledb.OleDbConnection.ReleaseObjectPool|API>" & vbLf)
Try
OleDbConnectionString.ReleaseObjectPool()
OleDbConnectionInternal.ReleaseObjectPool()
OleDbConnectionFactory.SingletonInstance.ClearAllPools()
Finally
Bid.ScopeLeave(intPtr)
End Try
End Sub


Private Shared Sub ResetState(connection As OleDbConnection)
If connection IsNot Nothing Then
connection.ResetState()
End If
End Sub


Public Sub New()
GC.SuppressFinalize(Me)
Me._innerConnection = DbConnectionClosedNeverOpened.SingletonInstance
End Sub


Private Sub CopyFrom(connection As OleDbConnection)
ADP.CheckArgumentNull(connection, "connection")
Me._userConnectionOptions = connection.UserConnectionOptions
Me._poolGroup = connection.PoolGroup
If DbConnectionClosedNeverOpened.SingletonInstance Is connection._innerConnection Then
Me._innerConnection = DbConnectionClosedNeverOpened.SingletonInstance
Return
End If
Me._innerConnection = DbConnectionClosedPreviouslyOpened.SingletonInstance
End Sub


Private Function ConnectionString_Get() As String
Bid.Trace("<prov.DbConnectionHelper.ConnectionString_Get|API> %d#" & vbLf, Me.ObjectID)
Dim shouldHidePassword As Boolean = Me.InnerConnection.ShouldHidePassword
Dim userConnectionOptions As DbConnectionOptions = Me.UserConnectionOptions
If userConnectionOptions Is Nothing Then
Return""
End If
Return userConnectionOptions.UsersConnectionString(shouldHidePassword)
End Function


Private Sub ConnectionString_Set(value As String)
Dim dbConnectionOptions As DbConnectionOptions = Nothing
Dim connectionPoolGroup As DbConnectionPoolGroup = Me.ConnectionFactory.GetConnectionPoolGroup(value, Nothing, dbConnectionOptions)
Dim innerConnection As DbConnectionInternal = Me.InnerConnection
Dim flag As Boolean = innerConnection.AllowSetConnectionString
If flag Then
flag = Me.SetInnerConnectionFrom(DbConnectionClosedBusy.SingletonInstance, innerConnection)
If flag Then
Me._userConnectionOptions = dbConnectionOptions
Me._poolGroup = connectionPoolGroup
Me._innerConnection = DbConnectionClosedNeverOpened.SingletonInstance
End If
End If
If Not flag Then
Throw ADP.OpenConnectionPropertySet("ConnectionString", innerConnection.State)
End If
If Bid.TraceOn Then
Dim a As String = If((dbConnectionOptions IsNot Nothing), dbConnectionOptions.UsersConnectionStringForTrace(), "")
Bid.Trace("<prov.DbConnectionHelper.ConnectionString_Set|API> %d#, '%ls'" & vbLf, Me.ObjectID, a)
End If
End Sub


<ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)>
Friend Sub Abort(e As Exception)
Dim innerConnection As DbConnectionInternal = Me._innerConnection
If ConnectionState.Open = innerConnection.State Then
Interlocked.CompareExchange(Of DbConnectionInternal)(Me._innerConnection, DbConnectionClosedPreviouslyOpened.SingletonInstance, innerConnection)
innerConnection.DoomThisConnection()
End If
If TypeOf e Is OutOfMemoryException Then
Bid.Trace("<prov.DbConnectionHelper.Abort|RES|INFO|CPOOL> %d#, Aborting operation due to asynchronous exception: %ls" & vbLf, Me.ObjectID, "OutOfMemory")
Return
End If
Bid.Trace("<prov.DbConnectionHelper.Abort|RES|INFO|CPOOL> %d#, Aborting operation due to asynchronous exception: %ls" & vbLf, Me.ObjectID, e.ToString())
End Sub


Friend Sub AddWeakReference(value As Object, tag As Integer)
Me.InnerConnection.AddWeakReference(value, tag)
End Sub


Protected Override Function BeginDbTransaction(isolationLevel As System.Data.IsolationLevel) As DbTransaction
Dim intPtr As IntPtr
Bid.ScopeEnter(intPtr, "<prov.DbConnectionHelper.BeginDbTransaction|API> %d#, isolationLevel=%d{ds.IsolationLevel}", Me.ObjectID, CInt(isolationLevel))
Dim result As DbTransaction
Try
Dim dbTransaction As DbTransaction = Me.InnerConnection.BeginTransaction(isolationLevel)
result = dbTransaction
Finally
Bid.ScopeLeave(intPtr)
End Try
Return result
End Function


Protected Override Function CreateDbCommand() As DbCommand
Dim dbCommand As DbCommand = Nothing
Dim intPtr As IntPtr
Bid.ScopeEnter(intPtr, "<prov.DbConnectionHelper.CreateDbCommand|API> %d#" & vbLf, Me.ObjectID)
Try
Dim providerFactory As DbProviderFactory = Me.ConnectionFactory.ProviderFactory
dbCommand = providerFactory.CreateCommand()
dbCommand.Connection = Me
Finally
Bid.ScopeLeave(intPtr)
End Try
Return dbCommand
End Function


Private Shared Function CreateExecutePermission() As CodeAccessPermission
Dim dBDataPermission As DBDataPermission = CType(OleDbConnectionFactory.SingletonInstance.ProviderFactory.CreatePermission(PermissionState.None), DBDataPermission)
dBDataPermission.Add(String.Empty, String.Empty, KeyRestrictionBehavior.AllowOnly)
Return dBDataPermission
End Function


Protected Override Sub Dispose(disposing As Boolean)
If disposing Then
Me._userConnectionOptions = Nothing
Me._poolGroup = Nothing
Me.Close()
End If
Me.DisposeMe(disposing)
MyBase.Dispose(disposing)
End Sub


Private Sub EnlistDistributedTransactionHelper(transaction As ITransaction)
Dim permissionSet As PermissionSet = New PermissionSet(PermissionState.None)
permissionSet.AddPermission(OleDbConnection.ExecutePermission)
permissionSet.AddPermission(New SecurityPermission(SecurityPermissionFlag.UnmanagedCode))
permissionSet.Demand()
Bid.Trace("<prov.DbConnectionHelper.EnlistDistributedTransactionHelper|RES|TRAN> %d#, Connection enlisting in a transaction." & vbLf, Me.ObjectID)
Dim transaction2 As Transaction = Nothing
If transaction IsNot Nothing Then
transaction2 = TransactionInterop.GetTransactionFromDtcTransaction(CType(transaction, IDtcTransaction))
End If
Me.InnerConnection.EnlistTransaction(transaction2)
GC.KeepAlive(Me)
End Sub


Public Override Sub EnlistTransaction(transaction As Transaction)
OleDbConnection.ExecutePermission.Demand()
Bid.Trace("<prov.DbConnectionHelper.EnlistTransaction|RES|TRAN> %d#, Connection enlisting in a transaction." & vbLf, Me.ObjectID)
Dim innerConnection As DbConnectionInternal = Me.InnerConnection
If Not innerConnection.HasEnlistedTransaction Then
innerConnection.EnlistTransaction(transaction)
GC.KeepAlive(Me)
Return
End If
If innerConnection.EnlistedTransaction.Equals(transaction) Then
Return
End If
Throw ADP.TransactionPresent()
End Sub


Private Function GetMetaDataFactory(internalConnection As DbConnectionInternal) As DbMetaDataFactory
Return Me.ConnectionFactory.GetMetaDataFactory(Me._poolGroup, internalConnection)
End Function


Friend Function GetMetaDataFactoryInternal(internalConnection As DbConnectionInternal) As DbMetaDataFactory
Return Me.GetMetaDataFactory(internalConnection)
End Function


Public Override Function GetSchema() As DataTable
Return Me.GetSchema(DbMetaDataCollectionNames.MetaDataCollections, Nothing)
End Function


Public Override Function GetSchema(collectionName As String) As DataTable
Return Me.GetSchema(collectionName, Nothing)
End Function


Public Override Function GetSchema(collectionName As String, restrictionValues As String()) As DataTable
OleDbConnection.ExecutePermission.Demand()
Return Me.InnerConnection.GetSchema(Me.ConnectionFactory, Me.PoolGroup, Me, collectionName, restrictionValues)
End Function


Friend Sub NotifyWeakReference(message As Integer)
Me.InnerConnection.NotifyWeakReference(message)
End Sub


Friend Sub PermissionDemand()
Dim poolGroup As DbConnectionPoolGroup = Me.PoolGroup
Dim dbConnectionOptions As DbConnectionOptions = If((poolGroup IsNot Nothing), poolGroup.ConnectionOptions, Nothing)
If dbConnectionOptions Is Nothing OrElse dbConnectionOptions.IsEmpty Then
Throw ADP.NoConnectionString()
End If
Dim userConnectionOptions As DbConnectionOptions = Me.UserConnectionOptions
userConnectionOptions.DemandPermission()
End Sub


Friend Sub RemoveWeakReference(value As Object)
Me.InnerConnection.RemoveWeakReference(value)
End Sub


Friend Sub SetInnerConnectionEvent([to] As DbConnectionInternal)
Dim connectionState As ConnectionState = Me._innerConnection.State And ConnectionState.Open
Dim connectionState2 As ConnectionState = [to].State And ConnectionState.Open
If connectionState <> connectionState2 AndAlso connectionState2 = ConnectionState.Closed Then
Me._closeCount += 1
End If
Me._innerConnection = [to]
If connectionState = ConnectionState.Closed AndAlso ConnectionState.Open = connectionState2 Then
Me.OnStateChange(DbConnectionInternal.StateChangeOpen)
Return
End If
If ConnectionState.Open = connectionState AndAlso connectionState2 = ConnectionState.Closed Then
Me.OnStateChange(DbConnectionInternal.StateChangeClosed)
Return
End If
If connectionState <> connectionState2 Then
Me.OnStateChange(New StateChangeEventArgs(connectionState, connectionState2))
End If
End Sub


Friend Function SetInnerConnectionFrom([to] As DbConnectionInternal, from As DbConnectionInternal) As Boolean
Return from Is Interlocked.CompareExchange(Of DbConnectionInternal)(Me._innerConnection, [to], from)
End Function


Friend Sub SetInnerConnectionTo([to] As DbConnectionInternal)
Me._innerConnection = [to]
End Sub


<Conditional("DEBUG")>
Friend Shared Sub VerifyExecutePermission()
Try
OleDbConnection.ExecutePermission.Demand()
Catch ex_0C As SecurityException
Throw
End Try
End Sub
End Class
End Namespace
الرد }}}}
تم الشكر بواسطة:
#2
Imports System
Imports System.ComponentModel
Imports System.Data.Common
Imports System.Globalization
Imports System.Runtime.InteropServices
Imports System.Security
Imports System.Security.Permissions


Namespace System.Data.OleDb
<DefaultEvent("RowUpdated"), Designer("Microsoft.VSDesigner.Data.VS.OleDbDataAdapterDesigner, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), ToolboxItem("Microsoft.VSDesigner.Data.VS.OleDbDataAdapterToolboxItem, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>
Public Class OleDbDataAdapter
Inherits DbDataAdapter
Implements IDbDataAdapter, IDataAdapter, ICloneable


Private Shared EventRowUpdated As Object = New Object()


Private Shared EventRowUpdating As Object = New Object()


Private _deleteCommand As OleDbCommand


Private _insertCommand As OleDbCommand


Private _selectCommand As OleDbCommand


Private _updateCommand As OleDbCommand


<ResCategory("DataCategory_Update"), ResDescription("DbDataAdapter_RowUpdated")>
Public Custom Event RowUpdated As OleDbRowUpdatedEventHandler
AddHandler
MyBase.Events.[AddHandler](OleDbDataAdapter.EventRowUpdated, value)
End AddHandler
RemoveHandler
MyBase.Events.[RemoveHandler](OleDbDataAdapter.EventRowUpdated, value)
End RemoveHandler
End Event


<ResCategory("DataCategory_Update"), ResDescription("DbDataAdapter_RowUpdating")>
Public Custom Event RowUpdating As OleDbRowUpdatingEventHandler
AddHandler
Dim oleDbRowUpdatingEventHandler As OleDbRowUpdatingEventHandler = CType(MyBase.Events(OleDbDataAdapter.EventRowUpdating), OleDbRowUpdatingEventHandler)
If oleDbRowUpdatingEventHandler IsNot Nothing AndAlso TypeOf value.Target Is DbCommandBuilder Then
Dim oleDbRowUpdatingEventHandler2 As OleDbRowUpdatingEventHandler = CType(ADP.FindBuilder(oleDbRowUpdatingEventHandler), OleDbRowUpdatingEventHandler)
If oleDbRowUpdatingEventHandler2 IsNot Nothing Then
MyBase.Events.[RemoveHandler](OleDbDataAdapter.EventRowUpdating, oleDbRowUpdatingEventHandler2)
End If
End If
MyBase.Events.[AddHandler](OleDbDataAdapter.EventRowUpdating, value)
End AddHandler
RemoveHandler
MyBase.Events.[RemoveHandler](OleDbDataAdapter.EventRowUpdating, value)
End RemoveHandler
End Event


<DefaultValue(Nothing), Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), ResCategory("DataCategory_Update"), ResDescription("DbDataAdapter_DeleteCommand")>
Public Property DeleteCommand() As OleDbCommand
Get
Return Me._deleteCommand
End Get
Set(value As OleDbCommand)
Me._deleteCommand = value
End Set
End Property


Property DeleteCommand() As IDbCommand
Get
Return Me._deleteCommand
End Get
Set(value As IDbCommand)
Me._deleteCommand = CType(value, OleDbCommand)
End Set
End Property


<DefaultValue(Nothing), Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), ResCategory("DataCategory_Update"), ResDescription("DbDataAdapter_InsertCommand")>
Public Property InsertCommand() As OleDbCommand
Get
Return Me._insertCommand
End Get
Set(value As OleDbCommand)
Me._insertCommand = value
End Set
End Property


Property InsertCommand() As IDbCommand
Get
Return Me._insertCommand
End Get
Set(value As IDbCommand)
Me._insertCommand = CType(value, OleDbCommand)
End Set
End Property


<DefaultValue(Nothing), Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), ResCategory("DataCategory_Fill"), ResDescription("DbDataAdapter_SelectCommand")>
Public Property SelectCommand() As OleDbCommand
Get
Return Me._selectCommand
End Get
Set(value As OleDbCommand)
Me._selectCommand = value
End Set
End Property


Property SelectCommand() As IDbCommand
Get
Return Me._selectCommand
End Get
Set(value As IDbCommand)
Me._selectCommand = CType(value, OleDbCommand)
End Set
End Property


<DefaultValue(Nothing), Editor("Microsoft.VSDesigner.Data.Design.DBCommandEditor, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), ResCategory("DataCategory_Update"), ResDescription("DbDataAdapter_UpdateCommand")>
Public Property UpdateCommand() As OleDbCommand
Get
Return Me._updateCommand
End Get
Set(value As OleDbCommand)
Me._updateCommand = value
End Set
End Property


Property UpdateCommand() As IDbCommand
Get
Return Me._updateCommand
End Get
Set(value As IDbCommand)
Me._updateCommand = CType(value, OleDbCommand)
End Set
End Property


Public Sub New()
GC.SuppressFinalize(Me)
End Sub


Public Sub New(selectCommand As OleDbCommand)
Me.[New]()
Me.SelectCommand = selectCommand
End Sub


Public Sub New(selectCommandText As String, selectConnectionString As String)
Me.[New]()
Dim connection As OleDbConnection = New OleDbConnection(selectConnectionString)
Me.SelectCommand = New OleDbCommand(selectCommandText, connection)
End Sub


Public Sub New(selectCommandText As String, selectConnection As OleDbConnection)
Me.[New]()
Me.SelectCommand = New OleDbCommand(selectCommandText, selectConnection)
End Sub


Private Sub New(from As OleDbDataAdapter)
MyBase.[New](from)
GC.SuppressFinalize(Me)
End Sub


Function Clone() As Object Implements ICloneable.Clone
Return New OleDbDataAdapter(Me)
End Function


Protected Override Function CreateRowUpdatedEvent(dataRow As DataRow, command As IDbCommand, statementType As StatementType, tableMapping As DataTableMapping) As RowUpdatedEventArgs
Return New OleDbRowUpdatedEventArgs(dataRow, command, statementType, tableMapping)
End Function


Protected Override Function CreateRowUpdatingEvent(dataRow As DataRow, command As IDbCommand, statementType As StatementType, tableMapping As DataTableMapping) As RowUpdatingEventArgs
Return New OleDbRowUpdatingEventArgs(dataRow, command, statementType, tableMapping)
End Function


Friend Shared Sub FillDataTable(dataReader As OleDbDataReader, <Out()> ParamArray dataTables As DataTable())
Dim oleDbDataAdapter As OleDbDataAdapter = New OleDbDataAdapter()
oleDbDataAdapter.Fill(dataTables, dataReader, 0, 0)
End Sub


Public Function Fill(dataTable As DataTable, ADODBRecordSet As Object) As Integer
Dim permissionSet As PermissionSet = New PermissionSet(PermissionState.None)
permissionSet.AddPermission(OleDbConnection.ExecutePermission)
permissionSet.AddPermission(New SecurityPermission(SecurityPermissionFlag.UnmanagedCode))
permissionSet.Demand()
Dim intPtr As IntPtr
Bid.ScopeEnter(intPtr, "<oledb.OleDbDataAdapter.Fill|API> %d#, dataTable, ADODBRecordSet" & vbLf, MyBase.ObjectID)
Dim result As Integer
Try
If dataTable Is Nothing Then
Throw ADP.ArgumentNull("dataTable")
End If
If ADODBRecordSet Is Nothing Then
Throw ADP.ArgumentNull("adodb")
End If
result = Me.FillFromADODB(dataTable, ADODBRecordSet, Nothing, False)
Finally
Bid.ScopeLeave(intPtr)
End Try
Return result
End Function


Public Function Fill(dataSet As DataSet, ADODBRecordSet As Object, srcTable As String) As Integer
Dim permissionSet As PermissionSet = New PermissionSet(PermissionState.None)
permissionSet.AddPermission(OleDbConnection.ExecutePermission)
permissionSet.AddPermission(New SecurityPermission(SecurityPermissionFlag.UnmanagedCode))
permissionSet.Demand()
Dim intPtr As IntPtr
Bid.ScopeEnter(intPtr, "<oledb.OleDbDataAdapter.Fill|API> %d#, dataSet, ADODBRecordSet, srcTable='%ls'" & vbLf, MyBase.ObjectID, srcTable)
Dim result As Integer
Try
If dataSet Is Nothing Then
Throw ADP.ArgumentNull("dataSet")
End If
If ADODBRecordSet Is Nothing Then
Throw ADP.ArgumentNull("adodb")
End If
If ADP.IsEmpty(srcTable) Then
Throw ADP.FillRequiresSourceTableName("srcTable")
End If
result = Me.FillFromADODB(dataSet, ADODBRecordSet, srcTable, True)
Finally
Bid.ScopeLeave(intPtr)
End Try
Return result
End Function


Private Function FillFromADODB(data As Object, adodb As Object, srcTable As String, multipleResults As Boolean) As Integer
Dim flag As Boolean = multipleResults
Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|ADODB> ADORecordsetConstruction" & vbLf)
Dim aDORecordsetConstruction As UnsafeNativeMethods.ADORecordsetConstruction = TryCast(adodb, UnsafeNativeMethods.ADORecordsetConstruction)
Dim aDORecordConstruction As UnsafeNativeMethods.ADORecordConstruction = Nothing
If aDORecordsetConstruction IsNot Nothing Then
If multipleResults Then
Bid.Trace("<oledb.Recordset15.get_ActiveConnection|API|ADODB>" & vbLf)
If(CType(adodb, UnsafeNativeMethods.Recordset15)).get_ActiveConnection() Is Nothing Then
multipleResults = False
End If
End If
Else
Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|ADODB> ADORecordConstruction" & vbLf)
aDORecordConstruction = (TryCast(adodb, UnsafeNativeMethods.ADORecordConstruction))
If aDORecordConstruction IsNot Nothing Then
multipleResults = False
End If
End If
Dim num As Integer = 0
If aDORecordsetConstruction IsNot Nothing Then
Dim num2 As Integer = 0
Dim array As Object() = New Object(1)
Dim oleDbHResult As OleDbHResult
While True
Dim srcTable2 As String = Nothing
If TypeOf data Is DataSet Then
srcTable2 = OleDbDataAdapter.GetSourceTableName(srcTable, num2)
End If
Dim flag2 As Boolean
num += Me.FillFromRecordset(data, aDORecordsetConstruction, srcTable2, flag2)
If Not multipleResults Then
GoTo IL_120
End If
array(0) = DBNull.Value
Bid.Trace("<oledb.Recordset15.NextRecordset|API|ADODB>" & vbLf)
Dim obj As Object
Dim obj2 As Object
oleDbHResult = (CType(adodb, UnsafeNativeMethods.Recordset15)).NextRecordset(obj, obj2)
Bid.Trace("<oledb.Recordset15.NextRecordset|API|ADODB|RET> %08X{HRESULT}" & vbLf, oleDbHResult)
If OleDbHResult.S_OK > oleDbHResult Then
Exit While
End If
adodb = obj2
If adodb Is Nothing Then
GoTo IL_120
End If
Bid.Trace("<oledb.IUnknown.QueryInterface|API|OLEDB|ADODB> ADORecordsetConstruction" & vbLf)
aDORecordsetConstruction = CType(adodb, UnsafeNativeMethods.ADORecordsetConstruction)
If flag2 Then
num2 += 1
End If
If aDORecordsetConstruction Is Nothing Then
GoTo IL_120
End If
End While
If CType((-2146825037), OleDbHResult) <> oleDbHResult Then
Dim errorInfo As UnsafeNativeMethods.IErrorInfo = Nothing
UnsafeNativeMethods.GetErrorInfo(0, errorInfo)
Dim empty As String = String.Empty
If errorInfo IsNot Nothing Then
ODB.GetErrorDescription(errorInfo, oleDbHResult, empty)
End If
Throw New COMException(empty, CInt(oleDbHResult))
End If
IL_120:
If aDORecordsetConstruction IsNot Nothing AndAlso (flag OrElse adodb Is Nothing) Then
Me.FillClose(True, aDORecordsetConstruction)
End If
Else
If aDORecordConstruction Is Nothing Then
Throw ODB.Fill_NotADODB("adodb")
End If
num = Me.FillFromRecord(data, aDORecordConstruction, srcTable)
If flag Then
Me.FillClose(False, aDORecordConstruction)
End If
End If
Return num
End Function


Private Function FillFromRecordset(data As Object, recordset As UnsafeNativeMethods.ADORecordsetConstruction, srcTable As String, <Out()> ByRef incrementResultCount As Boolean) As Integer
incrementResultCount = False
Dim obj As Object = Nothing
Dim chapter As IntPtr
Try
Bid.Trace("<oledb.ADORecordsetConstruction.get_Rowset|API|ADODB>" & vbLf)
obj = recordset.get_Rowset()
Bid.Trace("<oledb.ADORecordsetConstruction.get_Rowset|API|ADODB|RET> %08X{HRESULT}" & vbLf, 0)
Bid.Trace("<oledb.ADORecordsetConstruction.get_Chapter|API|ADODB>" & vbLf)
chapter = recordset.get_Chapter()
Bid.Trace("<oledb.ADORecordsetConstruction.get_Chapter|API|ADODB|RET> %08X{HRESULT}" & vbLf, 0)
Catch ex As Exception
If Not ADP.IsCatchableExceptionType(ex) Then
Throw
End If
Throw ODB.Fill_EmptyRecordSet("ADODBRecordSet", ex)
End Try
If obj IsNot Nothing Then
Dim commandBehavior As CommandBehavior = If((MissingSchemaAction.AddWithKey <> MyBase.MissingSchemaAction), CommandBehavior.[Default], CommandBehavior.KeyInfo)
commandBehavior = commandBehavior Or CommandBehavior.SequentialAccess
Dim oleDbDataReader As OleDbDataReader = Nothing
Try
Dim chapterHandle As ChapterHandle = ChapterHandle.CreateChapterHandle(chapter)
oleDbDataReader = New OleDbDataReader(Nothing, Nothing, 0, commandBehavior)
oleDbDataReader.InitializeIRowset(obj, chapterHandle, ADP.RecordsUnaffected)
oleDbDataReader.BuildMetaInfo()
incrementResultCount = (0 < oleDbDataReader.FieldCount)
If incrementResultCount Then
Dim result As Integer
If TypeOf data Is DataTable Then
result = MyBase.Fill(CType(data, DataTable), oleDbDataReader)
Return result
End If
result = MyBase.Fill(CType(data, DataSet), srcTable, oleDbDataReader, 0, 0)
Return result
End If
Finally
If oleDbDataReader IsNot Nothing Then
oleDbDataReader.Close()
End If
End Try
Return0
End If
Return0
End Function


Private Function FillFromRecord(data As Object, record As UnsafeNativeMethods.ADORecordConstruction, srcTable As String) As Integer
Dim obj As Object = Nothing
Try
Bid.Trace("<oledb.ADORecordConstruction.get_Row|API|ADODB>" & vbLf)
obj = record.get_Row()
Bid.Trace("<oledb.ADORecordConstruction.get_Row|API|ADODB|RET> %08X{HRESULT}" & vbLf, 0)
Catch ex As Exception
If Not ADP.IsCatchableExceptionType(ex) Then
Throw
End If
Throw ODB.Fill_EmptyRecord("adodb", ex)
End Try
If obj IsNot Nothing Then
Dim commandBehavior As CommandBehavior = If((MissingSchemaAction.AddWithKey <> MyBase.MissingSchemaAction), CommandBehavior.[Default], CommandBehavior.KeyInfo)
commandBehavior = commandBehavior Or (CommandBehavior.SingleRow Or CommandBehavior.SequentialAccess)
Dim oleDbDataReader As OleDbDataReader = Nothing
Try
oleDbDataReader = New OleDbDataReader(Nothing, Nothing, 0, commandBehavior)
oleDbDataReader.InitializeIRow(obj, ADP.RecordsUnaffected)
oleDbDataReader.BuildMetaInfo()
Dim result As Integer
If TypeOf data Is DataTable Then
result = MyBase.Fill(CType(data, DataTable), oleDbDataReader)
Return result
End If
result = MyBase.Fill(CType(data, DataSet), srcTable, oleDbDataReader, 0, 0)
Return result
Finally
If oleDbDataReader IsNot Nothing Then
oleDbDataReader.Close()
End If
End Try
Return0
End If
Return0
End Function


Private Sub FillClose(isrecordset As Boolean, value As Object)
Dim oleDbHResult As OleDbHResult
If isrecordset Then
Bid.Trace("<oledb.Recordset15.Close|API|ADODB>" & vbLf)
oleDbHResult = (CType(value, UnsafeNativeMethods.Recordset15)).Close()
Bid.Trace("<oledb.Recordset15.Close|API|ADODB|RET> %08X{HRESULT}" & vbLf, oleDbHResult)
Else
Bid.Trace("<oledb._ADORecord.Close|API|ADODB>" & vbLf)
oleDbHResult = (CType(value, UnsafeNativeMethods._ADORecord)).Close()
Bid.Trace("<oledb._ADORecord.Close|API|ADODB|RET> %08X{HRESULT}" & vbLf, oleDbHResult)
End If
If OleDbHResult.S_OK < oleDbHResult AndAlso CType((-2146824584), OleDbHResult) <> oleDbHResult Then
Dim errorInfo As UnsafeNativeMethods.IErrorInfo = Nothing
UnsafeNativeMethods.GetErrorInfo(0, errorInfo)
Dim empty As String = String.Empty
If errorInfo IsNot Nothing Then
ODB.GetErrorDescription(errorInfo, oleDbHResult, empty)
End If
Throw New COMException(empty, CInt(oleDbHResult))
End If
End Sub


Protected Override Sub OnRowUpdated(value As RowUpdatedEventArgs)
Dim oleDbRowUpdatedEventHandler As OleDbRowUpdatedEventHandler = CType(MyBase.Events(OleDbDataAdapter.EventRowUpdated), OleDbRowUpdatedEventHandler)
If oleDbRowUpdatedEventHandler IsNot Nothing AndAlso TypeOf value Is OleDbRowUpdatedEventArgs Then
oleDbRowUpdatedEventHandler(Me, CType(value, OleDbRowUpdatedEventArgs))
End If
MyBase.OnRowUpdated(value)
End Sub


Protected Override Sub OnRowUpdating(value As RowUpdatingEventArgs)
Dim oleDbRowUpdatingEventHandler As OleDbRowUpdatingEventHandler = CType(MyBase.Events(OleDbDataAdapter.EventRowUpdating), OleDbRowUpdatingEventHandler)
If oleDbRowUpdatingEventHandler IsNot Nothing AndAlso TypeOf value Is OleDbRowUpdatingEventArgs Then
oleDbRowUpdatingEventHandler(Me, CType(value, OleDbRowUpdatingEventArgs))
End If
MyBase.OnRowUpdating(value)
End Sub


Private Shared Function GetSourceTableName(srcTable As String, index As Integer) As String
If index = 0 Then
Return srcTable
End If
Return srcTable + index.ToString(CultureInfo.InvariantCulture)
End Function
End Class
End Namespace
microsoft partner
Team administrator
MCPD,MCITP,OCP,MP,MCC
Xprema Systems
الرد }}}}
تم الشكر بواسطة:
#3
53 مشاهدة ولا حتى شكرا
الكل بيشوف وبيهرب يعنى؟؟؟؟؟؟
microsoft partner
Team administrator
MCPD,MCITP,OCP,MP,MCC
Xprema Systems
الرد }}}}
تم الشكر بواسطة:
#4
الله يعطيك العافيه ويبارك فيك وشكرا على الكود

المشاركة الأولى ما فيه عندها زر (شكرا)
الرد }}}}
تم الشكر بواسطة:
#5
معلش انا كمبتدى دخلت ومفهمتش حاجة لو كان ممكن توضح كل كود بتاع ايه بالظبط علشان كدا الموضوع عليه نسبة مشاهدة ومفيش ردود الناس بتدخل زى كدا ومش عارفين ايه داه بس ياباشا تسلم ايدك على المجهود وياريت الناس كلها متبخلش بعلمها على حد
الرد }}}}
تم الشكر بواسطة:
#6
هذا الموضوع للأيش انا ما فهمت لو سمحت شرح بسيط ايش الكود بيعمل
الرد }}}}
تم الشكر بواسطة:
#7
نستطيع مشاهدة الكود (إذا احتجنا!!) في برنامج Reflector !
الرد }}}}
تم الشكر بواسطة:
#8
بعض الشرح بالعربى يقرب للناس الفكرة
لان الموضوع متقدم
ويحتاج توضيح
الرد }}}}
تم الشكر بواسطة:
#9
smss كتب :53 مشاهدة ولا حتى شكرا
الكل بيشوف وبيهرب يعنى؟؟؟؟؟؟


السلام عليكم ورحمة الله وبركاته






بارك الله فيك أخي سامر وزادك الله من علمه

أصارحك أنا يمكن ممن هربوا،
لكن تعرف ليش،
أول ما فتحت الموضوع وسردت الأسطر دخت وذهلت من طولها وأحسست أنني لا أفهم شيئاً، فلا شعورياً أغلقت المتصفح بأكمله،

أنت ما شاء الله مستوعب الموضوع، لكن بالنسبة للأعضاء غامض بسبب عدم وجود أي كلمة عربية توضح الأمر.

حبيبي سامر

لو أمكن تضع كل هذا الكود في مثال والأفضل يكون على VB2008 ويستحسن Express عشان الكل يستطيع تشغيله.

لي رجاء بعد إذنك أن تضع ولو على رأس كل دالة أو إجراء إيضاح بالمهمة التي يقوم بها، وليس بالضرورة شرح الأسطر التي بداخلها.


أعلم أن وقتك لم يعد كالسابق، لكن على قدر ما تستطيع.


[COLOR="#006400"]الموضوع مهم جداً ولا يستهان به،
عندي إحساس أن الكل يتمنى ذلك خصوصاً من أستاذ مثلك.


الله يوفقك ويحفظك




[/COLOR]
السلام عليكم ورحمة الله وبركاته
 
 
@@@ سامحوني، منقطع نهائياً @@@

 
الرد }}}}
تم الشكر بواسطة:
#10
@@أبورائد@@ كتب :
السلام عليكم ورحمة الله وبركاته






بارك الله فيك أخي سامر وزادك الله من علمه

أصارحك أنا يمكن ممن هربوا،
لكن تعرف ليش،
أول ما فتحت الموضوع وسردت الأسطر دخت وذهلت من طولها وأحسست أنني لا أفهم شيئاً، فلا شعورياً أغلقت المتصفح بأكمله،

أنت ما شاء الله مستوعب الموضوع، لكن بالنسبة للأعضاء غامض بسبب عدم وجود أي كلمة عربية توضح الأمر.

حبيبي سامر

لو أمكن تضع كل هذا الكود في مثال والأفضل يكون على VB2008 ويستحسن Express عشان الكل يستطيع تشغيله.

لي رجاء بعد إذنك أن تضع ولو على رأس كل دالة أو إجراء إيضاح بالمهمة التي يقوم بها، وليس بالضرورة شرح الأسطر التي بداخلها.


أعلم أن وقتك لم يعد كالسابق، لكن على قدر ما تستطيع.


[COLOR="#006400"]الموضوع مهم جداً ولا يستهان به،
عندي إحساس أن الكل يتمنى ذلك خصوصاً من أستاذ مثلك.


الله يوفقك ويحفظك




[/COLOR]
السلام عليكم ورحمة الله وبركاته

السلام عليكم ورحمة الله وبركاته
في بداية الامر احب اشكر استاذ سامر على الموضوع
جزاه الله كل الخير وبارك الله فيه
وجعله الله في موازين حسناته
ووفقه لما فيه صالح الاسلام والمسلمين
ربي يحفظه



وانا اوؤيد استاذ ابو رائد في رأيه
جزله الله خير
الرد }}}}
تم الشكر بواسطة:


التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم