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 Zoulfikar95 · Nov 08, 2018 at 04:35 PM · referencenamespace

Namespace not recognized even its added

im making an AR application using unity and vuforia as my graduation project, so im not so experienced in unity and C#.

everything is going smooth till i reached DB, now im trying to connect MySql DB to Unity and found this code some where in internet.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using System.Windows;
 using MySql.Data.MySqlClient;

 public class DBConnect : MonoBehaviour
 {

 private MySqlConnection connection;
 private string server;
 private string database;
 private string uid;
 private string password;

 //Constructor
 public DBConnect()
 {
     Initialize();
 }


 //Initialize values
 private void Initialize()
 {
     server = "localhost";
     database = "3datlas_db";
     uid = "root";
     password = "root";
     string connectionString;
     connectionString = "SERVER=" + server + ";" + "DATABASE=" +
     database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";

     connection = new MySqlConnection(connectionString);
 }

 //open connection to database
 private bool OpenConnection()
 {


     try
     {
         connection.Open();
         return true;
     }
     catch (MySqlException ex)
     {
         //When handling errors, you can your application's response based 
         //on the error number.
         //The two most common error numbers when connecting are as follows:
         //0: Cannot connect to server.
         //1045: Invalid user name and/or password.
         switch (ex.Number)
         {
             case 0:
              //   MessageBox.Show("Cannot connect to server.  Contact administrator");
                 break;

             case 1045:
           //      MessageBox.Show("Invalid username/password, please try again");
                 break;
         }
         return false;
     }
 }

 //Close connection
 private bool CloseConnection()
 {
     try
     {
         connection.Close();
         return true;
     }
     catch (MySqlException ex)
     {
         //MessageBox.Show(ex.Message);
         return false;
     }
 }

 //Insert statement
 public void Insert()
 {

 string query = "INSERT INTO tableinfo (name, age) VALUES('John Smith', '33')";

     //open connection
     if (this.OpenConnection() == true)
     {
         //create command and assign the query and connection from the constructor
         MySqlCommand cmd = new MySqlCommand(query, connection);

         //Execute command
         cmd.ExecuteNonQuery();

         //close connection
         this.CloseConnection();
     }
 }

 //Update statement
 public void Update()
 {
     string query = "UPDATE tableinfo SET name='Joe', age='22' WHERE name='John Smith'";

     //Open connection
     if (this.OpenConnection() == true)
     {
         //create mysql command
         MySqlCommand cmd = new MySqlCommand();
         //Assign the query using CommandText
         cmd.CommandText = query;
         //Assign the connection using Connection
         cmd.Connection = connection;

         //Execute query
         cmd.ExecuteNonQuery();

         //close connection
         this.CloseConnection();
     }
 }

 //Delete statement
 public void Delete()
 {
     string query = "DELETE FROM tableinfo WHERE name='John Smith'";

     if (this.OpenConnection() == true)
     {
         MySqlCommand cmd = new MySqlCommand(query, connection);
         cmd.ExecuteNonQuery();
         this.CloseConnection();
     }
 }

 //Select statement
 public List<string>[] Select()
 {
     string query = "SELECT * FROM tableinfo";

     //Create a list to store the result
     List<string>[] list = new List<string>[3];
     list[0] = new List<string>();
     list[1] = new List<string>();
     list[2] = new List<string>();

     //Open connection
     if (this.OpenConnection() == true)
     {
         //Create Command
         MySqlCommand cmd = new MySqlCommand(query, connection);
         //Create a data reader and Execute the command
         MySqlDataReader dataReader = cmd.ExecuteReader();

         //Read the data and store them in the list
         while (dataReader.Read())
         {
             list[0].Add(dataReader["id"] + "");
             list[1].Add(dataReader["name"] + "");
             list[2].Add(dataReader["age"] + "");
         }

         //close Data Reader
         dataReader.Close();

         //close Connection
         this.CloseConnection();

         //return list to be displayed
         return list;
     }
     else
     {
         return list;
     }
 }






 }

which is working till i found few errors: 1- Assets/DBconnection.cs(6,7): error CS0246: The type or namespace name MySql' could not be found. Are you missing an assembly reference? 2- Assets/DBconnection.cs(11,13): error CS0246: The type or namespace name MySqlConnection' could not be found. Are you missing an assembly reference? 3- Assets/DBconnection.cs(5,14): error CS0234: The type or namespace name Windows' does not exist in the namespace System'. Are you missing an assembly reference?

i have already added the necessary references but the problem is still there. i tried to search the internet but all of them saying to add references or to copy the necessary Dll files to assets folder in unity which i tried but still didn't work.

help plz :(

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

0 Replies

· Add your reply
  • Sort: 

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

94 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

Related Questions

The type or namespace name `GridSelection' could not be found. Are you missing a using directive or an assembly reference? 1 Answer

Referencing another C# Script Error 1 Answer

using System.Security.Cryptography.Xml in Unity 0 Answers

The type or namespace name could not be found. Are you missing a using directive or an assembly reference? 4 Answers

I use c# and have a problem about namespace System.Drawing! 3 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