I have a little problem with my MysqlConnection objets. I have those two connection strings in my app.config :
<connectionStrings>
<add name="bdpvcLocalhost" connectionString="Persist Security Info=False;server=localhost;Uid=root;Password=***;database=bdpvc" providerName="Mysql.Data.MySqlClient"/>
<add name="bdpvcProduction" connectionString="server=pvcserver.pvcservprod.local;user id=pvc_app;Pwd=***;database=bdpvc" providerName="Mysql.Data.MySqlClient"/>
</connectionStrings>
The first connection is for a local test database, the second one is for the real production database. Since i am still early in the developpement, I use my local database. I then use the following code (I cut some of the Parameters definition cause there is really a lot)
using (MySqlConnection connection = new MySqlConnection(_connectionString))
{
connection.Open();
using (MySqlTransaction transaction = connection.BeginTransaction())
{
const string sequenceQuery = "INSERT INTO sequence " +
"(No_Sequence, No_Client, No_Produit, No_Version_Produit, " +
" No_Soumission, No_Commande, No_Reference, Date_Livraison, " +
"Date_Commande, Date_Soumission, Quantite, Status, Contact, " +
"Notes, No_Production_Ancien, Erreur_Production, No_Fichier_Log, " +
"No_Utilisateur, Date_Enregistrement, Extension_Fichier_Fax, Uuid) " +
"VALUES(?No_Sequence, ?No_Client, ?No_Produit, ?No_Version_Produit, " +
"?No_Soumission, ?No_Commande, ?No_Reference, ?Date_Livraison, ?Date_Commande, " +
"?Date_Soumission, ?Quantite, ?Status, ?Contact, ?Notes, ?No_Production_Ancien, " +
"?Erreur_Production, ?No_Fichier_Log, ?No_Utilisateur, ?Date_Enregistrement, " +
"?Extension_Fichier_Fax, ?Uuid)";
const string selectSequenceNoQuery =
"SELECT MAX(No_Sequence) AS Valeur_No_Increment FROM sequence";
const string updateSequenceNoQuery =
"UPDATE tables SET Valeur_No_Increment = ?Valeur_No_Increment WHERE Nom_Tables = 'sequence'";
int currentIncrement = 0;
MySqlCommand selectNoSequenceCommand = new MySqlCommand(selectSequenceNoQuery, connection,
transaction);
MySqlCommand updateNoSequenceCommand = new MySqlCommand(updateSequenceNoQuery, connection,
transaction);
MySqlCommand insertSequenceCommand = new MySqlCommand(sequenceQuery, connection, transaction);
//------------------------------
//This query execute perfectly!
currentIncrement = Int32.Parse(selectNoSequenceCommand.ExecuteScalar().ToString());
insertSequenceCommand.Parameters.Add("?No_Sequence", MySqlDbType.String);
//Lots and lot of parameters definition
foreach (Sequence sequence in _sequences)
{
currentIncrement++;
sequence.No_Sequence = currentIncrement.ToString();
insertSequenceCommand.Parameters["?No_Sequence"].Value = sequence.No_Sequence;
//Lots and lots of value assignement
//---------------------------------
//But this one doesn't use the right user!
insertSequenceCommand.ExecuteNonQuery();
Console.WriteLine("Inserted new sequence with Uuid " + sequence.Uuid + " and increment " +
sequence.No_Sequence);
}
updateNoSequenceCommand.Parameters.AddWithValue("?Valeur_No_Increment", currentIncrement);
updateNoSequenceCommand.ExecuteNonQuery();
transaction.Commit();
}
}
The first query execute just fine. However, the second query isn't able to execute, because "the user pvc_app
doesn't exists". But I am connecting to my local database as root! And never in my code do I switch connection string! I tried deleting the second connection string in app.config, but it kept trying to connect as pvc_app
. I rebuild the application multiple time, rebooted my computer and even uninstalled/reinstalled the ADO.NET connector, but it kept trying to connect as pvc_app! Am I doing something wrong here?
Now, where is located this mysterious "connection string cache" so I can kill it with my bare hand? Cause it's really making my life a misery right now.