1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. We want to know how you learned Unity! Help us by taking this quick survey and have a chance at a $25 gift card
    Dismiss Notice
  5. Are you an artist or level designer going to Unite Europe? Join our roundtables there to discuss artist features.
    Dismiss Notice
  6. Unity 5.6 is now released.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice

[Help] Mysql Connector error C#

Discussion in 'Scripting' started by MoONStterTeixi, Jun 19, 2017 at 5:07 PM.

  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:
    1,635
    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 at 5:24 PM
  4. cstooch

    cstooch

    Joined:
    Apr 16, 2014
    Posts:
    197
    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:
    197
    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 at 8:48 AM