Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 anu_dev · Oct 31, 2017 at 08:44 PM · androidunityeditormysql

How to connect Mysql from Android build.

Mysql db connection is working perfectly from unity editor but when I tested from Android device getting the following error, "Exception has been thrown by the target of an invocation." In the InnerException -"System.ArgumentNullException:Argument cannot be null.Paramerter name:value at System.string.Join(System.String seperator,System.String[] value) in < filename unknown>"

I am using AWS for my database environment. Using the following code to connect MySQL : private void Awake() { if (Instance == null) Instance = this; else if (Instance != null) Destroy(gameObject);

     serverMainName =""
     serverDatabase =""
     serverUsername = ""
     serverPassword = ""

     FormManager.Instance.outcomeText.text = "Awake";
     FormManager.Instance.errorPage.SetActive(true);
     InitializeConnection();
 }


 // Used for creating initial connection to the server
 public void InitializeConnection()
 {
     
     string connectionString;
     connectionString = "SERVER=" + serverMainName
         + ";DATABASE=" + serverDatabase + ";UID="
         + serverUsername + ";PASSWORD=" + serverPassword + ";";
     FormManager.Instance.outcomeText.text = "InitializeConnection"+ connectionString;
     FormManager.Instance.errorPage.SetActive(true);
     connection = new MySqlConnection(connectionString);
 }

 // Open the connection to send a message
 private bool OpenConnection()
 {
     try
     {
         connection.Open();
         return true;
     }
     catch (MySqlException e)
     {
     
         FormManager.Instance.outcomeText.text = "Open Connection: " + e.Number + " || " + e.Message;
         FormManager.Instance.errorPage.SetActive(true);
         return false;
     }
 }


Any help on this will be thankful ...

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by GothSeiDank · Oct 31, 2017 at 08:48 PM

NEVER, EVER do that. NEVER expose your database in a game script. C# scripts can be decompiled easily and this just screams for getting hacked. Access your DB indirectly through a game server and don't trust any sent data, which means, verify that the data is actually valid before you store it.

Read more here:

https://gamedev.stackexchange.com/questions/119134/should-clients-in-an-online-game-access-the-database-directly-or-through-a-game

Comment
Add comment · Show 7 · 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 anu_dev · Oct 31, 2017 at 08:56 PM 0
Share

Thank you for your quick response.Unfortunately, I am not a unity programmer by experience. the above code was written by my X-colleague and I am trying to make it work.It would be great if you can direct me to any useful tutorial to put the code for $$anonymous$$ySQL connection

avatar image GothSeiDank anu_dev · Oct 31, 2017 at 09:07 PM 0
Share

I am sorry, but this really isn't something you can explain well in a simple forums post or tutorial. But, for a VERY basic rundown, you need to program a game server that accepts connections, the game sends the data to the game server (for example as a JSON string), the server must validate it and then the game server makes the connection to the DB and stores it, if it is deemed valid. That way the access data for the database cannot fall into wrong hands. For access to the game server you can also create accounts for your players, for example via Google Play Games Authentication on Android.

avatar image anu_dev GothSeiDank · Oct 31, 2017 at 09:16 PM 0
Share

Do you recommend Rest web service for the server side to handle DB activities?

Show more comments

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

153 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Database works on unity editor,but not on android device 1 Answer

Unable to complete SSL connection 0 Answers

Project scripts stop working after building it in Android 1 Answer

Query MySQL database from android build 0 Answers

How do i save input data for later use on Android devices? 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