| Laura San Roman |
Hola!!
De nuevo tengo un problemilla esta vez con transacciones. ?Alguien me podria ayudar?. Tengo el siguiente codigo:
SqlConnection myConnection = new SqlConnection("server=localhost;database=pubs;Trusted_Connection=yes"); myConnection.Open(); //Comienza la transaccion SqlTransaction myTrans = myConnection.BeginTransaction(); SqlCommand myCommand = new SqlCommand(); myCommand.Transaction = myTrans; try { myCommand.CommandText = CadenaSQL; myCommand.ExecuteNonQuery(); myCommand.CommandText = CadenaSQL1; myCommand.ExecuteNonQuery(); myTrans.Commit(); } catch(Exception e) { myTrans.Rollback(); } finally { myConnection.Close(); }
CadenaSQL tiene un insert a la base de datos que funciona perfectamente, pero cuando llega al metodo myCommand.ExecuteNonQuery() siempre me sale por la excepcion con el mismo mensaje: La conexion no ha sido inicializada. Llevo dandole vueltas y ya no veo nada ?alguien me puede decir que estoy haciendo mal?
Gracias y un saludo
|
|
| |
| |
| Luis Ruiz |
abre la conexion
nombredetuconexion.open
antes de darle executenonquery
kike
--- Laura San Roman <Click here to reveal e-mail address> wrote: [Original message clipped]
__________________________________________________ Do You Yahoo!? Make international calls for as low as $.04/minute with Yahoo! Messenger http://phonecard.yahoo.com/
|
|
| |
|
| |
| Luis Ruiz |
creo qute te falta asignarle la conexion a tu comando
myCommand.Connection = SqlCon
me equivoque vi que abristes la conexion
kike
--- Laura San Roman <Click here to reveal e-mail address> wrote: [Original message clipped]
__________________________________________________ Do You Yahoo!? Make international calls for as low as $.04/minute with Yahoo! Messenger http://phonecard.yahoo.com/
|
|
| |
|
| |
| Adrian Garcia |
Probaste con: .... myCommand.ActiveConection = myConnection; myCommand.Transaction = myTrans; try ....
Saludos
Adrian Garcia Microsoft MVP [C#/ASP] - MCSD NDSoft Filial Córdoba - Argentina Click here to reveal e-mail address
----Original Message Follows---- From: Laura San Roman <Click here to reveal e-mail address> Reply-To: "aspnges" <Click here to reveal e-mail address> To: "aspnges" <Click here to reveal e-mail address> Subject: [aspnges] Duda Transacciones Date: Fri, 24 Aug 2001 11:52:25 +0100
Hola!!
De nuevo tengo un problemilla esta vez con transacciones. ?Alguien me podria ayudar?. Tengo el siguiente codigo:
SqlConnection myConnection = new SqlConnection("server=localhost;database=pubs;Trusted_Connection=yes"); myConnection.Open(); //Comienza la transaccion SqlTransaction myTrans = myConnection.BeginTransaction(); SqlCommand myCommand = new SqlCommand(); myCommand.Transaction = myTrans; try { myCommand.CommandText = CadenaSQL; myCommand.ExecuteNonQuery(); myCommand.CommandText = CadenaSQL1; myCommand.ExecuteNonQuery(); myTrans.Commit(); } catch(Exception e) { myTrans.Rollback(); } finally { myConnection.Close(); }
CadenaSQL tiene un insert a la base de datos que funciona perfectamente, pero cuando llega al metodo myCommand.ExecuteNonQuery() siempre me sale por la excepcion con el mismo mensaje: La conexion no ha sido inicializada. Llevo dandole vueltas y ya no veo nada ?alguien me puede decir que estoy haciendo mal?
Gracias y un saludo
| [aspnges] member Click here to reveal e-mail address = YOUR ID | http://www.asplists.com/asplists/aspnges.asp = JOIN/QUIT | http://www.asplists.com/search = SEARCH Archives
_________________________________________________________________ Descargue GRATUITAMENTE MSN Explorer en http://explorer.msn.es/intl.asp
|
|
| |
|
| | |