本文整理汇总了C#中System.Data.Odbc.OdbcConnection.HandleError方法的典型用法代码示例。如果您正苦于以下问题:C# OdbcConnection.HandleError方法的具体用法?C# OdbcConnection.HandleError怎么用?C# OdbcConnection.HandleError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.Odbc.OdbcConnection
的用法示例。
在下文中一共展示了OdbcConnection.HandleError方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OdbcConnectionHandle
internal OdbcConnectionHandle(OdbcConnection connection, OdbcConnectionString constr, OdbcEnvironmentHandle environmentHandle) : base(ODBC32.SQL_HANDLE.DBC, environmentHandle) {
if(null == connection) {
throw ADP.ArgumentNull("connection");
}
if(null == constr) {
throw ADP.ArgumentNull("constr");
}
ODBC32.RetCode retcode;
//Set connection timeout (only before open).
//Note: We use login timeout since its odbc 1.0 option, instead of using
//connectiontimeout (which affects other things besides just login) and its
//a odbc 3.0 feature. The ConnectionTimeout on the managed providers represents
//the login timeout, nothing more.
int connectionTimeout = connection.ConnectionTimeout;
retcode = SetConnectionAttribute2(ODBC32.SQL_ATTR.LOGIN_TIMEOUT, (IntPtr)connectionTimeout, (Int32)ODBC32.SQL_IS.UINTEGER);
string connectionString = constr.UsersConnectionString(false);
// Connect to the driver. (Using the connection string supplied)
//Note: The driver doesn't filter out the password in the returned connection string
//so their is no need for us to obtain the returned connection string
// Prepare to handle a ThreadAbort Exception between SQLDriverConnectW and update of the state variables
retcode = Connect(connectionString);
connection.HandleError(this, retcode);
}
示例2: OdbcConnectionHandle
internal OdbcConnectionHandle(OdbcConnection connection, OdbcConnectionString constr, OdbcEnvironmentHandle environmentHandle) : base(ODBC32.SQL_HANDLE.DBC, environmentHandle)
{
if (connection == null)
{
throw ADP.ArgumentNull("connection");
}
if (constr == null)
{
throw ADP.ArgumentNull("constr");
}
int connectionTimeout = connection.ConnectionTimeout;
ODBC32.RetCode retcode = this.SetConnectionAttribute2(ODBC32.SQL_ATTR.LOGIN_TIMEOUT, (IntPtr) connectionTimeout, -5);
string connectionString = constr.UsersConnectionString(false);
retcode = this.Connect(connectionString);
connection.HandleError(this, retcode);
}
示例3: DeriveParametersFromStoredProcedure
// DeriveParametersFromStoredProcedure (
// OdbcConnection connection,
// OdbcCommand command);
//
// Uses SQLProcedureColumns to create an array of OdbcParameters
//
static private OdbcParameter[] DeriveParametersFromStoredProcedure(OdbcConnection connection, OdbcCommand command) {
List<OdbcParameter> rParams = new List<OdbcParameter>();
// following call ensures that the command has a statement handle allocated
CMDWrapper cmdWrapper = command.GetStatementHandle();
OdbcStatementHandle hstmt = cmdWrapper.StatementHandle;
int cColsAffected;
// maps an enforced 4-part qualified string as follows
// parts[0] = null - ignored but removal would be a run-time breaking change from V1.0
// parts[1] = CatalogName (optional, may be null)
// parts[2] = SchemaName (optional, may be null)
// parts[3] = ProcedureName
//
string quote = connection.QuoteChar(ADP.DeriveParameters);
string[] parts = MultipartIdentifier.ParseMultipartIdentifier(command.CommandText, quote, quote, '.', 4, true, Res.ODBC_ODBCCommandText, false);
if (null == parts[3]) { // match everett behavior, if the commandtext is nothing but whitespace set the command text to the whitespace
parts[3] = command.CommandText;
}
// note: native odbc appears to ignore all but the procedure name
ODBC32.RetCode retcode = hstmt.ProcedureColumns(parts[1], parts[2], parts[3], null);
// Note: the driver does not return an error if the given stored procedure does not exist
// therefore we cannot handle that case and just return not parameters.
if (ODBC32.RetCode.SUCCESS != retcode) {
connection.HandleError(hstmt, retcode);
}
using (OdbcDataReader reader = new OdbcDataReader(command, cmdWrapper, CommandBehavior.Default)) {
reader.FirstResult();
cColsAffected = reader.FieldCount;
// go through the returned rows and filter out relevant parameter data
//
while (reader.Read()) {
// devnote: column types are specified in the ODBC Programmer's Reference
// COLUMN_TYPE Smallint 16bit
// COLUMN_SIZE Integer 32bit
// DECIMAL_DIGITS Smallint 16bit
// NUM_PREC_RADIX Smallint 16bit
OdbcParameter parameter = new OdbcParameter();
parameter.ParameterName = reader.GetString(ODBC32.COLUMN_NAME-1);
switch ((ODBC32.SQL_PARAM)reader.GetInt16(ODBC32.COLUMN_TYPE-1)){
case ODBC32.SQL_PARAM.INPUT:
parameter.Direction = ParameterDirection.Input;
break;
case ODBC32.SQL_PARAM.OUTPUT:
parameter.Direction = ParameterDirection.Output;
break;
case ODBC32.SQL_PARAM.INPUT_OUTPUT:
parameter.Direction = ParameterDirection.InputOutput;
break;
case ODBC32.SQL_PARAM.RETURN_VALUE:
parameter.Direction = ParameterDirection.ReturnValue;
break;
default:
Debug.Assert(false, "Unexpected Parametertype while DeriveParamters");
break;
}
parameter.OdbcType = TypeMap.FromSqlType((ODBC32.SQL_TYPE)reader.GetInt16(ODBC32.DATA_TYPE-1))._odbcType;
parameter.Size = (int)reader.GetInt32(ODBC32.COLUMN_SIZE-1);
switch(parameter.OdbcType){
case OdbcType.Decimal:
case OdbcType.Numeric:
parameter.ScaleInternal = (Byte)reader.GetInt16(ODBC32.DECIMAL_DIGITS-1);
parameter.PrecisionInternal = (Byte)reader.GetInt16(ODBC32.NUM_PREC_RADIX-1);
break;
}
rParams.Add (parameter);
}
}
retcode = hstmt.CloseCursor();
return rParams.ToArray();;
}
示例4: DeriveParametersFromStoredProcedure
private static OdbcParameter[] DeriveParametersFromStoredProcedure(OdbcConnection connection, OdbcCommand command)
{
List<OdbcParameter> list = new List<OdbcParameter>();
CMDWrapper statementHandle = command.GetStatementHandle();
OdbcStatementHandle hrHandle = statementHandle.StatementHandle;
string leftQuote = connection.QuoteChar("DeriveParameters");
string[] strArray = MultipartIdentifier.ParseMultipartIdentifier(command.CommandText, leftQuote, leftQuote, '.', 4, true, "ODBC_ODBCCommandText", false);
if (strArray[3] == null)
{
strArray[3] = command.CommandText;
}
ODBC32.RetCode retcode = hrHandle.ProcedureColumns(strArray[1], strArray[2], strArray[3], null);
if (retcode != ODBC32.RetCode.SUCCESS)
{
connection.HandleError(hrHandle, retcode);
}
using (OdbcDataReader reader = new OdbcDataReader(command, statementHandle, CommandBehavior.Default))
{
reader.FirstResult();
int fieldCount = reader.FieldCount;
while (reader.Read())
{
OdbcParameter item = new OdbcParameter {
ParameterName = reader.GetString(3)
};
switch (reader.GetInt16(4))
{
case 1:
item.Direction = ParameterDirection.Input;
break;
case 2:
item.Direction = ParameterDirection.InputOutput;
break;
case 4:
item.Direction = ParameterDirection.Output;
break;
case 5:
item.Direction = ParameterDirection.ReturnValue;
break;
}
item.OdbcType = TypeMap.FromSqlType((ODBC32.SQL_TYPE) reader.GetInt16(5))._odbcType;
item.Size = reader.GetInt32(7);
switch (item.OdbcType)
{
case OdbcType.Decimal:
case OdbcType.Numeric:
item.ScaleInternal = (byte) reader.GetInt16(9);
item.PrecisionInternal = (byte) reader.GetInt16(10);
break;
}
list.Add(item);
}
}
retcode = hrHandle.CloseCursor();
return list.ToArray();
}