System.ArgumentException: Invalid Handle!

  • Thread starter Thread starter Luiz Papa
  • Start date Start date
L

Luiz Papa

Hello all,

I am having a problem when using ado.net and ODBC. Sometimes, when I execute
a query to the database (using the DataAdapter.Fill method) it throws an
ArgumentException whith the message "Invalid Handle!".

Does anyone know what could cause this error?

TIA,
Luiz Papa


The Method that executes the fill is:
public static DataTable getPedido(string NumeroPedido)

{

dsPedido.lmPedidoDataTable dttLista = new
Matrix.Pro.Dados.dsPedido.lmPedidoDataTable();

OdbcDataAdapter objDataAdapter = new OdbcDataAdapter("SELECT * FROM
SQLUser.lmPedido WHERE Empresa=\"1\" AND TipoAdmissao=\"7\" AND
NumeroPedido=?", ActiveConnection);

objDataAdapter.SelectCommand.Parameters.Add("NumeroPedido",
OdbcType.VarChar, 13, "NumeroPedido");

objDataAdapter.SelectCommand.Parameters["NumeroPedido"].Value =
NumeroPedido;

objDataAdapter.Fill(dttLista);

return dttLista;

}

The complete Exception.ToString() is:
System.ArgumentException: Invalid Handle!
at System.Data.Odbc.OdbcConnection.HandleError(HandleRef hrHandle,
SQL_HANDLE hType, RETCODE retcode)
at System.Data.Odbc.CMDWrapper.AllocateStatementHandle(IntPtr& hstmt)
at System.Data.Odbc.OdbcCommand.GetStatementHandle()
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior
behavior, String method)
at System.Data.Odbc.OdbcCommand.ExecuteReader(CommandBehavior behavior)
at
System.Data.Odbc.OdbcCommand.System.Data.IDbCommand.ExecuteReader(CommandBeh
avior behavior)
at System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable, IDbCommand
command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at Matrix.Pro.Dados.PDPedido.getPedido(String NumeroPedido)
at Matrix.Pro.Biblioteca.Pedido.CarregaPedido(String sNumeroPedido)
at
Matrix.Pro.Interface.ctlExamesNaoFaturaveis.txdPedido_SelectedValue(Object
sender, EventArgs e)
 
Hello all,

I am having a problem when using ado.net and ODBC. Sometimes, when I execute
a query to the database (using the DataAdapter.Fill method) it throws an
ArgumentException whith the message "Invalid Handle!".

Does anyone know what could cause this error?

TIA,
Luiz Papa


The Method that executes the fill is:
public static DataTable getPedido(string NumeroPedido)

{

dsPedido.lmPedidoDataTable dttLista = new
Matrix.Pro.Dados.dsPedido.lmPedidoDataTable();

OdbcDataAdapter objDataAdapter = new OdbcDataAdapter("SELECT * FROM
SQLUser.lmPedido WHERE Empresa=\"1\" AND TipoAdmissao=\"7\" AND
NumeroPedido=?", ActiveConnection);

objDataAdapter.SelectCommand.Parameters.Add("NumeroPedido",
OdbcType.VarChar, 13, "NumeroPedido");

objDataAdapter.SelectCommand.Parameters["NumeroPedido"].Value =
NumeroPedido;

objDataAdapter.Fill(dttLista);

return dttLista;

}

The complete Exception.ToString() is:
System.ArgumentException: Invalid Handle!
at System.Data.Odbc.OdbcConnection.HandleError(HandleRef hrHandle,
SQL_HANDLE hType, RETCODE retcode)
at System.Data.Odbc.CMDWrapper.AllocateStatementHandle(IntPtr& hstmt)
at System.Data.Odbc.OdbcCommand.GetStatementHandle()
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior
behavior, String method)
at System.Data.Odbc.OdbcCommand.ExecuteReader(CommandBehavior behavior)
at
System.Data.Odbc.OdbcCommand.System.Data.IDbCommand.ExecuteReader(CommandBeh
avior behavior)
at System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable, IDbCommand
command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at Matrix.Pro.Dados.PDPedido.getPedido(String NumeroPedido)
at Matrix.Pro.Biblioteca.Pedido.CarregaPedido(String sNumeroPedido)
at
Matrix.Pro.Interface.ctlExamesNaoFaturaveis.txdPedido_SelectedValue(Object
sender, EventArgs e)

User submitted from AEWNET (http://www.aewnet.com/)
 
Back
Top