2 // System.Data.Common.ExceptionHelper
\r
5 // Boris Kirzner (borisk@mainsoft.com)
\r
10 namespace System.Data.Common
\r
12 internal sealed class ExceptionHelper
\r
14 internal static ArgumentException InvalidSizeValue (int value)
\r
16 string [] args = new string [] {value.ToString ()};
\r
17 return new ArgumentException (GetExceptionMessage ("Invalid parameter Size value '{0}'. The value must be greater than or equal to 0.",args));
\r
20 internal static ArgumentException InvalidEnumValueException (String enumeration, object value)
\r
22 return new ArgumentException (String.Format ("The {0} enumeration value, {1}, is invalid", enumeration, value));
\r
25 internal static ArgumentOutOfRangeException InvalidDataRowVersion (DataRowVersion value)
\r
27 object [] args = new object [] { "DataRowVersion", value.ToString () } ;
\r
28 return new ArgumentOutOfRangeException (GetExceptionMessage ("{0}: Invalid DataRow Version enumeration value: {1}",args));
\r
31 internal static ArgumentOutOfRangeException InvalidParameterDirection (ParameterDirection value)
\r
33 object [] args = new object [] { "ParameterDirection", value.ToString () } ;
\r
34 return new ArgumentOutOfRangeException (GetExceptionMessage ("Invalid direction '{0}' for '{1}' parameter.",args));
\r
37 internal static InvalidOperationException NoStoredProcedureExists (string procedureName) {
\r
38 object [] args = new object [1] { procedureName } ;
\r
39 return new InvalidOperationException (GetExceptionMessage ("The stored procedure '{0}' doesn't exist.", args));
\r
42 internal static ArgumentNullException ArgumentNull (string parameter)
\r
44 return new ArgumentNullException (parameter);
\r
47 internal static InvalidOperationException TransactionRequired ()
\r
49 return new InvalidOperationException (GetExceptionMessage ("Execute requires the command to have a transaction object when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized."));
\r
52 internal static ArgumentOutOfRangeException InvalidOleDbType (int value)
\r
54 string [] args = new string [] { value.ToString() };
\r
55 return new ArgumentOutOfRangeException (GetExceptionMessage ("Invalid OleDbType enumeration value: {0}",args));
\r
58 internal static ArgumentException InvalidDbType(int value)
\r
60 string [] args = new string [] { value.ToString () };
\r
61 return new ArgumentException (GetExceptionMessage ("No mapping exists from DbType {0} to a known {1}.",args));
\r
64 internal static InvalidOperationException DeriveParametersNotSupported(Type type,CommandType commandType)
\r
66 string [] args = new string [] { type.ToString(),commandType.ToString() };
\r
67 return new InvalidOperationException (GetExceptionMessage ("{0} DeriveParameters only supports CommandType.StoredProcedure, not CommandType.{1}.",args));
\r
70 internal static InvalidOperationException ReaderClosed (string mehodName)
\r
72 string [] args = new string [] { mehodName };
\r
73 return new InvalidOperationException (GetExceptionMessage ("Invalid attempt to {0} when reader is closed.",args));
\r
76 internal static ArgumentOutOfRangeException InvalidSqlDbType (int value)
\r
78 string [] args = new string [] { value.ToString () };
\r
79 return new ArgumentOutOfRangeException (GetExceptionMessage ("{0}: Invalid SqlDbType enumeration value: {1}.",args));
\r
82 internal static ArgumentException UnknownDataType (string type1, string type2)
\r
84 string [] args = new string [] { type1, type2 };
\r
85 return new ArgumentException (GetExceptionMessage ("No mapping exists from DbType {0} to a known {1}.",args));
\r
88 internal static InvalidOperationException TransactionNotInitialized ()
\r
90 return new InvalidOperationException (GetExceptionMessage ("Execute requires the command to have a transaction object when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized."));
\r
93 internal static InvalidOperationException ParametersNotInitialized (int parameterPosition,string parameterName,string parameterType)
\r
95 object [] args = new object [] { parameterPosition, parameterName, parameterType };
\r
96 return new InvalidOperationException (GetExceptionMessage ("Parameter {0}: '{1}', the property DbType is uninitialized: OleDbType.{2}.",args));
\r
99 internal static InvalidOperationException WrongParameterSize(string provider)
\r
101 string [] args = new string [] { provider };
\r
102 return new InvalidOperationException (GetExceptionMessage ("{0}.Prepare method requires all variable length parameters to have an explicitly set non-zero Size.",args));
\r
105 internal static InvalidOperationException ConnectionNotOpened (string operationName, string connectionState)
\r
107 object [] args = new object [] { operationName, connectionState };
\r
108 return new InvalidOperationException (GetExceptionMessage ("{0} requires an open and available Connection. The connection's current state is {1}.",args));
\r
111 internal static InvalidOperationException ConnectionNotInitialized (string methodName)
\r
113 object [] args = new object [] { methodName };
\r
114 return new InvalidOperationException (GetExceptionMessage ("{0}: Connection property has not been initialized.",args));
\r
117 internal static InvalidOperationException OpenConnectionRequired (string methodName, object connectionState)
\r
119 object [] args = new object [] { methodName, connectionState };
\r
120 return new InvalidOperationException (GetExceptionMessage ("{0} requires an open and available Connection. The connection's current state is {1}.",args));
\r
123 internal static InvalidOperationException OpenedReaderExists ()
\r
125 return new InvalidOperationException (GetExceptionMessage ("There is already an open DataReader associated with this Connection which must be closed first."));
\r
128 internal static InvalidOperationException ConnectionAlreadyOpen (object connectionState)
\r
130 object [] args = new object [] { connectionState };
\r
131 return new InvalidOperationException (GetExceptionMessage ("The connection is already Open (state={0}).",args));
\r
134 internal static InvalidOperationException ConnectionStringNotInitialized ()
\r
136 return new InvalidOperationException (GetExceptionMessage ("The ConnectionString property has not been initialized."));
\r
139 internal static InvalidOperationException ConnectionIsBusy (object commandType,object connectionState)
\r
141 object [] args = new object [] { commandType.ToString (), connectionState.ToString () };
\r
142 return new InvalidOperationException (GetExceptionMessage ("The {0} is currently busy {1}.",args));
\r
145 internal static InvalidOperationException NotAllowedWhileConnectionOpen (string propertyName, object connectionState)
\r
147 object [] args = new object [] { propertyName, connectionState };
\r
148 return new InvalidOperationException (GetExceptionMessage ("Not allowed to change the '{0}' property while the connection (state={1}).",args));
\r
151 internal static ArgumentException OleDbNoProviderSpecified ()
\r
153 return new ArgumentException (GetExceptionMessage ("An OLE DB Provider was not specified in the ConnectionString. An example would be, 'Provider=SQLOLEDB;'."));
\r
156 internal static ArgumentException InvalidValueForKey (string key)
\r
158 string [] args = new string [] { key };
\r
159 return new ArgumentException (String.Format ("Invalid value for key {0}",args));
\r
162 internal static InvalidOperationException ParameterSizeNotInitialized( int parameterIndex, string parameterName,string parameterType,int parameterSize)
\r
164 object [] args = new object [] { parameterIndex.ToString (), parameterName, parameterType, parameterSize.ToString () };
\r
165 return new InvalidOperationException (GetExceptionMessage ("Parameter {0}: '{1}' of type: {2}, the property Size has an invalid size: {3}",args));
\r
168 internal static ArgumentException InvalidUpdateStatus (UpdateStatus status)
\r
170 object [] args = new object [] { status };
\r
171 return new ArgumentException (GetExceptionMessage ("Invalid UpdateStatus: {0}",args));
\r
174 internal static InvalidOperationException UpdateRequiresCommand (string command)
\r
176 object [] args = new object [] { command };
\r
177 return new InvalidOperationException (GetExceptionMessage ("Auto SQL generation during {0} requires a valid SelectCommand.",args));
\r
180 internal static DataException RowUpdatedError ()
\r
182 return new DataException (GetExceptionMessage ("RowUpdatedEvent: Errors occurred; no additional is information available."));
\r
185 internal static ArgumentNullException CollectionNoNullsAllowed (object collection, object objectsType)
\r
187 object [] args = new object [] {collection.GetType ().ToString (), objectsType.ToString ()};
\r
188 return new ArgumentNullException (GetExceptionMessage ("The {0} only accepts non-null {1} type objects."));
\r
191 internal static ArgumentException CollectionAlreadyContains(object objectType,string propertyName, object propertyValue, object collection)
\r
193 object [] args = new object [] {objectType.ToString (), propertyName, propertyValue, collection.GetType ().ToString ()};
\r
194 return new ArgumentException (GetExceptionMessage ("The {0} with {1} '{2}' is already contained by this {3}.",args));
\r
197 internal static string GetExceptionMessage (string exceptionMessage,object [] args)
\r
199 if ((args == null) || (args.Length == 0)) {
\r
200 return exceptionMessage;
\r
203 return String.Format (exceptionMessage,args);
\r
207 internal static string GetExceptionMessage (string exceptionMessage)
\r
209 return GetExceptionMessage (exceptionMessage,null);
\r