[C#] [Oracle] Problème d'Update
Bonjour,
j'ai actuellement un problème très bizarre que je ne comprends pas. Voici un extrait de mon code ( avec une requête simplifié au maximum pour démarrer ):
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| string strSQL = "UPDATE REPTYPE_RECLAMATION_V2 SET RPT_ACTIF = 0 WHERE (RPT_ID = 1);";
OracleCommand oraCmd = new OracleCommand(strSQL, oraCnx);
oraCmd.CommandType = CommandType.Text;
try
{
int i = oraCmd.ExecuteNonQuery();
}
catch(OracleException excOra)
{
Console.WriteLine(excOra.Message);
} |
l'object oraCnx est bien initialisé car je passe par le même code pour réaliser des requêtes d'insertion.
Cela me produit l'exception suivante :
Code:
[13:14:04]ORA-00911: invalid character
En effet dans la requête SQL j'ai mis un point virgule en fin de ligne. Après lecture des causes de l'exception j'enlève donc ce point virgule. Je relance mon application et la ca freeze ( je suis en debug ) sur l'ExecuteNonQuery(). :? Je ne trouve pas sur le net de tuto avec des requêtes update similaires. Je me suis aidé de celui ci pour développer ce que j'ai à faire. Tout marchait pour le mieux concernant la connexion/déconnexion à la BDD, les sélections et même insertions.... mais les mises à jour ne fonctionnent pas :?
Merci d'avance pour votre aide :D
Re: [C#] [Oracle] Problème d'Update
Initialement mon code ressemble plutôt à ca ( voir les trois lignes mis en commentaires ).
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| string strSQL = @"UPDATE REPTYPE_RECLAMATION_V2 SET RPT_ACTIF = 0 WHERE (RPT_ID = 1);";
//OracleTransaction oraTrans = oraCnx.BeginTransaction();
OracleCommand oraCmd = new OracleCommand(strSQL, oraCnx);
oraCmd.CommandType = CommandType.Text;
try
{
int i = oraCmd.ExecuteNonQuery();
//oraTrans.Commit();
}
catch(OracleException excOra)
{
Console.WriteLine(excOra.Message);
//oraTrans.Rollback();
}
catch(InvalidOperationException excInvalid)
{
Console.WriteLine(excInvalide.Message);
//oraTrans.Rollback();
} |
Et ca me faisant cette exception que je comprends pas du tout :?:
Code:
Execute requires the Command object to have a Transaction object when the Connection object assigned to the Command is in a pending local transaction. The Transaction property of the Command has not been initialized.
... au lieu de celle dont je parlais dans mon premier post. Donc j'ai retiré c'est trois lignes pour "simplifier" . :wink:
Par contre maintenant ca ne freeze plus quelque soit la syntaxe de fin et avec/sans le '@' dont tu as parlé.
Re: [C#] [Oracle] Problème d'Update
Je n'ai pas du être très clair dans mon message précédent, je vais donc le remettre au "propre" :wink:
Citation:
Envoyé par _Air_
Initialement mon code ressemble plutôt à ca
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| string strSQL = "UPDATE REPTYPE_RECLAMATION_V2 SET RPT_ACTIF = 0 WHERE (RPT_ID = 1)";
OracleTransaction oraTrans = oraCnx.BeginTransaction();
OracleCommand oraCmd = new OracleCommand(strSQL, oraCnx);
oraCmd.CommandType = CommandType.Text;
try
{
int i = oraCmd.ExecuteNonQuery();
oraTrans.Commit();
}
catch(OracleException excOra)
{
Console.WriteLine(excOra.Message);
oraTrans.Rollback();
}
catch(InvalidOperationException excInvalid)
{
Console.WriteLine(excInvalide.Message);
oraTrans.Rollback();
} |
Ca génère cette exception ( de type InvalidOperation ) que je ne comprends pas du tout :?:
Code:
1 2 3 4 5 6 7 8 9 10 11
|
MESSAGE : Execute requires the Command object to have a Transaction object when the Connection object assigned to the Command is in a pending local transaction. The Transaction property of the Command has not been initialized.
SOURCE : System.Data.OracleClient
et le STACKTRACE:
at System.Data.OracleClient.OracleCommand.Execute(OciHandle statementHandle, CommandBehavior behavior, Boolean isReader, Boolean needRowid, OciHandle& rowidDescriptor, ArrayList& refCursorParameterOrdinals)
at System.Data.OracleClient.OracleCommand.Execute(OciHandle statementHandle, CommandBehavior behavior, Boolean needRowid, OciHandle& rowidDescriptor)
at System.Data.OracleClient.OracleCommand.ExecuteNonQueryInternal(Boolean needRowid, OciHandle& rowidDescriptor)
at System.Data.OracleClient.OracleCommand.ExecuteNonQuery()
at _oraNET_._Work_.CReclam_RepType.storeData(COraConnexion& oraCnx, Int32 iID) in ... |
.. bref j'ai essayé et ré-essayé tout un tas de "combinaison de code" ( dont celle ci dessus bien évidemment) mais rien ne fonctionne :?