Search Unity

MySqlException issue

Discussion in 'Scripting' started by Hopure, Feb 28, 2015.

  1. Hopure

    Hopure

    Joined:
    Apr 3, 2014
    Posts:
    1
    Hi,

    I'm learning to connect on my database.
    This is my code :

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using MySql.Data.MySqlClient;
    4.  
    5. public class Connexion : MonoBehaviour
    6.     {
    7.  
    8.     #region Propriétés Publiques
    9.     public string account;
    10.     public string password;
    11.     public GameObject accountInputGO;
    12.     public GameObject passwordInputGO;
    13.     #endregion
    14.  
    15.     #region Propriétés Privées
    16.     private string connexionString;
    17.     private MySqlConnection connexionBDD;
    18.     private MySqlCommand commandeSQL;
    19.     private MySqlDataReader lecteurBDD;
    20.     private bool erreurBDD;
    21.     private string erreurBDDTexte;
    22.     #endregion
    23.  
    24.     #region Méthodes Unity
    25.     void Awake()
    26.     {
    27.         connexionString = "Server=localhost;Database=****;Uid=****;Pwd=*****";
    28.         connexionBDD = new MySqlConnection(connexionString);    
    29.     }
    30.  
    31.     void Update()
    32.     {
    33.          
    34.     }
    35.     #endregion
    36.  
    37.     #region Méthodes Autres
    38.     public void CreationBoutton() {
    39.         if (accountInputGO.GetComponent<UIInput>().value != "" && passwordInputGO.GetComponent<UIInput>().value != "") {
    40.             account = accountInputGO.GetComponent<UIInput>().value;
    41.             password = passwordInputGO.GetComponent<UIInput>().value;
    42.             CreationCompte();
    43.         }
    44.    
    45.     }
    46.  
    47.    public void CreationCompte() {
    48.        try {
    49.        }
    50.  
    51.        catch (MySqlException ex) {
    52.  
    53.        }
    54.    }
    55.  
    56.     public void VoirCompteBoutton() {
    57.     }
    58.     #endregion
    59. } // Fin du Script
    catch (MySqlException ex) make this error :
    The type caught or thrown must be derived from System.Exception


    When i try this with classic C# application (without unity), there is no problem
    When i try with unity, i have this error.

    MySql.Data.dll (v2.0) is referenced in Unity and Visual studio
    Could you help me before i become crazy ^^'
     
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    You say that this works in a "classic" C# application, but I assume you're not compiling exactly the same code, because I don't think a standalone C# app would like the "using UnityEngine" statement at the top of this file. Maybe there's some other minor difference you're overlooking between the working and non-working versions?

    Have you tried just copying the entire sourcefile from the working "classic" C# app into Unity, with no modifications at all?
     
  3. RChrispy

    RChrispy

    Joined:
    Dec 18, 2013
    Posts:
    71
    I have the same problem maybe someone found a solution for this?