Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. We're running great holiday deals on subscriptions, swag and Asset Store packages! Take a peek at this blog for more information!
    Dismiss Notice
  3. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  4. Unity 2017.2 is now released.
    Dismiss Notice
  5. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  6. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  8. Unity 2017.3 beta is now available for download.
    Dismiss Notice

[Help] Mysql Connector error C#

Discussion in 'Scripting' started by MoONStterTeixi, Jun 19, 2017.

  1. MoONStterTeixi

    MoONStterTeixi

    Joined:
    Nov 10, 2016
    Posts:
    5
    I have a problem when i try conect to Mysql server.
    This is my error:

    MySqlException: Exception of type 'MySql.Data.MySqlClient.MySqlException' was thrown.
    MySql.Data.MySqlClient.NativeDriver.Open ()
    MySql.Data.MySqlClient.Driver.Create (MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings)
    MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection ()
    MySql.Data.MySqlClient.MySqlPool.GetPooledConnection ()
    MySql.Data.MySqlClient.MySqlPool.TryToGetDriver ()

    This is my code for the conexion:

    string server = "192.168.1.128";
    string user = "*";
    string passw = "*";
    string db = "Game";

    string scon = "SERVER=" + server + ";" +
    "DATABASE=" + db + ";" +
    "UID=" + user + ";" +
    "PASSWORD=" + passw + ";"; ;

    MySqlConnection cn = new MySqlConnection(scon);
    cn.Open();
    print("Conected.");

    I try the same code out of unity in a console proyect C# and run it but when i use in unity crahs.

    I put the correct .dll (Mysql.Data, System.Data)

    Try for help me.
     
  2. jeffreyschoch

    jeffreyschoch

    Joined:
    Jan 21, 2015
    Posts:
    2,027
    You can get a more detailed information if you use a Try/Catch block. It might give you a better idea of what is going wrong:
    Code (CSharp):
    1. try {
    2.     cn.Open();
    3. } catch(MySqlException e) {
    4.     Debug.Log(e.Message); // error message
    5.     Debug.Log(e.Number); // sql error number (google it)
    6. }
     
  3. MoONStterTeixi

    MoONStterTeixi

    Joined:
    Nov 10, 2016
    Posts:
    5
    Code (CSharp):
    1. Exception of type 'MySql.Data.MySqlClient.MySqlException' was thrown.
    2. UnityEngine.Debug:Log(Object)
    3. Test:Conexion() (at Assets/Test.cs:38)  //This line is the ouput of Debug.Log(e.Message);
    4. Test:Start() (at Assets/Test.cs:11) //calling  funcion Conexion();
    The code error is the number 1042

    The code error i read is not have Permissions but have it

    I can undestan this if i can't conect but if in other out of unity conect it
     
    Last edited: Jun 19, 2017
  4. cstooch

    cstooch

    Joined:
    Apr 16, 2014
    Posts:
    354
    MySQL lists 1042 as "Message: Can't get hostname for your address".

    Are you sure that's the IP address you should use? If you're just testing everything locally on one machine (where the sql server is located) you might be able to use localhost in place of that IP. That IP address you're using is also only going to work if your MySQL server and your testing machine are on the same network. Not sure what your set up is, but you might want to describe if your MySQL server is on the same PC that you're testing on, or on a PC on the same network, or if it's out on the web somewhere, or what.
    Do you need to supply a port number?

    You did mention permissions, although that's not what MySQL's site says that error is for, but make sure your login credentials are correct too.
     
  5. MoONStterTeixi

    MoONStterTeixi

    Joined:
    Nov 10, 2016
    Posts:
    5
    This is a c# aplication out of unity and conect to my MYSQL server.
    The server are ina virtual machine on my network.
    The conection make but the same code in unity not work

    [​IMG]
     
  6. MoONStterTeixi

    MoONStterTeixi

    Joined:
    Nov 10, 2016
    Posts:
    5
    My problem persists any of you know how to fix it?
     
  7. cstooch

    cstooch

    Joined:
    Apr 16, 2014
    Posts:
    354
    Sorry, your English is difficult to understand, so I'm not sure what you meant by "The conection make". Did you mean that you successfully connected to the database from outside of Unity? If that is what you mean, was this successful connection done on the same PC as the one you are using to connect within Unity? If you have not tested connecting to the database on this PC outside of Unity, I would suggest doing so.
     
  8. MoONStterTeixi

    MoONStterTeixi

    Joined:
    Nov 10, 2016
    Posts:
    5
    Sry i don't have a good english,
    y wanna say out of unity i can conect correctly, but in unity i can't.
    I have Mysql server in a virtual machine and i conect to him from host machine.

    out from host pc i can conect and this is other thing i can undestan.
    Host range 192.168.1.37
    Virtual range 192.168.1.128
    Other pc range 192.168.1.34

    when i make ping to VM 192.168.1.37 answer me and i dont lose packages. I can undestan this.

    But i undestan if in the host i can make ping conect to shh, conect with HeidiSQL and make a program Console Witch c# and conect correctly i can undestan why in unity No.

    PD: The network card im using is NAT, but i test witch brigde too and don't work.

    Sry other time for my English and thanks for try help me.
     
    Last edited: Jun 22, 2017