System.ArgumentException: Invalid Handle!

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)
 
G

Guest

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/)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top