private OdbcException(SerializationInfo si, StreamingContext sc) : base(si, sc) { this.odbcErrors = new OdbcErrorCollection(); this._retcode = (ODBC32.RETCODE)si.GetValue("odbcRetcode", typeof(ODBC32.RETCODE)); this.odbcErrors = (OdbcErrorCollection)si.GetValue("odbcErrors", typeof(OdbcErrorCollection)); base.HResult = -2146232009; }
internal OdbcInfoMessageEventArgs(OdbcErrorCollection errors) { foreach (OdbcError e in errors) { this.errors.Add(e); } }
internal Exception HandleErrorNoThrow(OdbcHandle hrHandle, ODBC32.RetCode retcode) { switch (retcode) { case ODBC32.RetCode.SUCCESS: break; case ODBC32.RetCode.SUCCESS_WITH_INFO: if (this.infoMessageEventHandler != null) { OdbcErrorCollection errors = ODBC32.GetDiagErrors(null, hrHandle, retcode); errors.SetSource(this.Driver); this.OnInfoMessage(new OdbcInfoMessageEventArgs(errors)); } break; default: { OdbcException innerException = OdbcException.CreateException(ODBC32.GetDiagErrors(null, hrHandle, retcode), retcode); if (innerException != null) { innerException.Errors.SetSource(this.Driver); } this.ConnectionIsAlive(innerException); return(innerException); } } return(null); }
internal static void GetDiagErrors(OdbcErrorCollection errors, string source, OdbcHandle hrHandle, RetCode retcode) { if (retcode != RetCode.SUCCESS) { short record = 0; short cchActual = 0; StringBuilder message = new StringBuilder(0x400); bool flag = true; while (flag) { int num3; string str; record = (short)(record + 1); retcode = hrHandle.GetDiagnosticRecord(record, out str, message, out num3, out cchActual); if ((RetCode.SUCCESS_WITH_INFO == retcode) && ((message.Capacity - 1) < cchActual)) { message.Capacity = cchActual + 1; retcode = hrHandle.GetDiagnosticRecord(record, out str, message, out num3, out cchActual); } if ((retcode == RetCode.SUCCESS) || (retcode == RetCode.SUCCESS_WITH_INFO)) { errors.Add(new OdbcError(source, message.ToString(), str, num3)); } } } }
// Helpers internal static OdbcErrorCollection GetDiagErrors(string source, OdbcHandle hrHandle, RetCode retcode) { OdbcErrorCollection errors = new OdbcErrorCollection(); GetDiagErrors(errors, source, hrHandle, retcode); return(errors); }
private OdbcException(SerializationInfo si, StreamingContext sc) : base(si, sc) { this.odbcErrors = new OdbcErrorCollection(); this._retcode = (ODBC32.RETCODE) si.GetValue("odbcRetcode", typeof(ODBC32.RETCODE)); this.odbcErrors = (OdbcErrorCollection) si.GetValue("odbcErrors", typeof(OdbcErrorCollection)); base.HResult = -2146232009; }
internal static void GetDiagErrors(OdbcErrorCollection errors, string source, OdbcHandle hrHandle, RetCode retcode) { if (retcode != RetCode.SUCCESS) { short record = 0; short cchActual = 0; StringBuilder message = new StringBuilder(0x400); bool flag = true; while (flag) { int num3; string str; record = (short) (record + 1); retcode = hrHandle.GetDiagnosticRecord(record, out str, message, out num3, out cchActual); if ((RetCode.SUCCESS_WITH_INFO == retcode) && ((message.Capacity - 1) < cchActual)) { message.Capacity = cchActual + 1; retcode = hrHandle.GetDiagnosticRecord(record, out str, message, out num3, out cchActual); } if ((retcode == RetCode.SUCCESS) || (retcode == RetCode.SUCCESS_WITH_INFO)) { errors.Add(new OdbcError(source, message.ToString(), str, num3)); } } } }
// non-throwing HandleError internal Exception HandleErrorNoThrow(OdbcHandle hrHandle, ODBC32.RetCode retcode) { Debug.Assert(retcode != ODBC32.RetCode.INVALID_HANDLE, "retcode must never be ODBC32.RetCode.INVALID_HANDLE"); switch (retcode) { case ODBC32.RetCode.SUCCESS: break; case ODBC32.RetCode.SUCCESS_WITH_INFO: { //Optimize to only create the event objects and obtain error info if //the user is really interested in retriveing the events... if (_infoMessageEventHandler != null) { OdbcErrorCollection errors = ODBC32.GetDiagErrors(null, hrHandle, retcode); errors.SetSource(this.Driver); OnInfoMessage(new OdbcInfoMessageEventArgs(errors)); } break; } default: OdbcException e = OdbcException.CreateException(ODBC32.GetDiagErrors(null, hrHandle, retcode), retcode); if (e != null) { e.Errors.SetSource(this.Driver); } ConnectionIsAlive(e); // this will close and throw if the connection is dead return((Exception)e); } return(null); }
// Helpers public static OdbcErrorCollection GetDiagErrors(string source, HandleRef hrHandle, SQL_HANDLE hType, RETCODE retcode) { switch (retcode) { case RETCODE.SUCCESS: return(null); case RETCODE.INVALID_HANDLE: throw ODC.InvalidHandle(); default: { Int32 NativeError; Int16 iRec = 0; Int16 cchActual = 0; OdbcErrorCollection errors = new OdbcErrorCollection(); try { using (CNativeBuffer message = new CNativeBuffer(1024)) { using (CNativeBuffer state = new CNativeBuffer(12)) { bool moreerrors = true; while (moreerrors) { retcode = (RETCODE)UnsafeNativeMethods.Odbc32.SQLGetDiagRecW( (short)hType, hrHandle, ++iRec, //Orindals are 1:base in odbc state, out NativeError, message, (short)(message.Length / 2), //cch out cchActual); //cch //Note: SUCCESS_WITH_INFO from SQLGetDiagRec would be because //the buffer is not large enough for the error string. moreerrors = (retcode == RETCODE.SUCCESS || retcode == RETCODE.SUCCESS_WITH_INFO); if (moreerrors) { //Sets up the InnerException as well... errors.Add(new OdbcError( source, (string)message.MarshalToManaged(SQL_C.WCHAR, SQL_NTS), (string)state.MarshalToManaged(SQL_C.WCHAR, SQL_NTS), NativeError ) ); } } } } } catch { throw; } return(errors); } } }
static string CreateMessage (OdbcErrorCollection errors) { StringBuilder sb = new StringBuilder (); for (int i = 0; i < errors.Count; i++) { if (i > 0) sb.Append (Environment.NewLine); OdbcError error = errors [i]; sb.AppendFormat ("ERROR [{0}] {1}", error.SQLState, error.Message); } return sb.ToString (); }
ODBC32.RETCODE _retcode; // DO NOT REMOVE! only needed for serialization purposes, because Everett had it. static internal OdbcException CreateException(OdbcErrorCollection errors, ODBC32.RetCode retcode) { StringBuilder builder = new StringBuilder(); foreach (OdbcError error in errors) { if (builder.Length > 0) { builder.Append(Environment.NewLine); } builder.Append(Res.GetString(Res.Odbc_ExceptionMessage, ODBC32.RetcodeToString(retcode), error.SQLState, error.Message)); // MDAC 68337 } OdbcException exception = new OdbcException(builder.ToString(), errors); return exception; }
internal static OdbcException CreateException(OdbcErrorCollection errors, ODBC32.RetCode retcode) { StringBuilder builder = new StringBuilder(); foreach (OdbcError error in errors) { if (builder.Length > 0) { builder.Append(Environment.NewLine); } builder.Append(Res.GetString("Odbc_ExceptionMessage", new object[] { ODBC32.RetcodeToString(retcode), error.SQLState, error.Message })); } return new OdbcException(builder.ToString(), errors); }
internal OdbcException CreateOdbcException(OdbcHandleType HandleType, IntPtr Handle) { short buflen = 256; short txtlen = 0; int nativeerror = 0; OdbcReturn ret = OdbcReturn.Success; OdbcErrorCollection errors = new OdbcErrorCollection(); while (true) { byte [] buf_MsgText = new byte [buflen * 2]; byte [] buf_SqlState = new byte [buflen * 2]; switch (HandleType) { case OdbcHandleType.Dbc: ret = libodbc.SQLError(IntPtr.Zero, Handle, IntPtr.Zero, buf_SqlState, ref nativeerror, buf_MsgText, buflen, ref txtlen); break; case OdbcHandleType.Stmt: ret = libodbc.SQLError(IntPtr.Zero, IntPtr.Zero, Handle, buf_SqlState, ref nativeerror, buf_MsgText, buflen, ref txtlen); break; case OdbcHandleType.Env: ret = libodbc.SQLError(Handle, IntPtr.Zero, IntPtr.Zero, buf_SqlState, ref nativeerror, buf_MsgText, buflen, ref txtlen); break; } if (ret != OdbcReturn.Success) { break; } string state = RemoveTrailingNullChar(Encoding.Unicode.GetString(buf_SqlState)); string message = Encoding.Unicode.GetString(buf_MsgText, 0, txtlen * 2); errors.Add(new OdbcError(message, state, nativeerror)); } string source = SafeDriver; foreach (OdbcError error in errors) { error.SetSource(source); } return(new OdbcException(errors)); }
internal static OdbcException CreateException(OdbcErrorCollection errors, ODBC32.RetCode retcode) { StringBuilder builder = new StringBuilder(); foreach (OdbcError error in errors) { if (builder.Length > 0) { builder.Append(Environment.NewLine); } builder.Append(Res.GetString("Odbc_ExceptionMessage", new object[] { ODBC32.RetcodeToString(retcode), error.SQLState, error.Message })); } return(new OdbcException(builder.ToString(), errors)); }
static string CreateMessage(OdbcErrorCollection errors) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < errors.Count; i++) { if (i > 0) { sb.Append(Environment.NewLine); } OdbcError error = errors [i]; sb.AppendFormat("ERROR [{0}] {1}", error.SQLState, error.Message); } return(sb.ToString()); }
internal static OdbcException CreateException(OdbcErrorCollection errors, ODBC32.RetCode retcode) { StringBuilder builder = new StringBuilder(); foreach (OdbcError error in errors) { if (builder.Length > 0) { builder.Append(Environment.NewLine); } builder.Append(SR.GetString(SR.Odbc_ExceptionMessage, ODBC32.RetcodeToString(retcode), error.SQLState, error.Message)); // MDAC 68337 } OdbcException exception = new OdbcException(builder.ToString(), errors); return(exception); }
internal static void GetDiagErrors(OdbcErrorCollection errors, string source, OdbcHandle hrHandle, RetCode retcode) { Debug.Assert(retcode != ODBC32.RetCode.INVALID_HANDLE, "retcode must never be ODBC32.RetCode.INVALID_HANDLE"); if (RetCode.SUCCESS != retcode) { int NativeError; short iRec = 0; short cchActual = 0; StringBuilder message = new StringBuilder(1024); string sqlState; bool moreerrors = true; while (moreerrors) { ++iRec; retcode = hrHandle.GetDiagnosticRecord(iRec, out sqlState, message, out NativeError, out cchActual); if ((RetCode.SUCCESS_WITH_INFO == retcode) && (message.Capacity - 1 < cchActual)) { message.Capacity = cchActual + 1; retcode = hrHandle.GetDiagnosticRecord(iRec, out sqlState, message, out NativeError, out cchActual); } //Note: SUCCESS_WITH_INFO from SQLGetDiagRec would be because //the buffer is not large enough for the error string. moreerrors = (retcode == RetCode.SUCCESS || retcode == RetCode.SUCCESS_WITH_INFO); if (moreerrors) { //Sets up the InnerException as well... errors.Add(new OdbcError( source, message.ToString(), sqlState, NativeError ) ); } } } }
internal OdbcException(string message, OdbcErrorCollection errors) : base(message) { this.odbcErrors = new OdbcErrorCollection(); this.odbcErrors = errors; base.HResult = -2146232009; }
internal OdbcException (OdbcErrorCollection errors) : base (CreateMessage (errors)) { odbcErrors = errors; }
internal OdbcException(string message, OdbcErrorCollection errors) : base(message) { odbcErrors = errors; HResult = HResults.OdbcException; }
private OdbcException(SerializationInfo si, StreamingContext sc) : base(si, sc) { odbcErrors = new OdbcErrorCollection(); odbcErrors = ((OdbcErrorCollection)si.GetValue( "odbcErrors", typeof(OdbcErrorCollection))); }
// runtime will call even if private... // <fxcop ignore=SerializableTypesMustHaveMagicConstructorWithAdequateSecurity /> private OdbcException(SerializationInfo si, StreamingContext sc) : base(si, sc) { _retcode = (ODBC32.RETCODE)si.GetValue("odbcRetcode", typeof(ODBC32.RETCODE)); odbcErrors = (OdbcErrorCollection)si.GetValue("odbcErrors", typeof(OdbcErrorCollection)); }
static internal void GetDiagErrors(OdbcErrorCollection errors, string source, OdbcHandle hrHandle, RetCode retcode) { Debug.Assert(retcode!=ODBC32.RetCode.INVALID_HANDLE, "retcode must never be ODBC32.RetCode.INVALID_HANDLE"); if (RetCode.SUCCESS != retcode) { Int32 NativeError; Int16 iRec = 0; Int16 cchActual = 0; StringBuilder message = new StringBuilder(1024); string sqlState; bool moreerrors = true; while(moreerrors) { ++iRec; retcode = hrHandle.GetDiagnosticRecord(iRec, out sqlState, message, out NativeError, out cchActual); if ((RetCode.SUCCESS_WITH_INFO == retcode) && (message.Capacity-1 < cchActual)) { message.Capacity = cchActual+1; retcode = hrHandle.GetDiagnosticRecord(iRec, out sqlState, message, out NativeError, out cchActual); } //Note: SUCCESS_WITH_INFO from SQLGetDiagRec would be because //the buffer is not large enough for the error string. moreerrors = (retcode == RetCode.SUCCESS || retcode == RetCode.SUCCESS_WITH_INFO); if(moreerrors) { //Sets up the InnerException as well... errors.Add(new OdbcError( source, message.ToString(), sqlState, NativeError ) ); } } } }
private bool NextResult(bool disposing, bool allresults) { ODBC32.RetCode code; bool flag; ODBC32.RetCode sUCCESS = ODBC32.RetCode.SUCCESS; bool flag3 = false; bool flag2 = this.IsCommandBehavior(CommandBehavior.SingleResult); if (this.IsClosed) { throw ADP.DataReaderClosed("NextResult"); } this._fieldNameLookup = null; if (this.IsCancelingCommand || this._noMoreResults) { return false; } this._isRead = false; this._hasRows = HasRowsStatus.DontKnow; this._fieldNameLookup = null; this.metadata = null; this.schemaTable = null; int num = 0; OdbcErrorCollection errors = null; do { this._isValidResult = false; code = this.StatementHandle.MoreResults(); flag = (code == ODBC32.RetCode.SUCCESS) || (code == ODBC32.RetCode.SUCCESS_WITH_INFO); if (code == ODBC32.RetCode.SUCCESS_WITH_INFO) { this.Connection.HandleErrorNoThrow(this.StatementHandle, code); } else if ((!disposing && (code != ODBC32.RetCode.NO_DATA)) && (code != ODBC32.RetCode.SUCCESS)) { if (errors == null) { sUCCESS = code; errors = new OdbcErrorCollection(); } ODBC32.GetDiagErrors(errors, null, this.StatementHandle, code); num++; } if (!disposing && flag) { num = 0; SQLLEN rowCount = this.GetRowCount(); this.CalculateRecordsAffected((int) rowCount); if (!flag2) { short num2; this.FieldCountNoThrow(out num2); flag3 = 0 != num2; this._isValidResult = flag3; } } } while ((((!flag2 && flag) && !flag3) || (((ODBC32.RetCode.NO_DATA != code) && allresults) && (num < 0x7d0))) || (flag2 && flag)); if (0x7d0 <= num) { Bid.Trace("<odbc.OdbcDataReader.NextResult|INFO> 2000 consecutive failed results"); } if (code == ODBC32.RetCode.NO_DATA) { this.dataCache = null; this._noMoreResults = true; } if (errors != null) { errors.SetSource(this.Connection.Driver); OdbcException innerException = OdbcException.CreateException(errors, sUCCESS); this.Connection.ConnectionIsAlive(innerException); throw innerException; } return flag; }
private OdbcInfoMessageEventArgs CreateOdbcInfoMessageEvent (OdbcErrorCollection errors) { return new OdbcInfoMessageEventArgs (errors); }
void Open () { if (State == ConnectionState.Open) throw new InvalidOperationException (); OdbcReturn ret = OdbcReturn.Error; OdbcException e = null; try { // allocate Environment handle ret = libodbc.SQLAllocHandle (OdbcHandleType.Env, IntPtr.Zero, ref henv); if ((ret != OdbcReturn.Success) && (ret != OdbcReturn.SuccessWithInfo)) { OdbcErrorCollection errors = new OdbcErrorCollection (); errors.Add (new OdbcError (SafeDriver, "Error in " + SafeDriver, "", 1)); e = new OdbcException (errors); MessageHandler (e); throw e; } ret = libodbc.SQLSetEnvAttr (henv, OdbcEnv.OdbcVersion, (IntPtr) libodbc.SQL_OV_ODBC3 , 0); if ((ret != OdbcReturn.Success) && (ret != OdbcReturn.SuccessWithInfo)) throw CreateOdbcException (OdbcHandleType.Env, henv); // allocate connection handle ret = libodbc.SQLAllocHandle (OdbcHandleType.Dbc, henv, ref hdbc); if ((ret != OdbcReturn.Success) && (ret != OdbcReturn.SuccessWithInfo)) throw CreateOdbcException (OdbcHandleType.Env, henv); // DSN connection if (ConnectionString.ToLower ().IndexOf ("dsn=") >= 0) { string _uid = string.Empty, _pwd = string.Empty, _dsn = string.Empty; string [] items = ConnectionString.Split (new char[1] {';'}); foreach (string item in items) { string [] parts = item.Split (new char[1] {'='}); switch (parts [0].Trim ().ToLower ()) { case "dsn": _dsn = parts [1].Trim (); break; case "uid": _uid = parts [1].Trim (); break; case "pwd": _pwd = parts [1].Trim (); break; } } ret = libodbc.SQLConnect(hdbc, _dsn, -3, _uid, -3, _pwd, -3); if ((ret != OdbcReturn.Success) && (ret != OdbcReturn.SuccessWithInfo)) throw CreateOdbcException (OdbcHandleType.Dbc, hdbc); } else { // DSN-less Connection string OutConnectionString = new String (' ',1024); short OutLen = 0; ret = libodbc.SQLDriverConnect (hdbc, IntPtr.Zero, ConnectionString, -3, OutConnectionString, (short) OutConnectionString.Length, ref OutLen, 0); if ((ret != OdbcReturn.Success) && (ret != OdbcReturn.SuccessWithInfo)) throw CreateOdbcException (OdbcHandleType.Dbc, hdbc); } RaiseStateChange (ConnectionState.Closed, ConnectionState.Open); } catch { // free handles if any. FreeHandles (); throw; } disposed = false; }
private bool NextResult(bool disposing, bool allresults) { // if disposing, loop through all the remaining results and ignore error messages // if allresults, loop through all results and collect all error messages for a single exception // callers are via Close(false, true), Dispose(true, false), NextResult(false,false) Debug.Assert(!disposing || !allresults, "both disposing & allresults are true"); const int MaxConsecutiveFailure = 2000; // see WebData 72126 for why more than 1000 SQLLEN cRowsAffected; Int16 cColsAffected; ODBC32.RetCode retcode, firstRetCode = ODBC32.RetCode.SUCCESS; bool hasMoreResults; bool hasColumns = false; bool singleResult = IsCommandBehavior(CommandBehavior.SingleResult); if (IsClosed) { throw ADP.DataReaderClosed("NextResult"); } _fieldNameLookup = null; if (IsCancelingCommand || _noMoreResults) { return false; } //Blow away the previous cache (since the next result set will have a different shape, //different schema data, and different data. _isRead = false; _hasRows = HasRowsStatus.DontKnow; _fieldNameLookup = null; this.metadata = null; this.schemaTable = null; int loop = 0; // infinite loop protection, max out after 2000 consecutive failed results OdbcErrorCollection errors = null; // SQLBU 342112 do { _isValidResult = false; retcode = StatementHandle.MoreResults(); hasMoreResults = ((retcode == ODBC32.RetCode.SUCCESS) ||(retcode == ODBC32.RetCode.SUCCESS_WITH_INFO)); if (retcode == ODBC32.RetCode.SUCCESS_WITH_INFO) { Connection.HandleErrorNoThrow(StatementHandle, retcode); } else if (!disposing && (retcode != ODBC32.RetCode.NO_DATA) && (ODBC32.RetCode.SUCCESS != retcode)) { // allow for building comulative error messages. if (null == errors) { firstRetCode = retcode; errors = new OdbcErrorCollection(); } ODBC32.GetDiagErrors(errors, null, StatementHandle, retcode); ++loop; } if (!disposing && hasMoreResults) { loop = 0; cRowsAffected = GetRowCount(); // get rowcount of the current resultset (if any) CalculateRecordsAffected(cRowsAffected); // update recordsaffected if (!singleResult) { // update row- and columncount FieldCountNoThrow(out cColsAffected); hasColumns = (0 != cColsAffected); _isValidResult = hasColumns; } } } while ((!singleResult && hasMoreResults && !hasColumns) // repeat for results with no columns || ((ODBC32.RetCode.NO_DATA != retcode) && allresults && (loop < MaxConsecutiveFailure)) // or process all results until done || (singleResult && hasMoreResults)); // or for any result in singelResult mode if (MaxConsecutiveFailure <= loop) { Bid.Trace("<odbc.OdbcDataReader.NextResult|INFO> 2000 consecutive failed results"); } if(retcode == ODBC32.RetCode.NO_DATA) { this.dataCache = null; _noMoreResults = true; } if (null != errors) { Debug.Assert(!disposing, "errors while disposing"); errors.SetSource(Connection.Driver); OdbcException exception = OdbcException.CreateException(errors, firstRetCode); Connection.ConnectionIsAlive(exception); throw exception; } return (hasMoreResults); }
internal OdbcException(OdbcError Error) : base(Error.Message) { odbcErrors = new OdbcErrorCollection(); odbcErrors.Add(Error); }
// runtime will call even if private... private OdbcException(SerializationInfo si, StreamingContext sc) : base(si, sc) { _retcode = (ODBC32.RETCODE) si.GetValue("odbcRetcode", typeof(ODBC32.RETCODE)); odbcErrors = (OdbcErrorCollection) si.GetValue("odbcErrors", typeof(OdbcErrorCollection)); HResult = HResults.OdbcException; }
// Helpers static internal OdbcErrorCollection GetDiagErrors(string source, OdbcHandle hrHandle, RetCode retcode) { OdbcErrorCollection errors = new OdbcErrorCollection(); GetDiagErrors(errors, source, hrHandle, retcode); return errors; }
void Open() { if (State == ConnectionState.Open) { throw new InvalidOperationException(); } OdbcReturn ret = OdbcReturn.Error; OdbcException e = null; try { // allocate Environment handle ret = libodbc.SQLAllocHandle(OdbcHandleType.Env, IntPtr.Zero, ref henv); if ((ret != OdbcReturn.Success) && (ret != OdbcReturn.SuccessWithInfo)) { OdbcErrorCollection errors = new OdbcErrorCollection(); errors.Add(new OdbcError(this)); e = new OdbcException(errors); MessageHandler(e); throw e; } ret = libodbc.SQLSetEnvAttr(henv, OdbcEnv.OdbcVersion, (IntPtr)libodbc.SQL_OV_ODBC3, 0); if ((ret != OdbcReturn.Success) && (ret != OdbcReturn.SuccessWithInfo)) { throw CreateOdbcException(OdbcHandleType.Env, henv); } // allocate connection handle ret = libodbc.SQLAllocHandle(OdbcHandleType.Dbc, henv, ref hdbc); if ((ret != OdbcReturn.Success) && (ret != OdbcReturn.SuccessWithInfo)) { throw CreateOdbcException(OdbcHandleType.Env, henv); } // DSN connection if (ConnectionString.ToLower().IndexOf("dsn=") >= 0) { string _uid = string.Empty, _pwd = string.Empty, _dsn = string.Empty; string [] items = ConnectionString.Split(new char[1] { ';' }); foreach (string item in items) { string [] parts = item.Split(new char[1] { '=' }); switch (parts [0].Trim().ToLower()) { case "dsn": _dsn = parts [1].Trim(); break; case "uid": _uid = parts [1].Trim(); break; case "pwd": _pwd = parts [1].Trim(); break; } } ret = libodbc.SQLConnect(hdbc, _dsn, -3, _uid, -3, _pwd, -3); if ((ret != OdbcReturn.Success) && (ret != OdbcReturn.SuccessWithInfo)) { throw CreateOdbcException(OdbcHandleType.Dbc, hdbc); } } else { // DSN-less Connection string OutConnectionString = new String(' ', 1024); short OutLen = 0; ret = libodbc.SQLDriverConnect(hdbc, IntPtr.Zero, ConnectionString, -3, OutConnectionString, (short)OutConnectionString.Length, ref OutLen, 0); if ((ret != OdbcReturn.Success) && (ret != OdbcReturn.SuccessWithInfo)) { throw CreateOdbcException(OdbcHandleType.Dbc, hdbc); } } RaiseStateChange(ConnectionState.Closed, ConnectionState.Open); } catch { // free handles if any. FreeHandles(); throw; } disposed = false; }
internal OdbcException(OdbcErrorCollection errors, ODBC32.RETCODE retcode) { odbcErrors = errors; _retcode = retcode; }
private OdbcInfoMessageEventArgs CreateOdbcInfoMessageEvent(OdbcErrorCollection errors) { return(new OdbcInfoMessageEventArgs(errors)); }
internal OdbcException(OdbcErrorCollection errors) : base(CreateMessage(errors)) { odbcErrors = errors; }
private OdbcException(SerializationInfo si, StreamingContext sc) : base(si, sc) { // Ignoring ODBC32.RETCODE _odbcErrors = (OdbcErrorCollection)si.GetValue("odbcErrors", typeof(OdbcErrorCollection)); HResult = HResults.OdbcException; }
internal OdbcInfoMessageEventArgs(OdbcErrorCollection errors) { this._errors = errors; }
internal OdbcException(string message, OdbcErrorCollection errors) : base(message) { _odbcErrors = errors; HResult = HResults.OdbcException; }
internal OdbcInfoMessageEventArgs (OdbcErrorCollection errors) { foreach (OdbcError e in errors) this.errors.Add (e); }
internal OdbcException(OdbcError Error) : base (Error.Message) { odbcErrors = new OdbcErrorCollection (); odbcErrors.Add (Error); }
internal OdbcException CreateOdbcException (OdbcHandleType HandleType, IntPtr Handle) { short buflen = 256; short txtlen = 0; int nativeerror = 0; OdbcReturn ret = OdbcReturn.Success; OdbcErrorCollection errors = new OdbcErrorCollection (); while (true) { byte [] buf_MsgText = new byte [buflen * 2]; byte [] buf_SqlState = new byte [buflen * 2]; switch (HandleType) { case OdbcHandleType.Dbc: ret = libodbc.SQLError (IntPtr.Zero, Handle, IntPtr.Zero, buf_SqlState, ref nativeerror, buf_MsgText, buflen, ref txtlen); break; case OdbcHandleType.Stmt: ret = libodbc.SQLError (IntPtr.Zero, IntPtr.Zero, Handle, buf_SqlState, ref nativeerror, buf_MsgText, buflen, ref txtlen); break; case OdbcHandleType.Env: ret = libodbc.SQLError (Handle, IntPtr.Zero, IntPtr.Zero, buf_SqlState, ref nativeerror, buf_MsgText, buflen, ref txtlen); break; } if (ret != OdbcReturn.Success) break; string state = RemoveTrailingNullChar (Encoding.Unicode.GetString (buf_SqlState)); string message = Encoding.Unicode.GetString (buf_MsgText, 0, txtlen * 2); errors.Add (new OdbcError (SafeDriver, message, state, nativeerror)); } string source = SafeDriver; foreach (OdbcError error in errors) error.SetSource (source); return new OdbcException (errors); }
private OdbcException (SerializationInfo si, StreamingContext sc) : base(si, sc) { odbcErrors = new OdbcErrorCollection (); odbcErrors = ((OdbcErrorCollection) si.GetValue ("odbcErrors", typeof(OdbcErrorCollection))); }