LANZAR SP ORACLE

07/06/2005 - 02:33 por Israel | Informe spam
QUE TAL. SALUDOS ,,

TENGO UNA DUDA. QUISIERA SABER COMO LANZAR UN SP DE ORACLE DESDE ADO.NET ?

Hice una conexion por ODBC , prueba la conexion y me responde
correctamente pero en le codigo al llegar a la linea



int resp = comando.ExecuteNonQuery();




me manda un error :

Unhandled Exception: System.NullReferenceException: Object reference not set
to
an instance of an object.
at System.Data.Common.Odbc32.SQLExecDirectW(IntPtr StatementHandle,
String St
atementText, Int32 TextLength)
at Microsoft.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior
behavi
or, String method)
at Microsoft.Data.Odbc.OdbcCommand.ExecuteNonQuery()
at CargaHDFoto.Class1.conexionODBC()
at CargaHDFoto.Class1.Main(String[] args)


Esto es lo que uso para la conexion

OdbcConnection cn;

string strConnection = @"dsnºCUDV2;uid=cte_unico;pwd=cte_unico;";


cn = new OdbcConnection(strConnection);

string mystring = "EXEC CTE_UNICO.SpInsBioTarjetaAzteca";
OdbcCommand comando = new OdbcCommand(mystring,cn);
comando.CommandType = CommandType.StoredProcedure;

try
{
cn.Open();
Console.WriteLine("conexion OK");

int resp = comando.ExecuteNonQuery(); <<<<< AQUI DA EL ERROR



Console.WriteLine("ok SP");
}

catch (OdbcException ex)
{
cn.Close();

string mensaje = ex.ToString();
Console.WriteLine("ERROR AL EJECUTAR SP : " + mensaje);
}


Que estara fallando ?
Pueden darme una idea por favor ?

Gracias

Preguntas similare

Leer las respuestas

#1 A.Poblacion
07/06/2005 - 09:14 | Informe spam
"Israel" wrote in message
news:
string mystring = "EXEC CTE_UNICO.SpInsBioTarjetaAzteca";
OdbcCommand comando = new OdbcCommand(mystring,cn);
comando.CommandType = CommandType.StoredProcedure;

Que estara fallando ?



Creo que, tal como has escrito el string, no es un
CommandType.StoredProcedure sino un CommandType.Text. Para que sea un
StoredProcedure, tienes que quitar el EXEC del string.
Respuesta Responder a este mensaje
#2 Israel
07/06/2005 - 17:10 | Informe spam
Hola..
lo que pasa es que cuando solo le ponia el nombre del SP me mandaba un error :

Microsoft.Data.Odbc.OdbcException: ERROR [42000] [Oracle]
[ODBC][Ora]ORA-00900: invalid SQL statement

at Microsoft.Data.Odbc.OdbcConnection.HandleError(IntPtr hHandle,
SQL_HANDLE
hType, RETCODE retcode)
at Microsoft.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior
behavi
or, String method)
at Microsoft.Data.Odbc.OdbcCommand.ExecuteNonQuery()
at CargaHDFoto.Class1.conexionODBC()



Me podrias ayudar otra vez ?
Gracias

"A.Poblacion" escribió:

"Israel" wrote in message
news:
> string mystring = "EXEC CTE_UNICO.SpInsBioTarjetaAzteca";
> OdbcCommand comando = new OdbcCommand(mystring,cn);
> comando.CommandType = CommandType.StoredProcedure;

> Que estara fallando ?

Creo que, tal como has escrito el string, no es un
CommandType.StoredProcedure sino un CommandType.Text. Para que sea un
StoredProcedure, tienes que quitar el EXEC del string.




Respuesta Responder a este mensaje
#3 bartolete
20/06/2005 - 21:42 | Informe spam
Prueba indicandole en la cadena de conexion la base de datos que vas a usar
(initial catalog="...") y en mystring indica solo el nombre del
procedimiento almacenado (string mystring = "SpInsBioTarjetaAzteca";)

La sentencia cn.Close() no debe estar en el catch, porque asi solo se
ejecutara si ha habido algun error, dejandola abierta si no lo ha habido.
Ponlo mejor en el finally, asi siempre se ejecutara.

No veo nada mas raro por lo que pueda dar error.
email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida