internal OdbcHandle(OdbcStatementHandle parentHandle, ODBC32.SQL_ATTR attribute) : base(IntPtr.Zero, true) { ODBC32.RetCode code; this._handleType = ODBC32.SQL_HANDLE.DESC; bool success = false; RuntimeHelpers.PrepareConstrainedRegions(); try { int num; parentHandle.DangerousAddRef(ref success); code = parentHandle.GetStatementAttribute(attribute, out this.handle, out num); } finally { if (success) { if (IntPtr.Zero != base.handle) { this._parentHandle = parentHandle; } else { parentHandle.DangerousRelease(); } } } if (ADP.PtrZero == base.handle) { throw ODBC.FailedToGetDescriptorHandle(code); } }
internal OdbcHandle(OdbcStatementHandle parentHandle, ODBC32.SQL_ATTR attribute) : base(IntPtr.Zero, true) { Debug.Assert((ODBC32.SQL_ATTR.APP_PARAM_DESC == attribute) || (ODBC32.SQL_ATTR.APP_ROW_DESC == attribute), "invalid attribute"); _handleType = ODBC32.SQL_HANDLE.DESC; int cbActual; ODBC32.RetCode retcode; bool mustRelease = false; RuntimeHelpers.PrepareConstrainedRegions(); try { // must addref before calling native so it won't be released just after parentHandle.DangerousAddRef(ref mustRelease); retcode = parentHandle.GetStatementAttribute(attribute, out base.handle, out cbActual); } finally { if (mustRelease) { if (IntPtr.Zero != base.handle) { // must call DangerousAddRef after a handle is actually created // since ReleaseHandle will only call DangerousRelease if a handle exists _parentHandle = parentHandle; } else { // without a handle, ReleaseHandle may not be called parentHandle.DangerousRelease(); } } } if (ADP.PtrZero == base.handle) { throw ODBC.FailedToGetDescriptorHandle(retcode); } // no info-message handle on getting a descriptor handle }