0
我有一个与我的MysqlConnection objets小问题。我有这两个连接字符串在我的app.config:MysqlCommand切换连接意外
<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>
第一个连接是本地测试数据库,第二个是真正的生产数据库。由于我在开发早期,我使用本地数据库。然后我用下面的代码(我切一些参数定义事业真的是有很多)
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();
}
}
第一个查询执行就好了。但是,第二个查询无法执行,因为“用户pvc_app
不存在”。 但我以root身份连接到本地数据库!而且从来没有在我的代码中切换连接字符串!我试图删除app.config中的第二个连接字符串,但它一直试图连接为pvc_app
。我多次重建应用程序,重新启动计算机,甚至卸载/重新安装了ADO.NET连接器,但它一直试图以pvc_app连接!我在这里做错了什么?
现在,这个神秘的“连接字符串缓存”位于哪里,所以我可以用我的裸手杀死它?因为现在真的让我的生活变得不幸。