2009-08-13 18 views
0

私のMysqlConnectionオブジェクトに少し問題があります。私は私のApp.configファイルにこれら二つの接続文字列を持っている:MysqlCommandコネクションをunexpectedlyに切り替える

<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が存在しないため、2番目のクエリは実行できません。 しかし、私は自分のローカルデータベースにrootとして接続しています!私のコードで決して接続文字列を切り替えません!私はapp.configの2番目の接続文字列を削除しようとしましたが、それでもpvc_appとして接続しようとしました。私は複数回アプリケーションを再構築し、コンピュータを再起動し、ADO.NETコネクタをアンインストール/再インストールしましたが、pvc_appとして接続しようとしていました!私はここで何か間違っていますか?

ここで、この不思議な「接続文字列キャッシュ」がどこにあるので、私は素手でそれを殺すことができますか?私の人生は本当に不幸になっています。

答えて

0

この問題を回避するには、デフォルトのパスワードを持つ別のユーザーを作成します。接続がうまくいきました。それはADO.NETコネクタのバグのようです。