Sql Server Compact 4.0 error

Hello…
I’m trying to establishing a connection with a local database,The database item added to as following:


and I think this means that the database is connected successfully:

This, is my code:

 using System;
    using UnityEngine;
    using System.Collections;
    using System.Data.SqlClient;

public class NewBehaviourScript : MonoBehaviour {
	
	int pointer_number = 0;
    string sectionID;
    string sectionName;
    string search;
    SqlConnection myConnection = new SqlConnection();
                                                  
	// Use this for initialization
	void Start () {


        try
        {
            myConnection.Open();
        }
        catch (Exception e)
        {
            print("Exception");
        }
	}
void Update () {


		if(pointer_number == 0)
		{
			if(Input.GetKey(KeyCode.A))
			{
                Mapping();
			}
		}
}

 void Mapping()
    {
        try
        {
            SqlDataReader myReader = null;
            SqlCommand myCommand = new SqlCommand("select * from Object WHERE Name="+TextField.textFieldString.ToString(),
                                                     myConnection);
            myReader = myCommand.ExecuteReader();

            while (myReader.Read())
            {
                sectionID = myReader["Section_ID"].ToString();
            }

            myReader.Close();
        }
        catch (Exception e)
        {
             print("Exception");
        }

        print(sectionID);

       try
        {
            SqlDataReader myReader = null;
            SqlCommand myCommand = new SqlCommand("select Name from Section WHERE Section_ID=" + sectionID,
                                                     myConnection);
            myReader = myCommand.ExecuteReader();
            while (myReader.Read())
            {
                sectionName = myReader["Name"].ToString();
            }
        }
        catch (Exception e)
        {
            print("Exception");
        }
}

my problem is that the exception of the connection statement in start function is always arises at run time, and also,I think my problem is My connection string,I know it’s empty,but I tried a lot of things and options but isn’t working?
The error that arise in the unity console is:

ExecuteReader requires an open connection to continue.This connection is closed.
System.Data.sqlClient.sqlCommand.ValidateCommand(System.string method, boolean asynch)
Help please…

The main issue is empty connection string - you have to specify it. For examples you can check http://www.connectionstrings.com/sql-server-compact/

Another problem is managing your connection. Opening it inside Start and keeping it opened is a bad practice. It should only be opened when necessary, which in your case means at the beginning of Mapping method. And it should be closed at the end of this method, not in the middle like you did - what connection will be used for your second command?

And most importantly - you’re using SqlConnection, but for SQL CE you need SqlCeConnection (System.Data.SqlServerCe namespace).

I also strongly suggest using statement to control your connection:

using(var connection = new SqlCeConnection(connectionString))
{
    connection.Open();
    // actual code to retrieve data from db
}

Finally I found a way to connect unity with a database, not too hard, not too simple.
The database I used is MySQL database,I install this version:

MySQL V5.7.2

And following this tutorial as is:

Connect MySQL to C# Tutorial

In this tutorial take care to the following:

1-The default username is ‘root’.

2-The tutorial has nothing about how to install MySQL database on your machine, but I found it easy and straight forward, anyway, you can refer to here as installation guide, also,During the installation I Didn’t specify any users like db-administrator,I leave it empty,I set the database password only.

3-Modify The DDL and DML methods as your needs, the modification most-likely will be on the
number of lists (which represent the columns) and names of columns inside the while loop that exists nearly in every method.

4-These are the namespaces you must have:

Using system;
Using System.collections.generic;
Using UnityEngine;
Using System.collections;
Using MySql.Data.MySqlClient;

and I’m thankful for everyone tried to help me…

Important: for player standalone(.exe) to work correctly you must go to Unity/editor/data/mono/lib/mono/unity and copy l18N.dll and l18N.West.dll to the folder asset in your project.