Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by quantum_rez · Dec 10, 2012 at 10:09 AM · mobiledatabaseonlinemysql

Cannot run database when convert to exe or play in android devices?

Hi all, im trying to make online game. i already can connect to online MySQL server.

When i test it on game view in unity it's working, but when i convert it into exe or when i played in my android devices it's not working.

Can anyone tell me why it's not working when i played it in exe or in my mobile device?

This is my code :

 using UnityEngine;
 using System.Collections;
 using System.Data;
 using MySql.Data.MySqlClient;
 
 public class DatabaseCS : MonoBehaviour {
     
     private static IDbConnection dbConnection;
     
     // Use this for initialization
     void Start () {
         
     }
     
     public void OnGUI () {
         openSqlConnection();
         
         IDataReader  reader = doQuery("SELECT Name FROM unity3d WHERE Name = 'Cube'");
         
         while (reader.Read()) {
 
             string myVar = (string) reader["Name"];
             GUI.Button(new Rect(Screen.width / 2 - 50,Screen.height / 2 - 50,100,30), myVar);
         }
         
     }
     
     public void OnApplicationQuit() {
 
         closeSqlConnection();
 
     }
     
     private static void openSqlConnection() {
         
         print ("Open");
         
         string connectionString = 
             
             "Server=myserver;" +
 
             "Database=mydatabase;" +
 
             "User ID = myuser;" +
 
             "Password=mypassword;" +
 
             "Pooling=false";
 
         dbConnection = new MySqlConnection(connectionString);
 
         dbConnection.Open();
 
         Debug.Log("Connected to database.");
 
     }
     
     private static void closeSqlConnection() {
 
         dbConnection.Close();
 
         dbConnection = null;
 
         Debug.Log("Disconnected from database.");
 
     }
     
     public static IDataReader doQuery(string sqlQuery) {
 
         IDbCommand dbCommand = dbConnection.CreateCommand();
     
         dbCommand.CommandText = sqlQuery;
     
         IDataReader reader = dbCommand.ExecuteReader();
     
         dbCommand.Dispose();
     
         dbCommand = null;
     
         return reader;
 
     }
 
     
     // Update is called once per frame
     void Update () {
     
     }
 }


Thanks

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Graham-Dunnett ♦♦ · Dec 11, 2012 at 12:14 AM 0
Share

What errors do you get from the PC standalone build? Do you have an Android version of $$anonymous$$ySql.Data.$$anonymous$$ySqlClient?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by quantum_rez · Dec 11, 2012 at 07:45 AM

i don't know what's the error, i can't see it.

what i know is my gui button not appear when i play in pc standalone and my android.

this is the code : while (reader.Read()) {

            string myVar = (string) reader["Name"];
          GUI.Button(new Rect(Screen.width / 2 - 50,Screen.height / 2 - 50,100,30), myVar);
        }

but when i change my gui button without database it's work in pc standalone and my android.

Like this : GUI.Button(new Rect(Screen.width / 2 - 50,Screen.height / 2 - 50,100,30), "My Button");

where i can get MySql.Data.MySqlClient for android?

Thanks

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Bunny83 · Dec 11, 2012 at 11:54 AM

First: NEVER direct connect to a database from a client. The client have to know your username / password and can change everything in your database. Usually you would use a webserver with a phph script which handles database access on the server.

Next thing is OnGUI is called multiple times per frame. You create, destroy and query the database at least 2 times per frame!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Workflow Question with Unity and online Database 0 Answers

Android Mysql Database online 3 Answers

Mobile Database for Unity 0 Answers

mystery MYSQL error .. 2 Answers

Update mySQL at game runtime ??? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges