Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • SQLite3 with Unity5 : Connectivity

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 949
    Comment on it

    First you have to add an extension (named.. SQLite Manager) in the Mozilla Firefox browser. (It is simply for managing database in some cases).

    Then you need three .dll files (known as ASSEMBLIES)..., (these files are simply PLUGINS for SQLite3) :

    1. sqlite3.dll --> (initially this file is "sqlite3-64.dll"., the only thing you have to do is.. change the file name to.. "sqlite3.dll")

    download link..,

    http://goo.gl/pkQIa7 64Bit download

    http://goo.gl/gTQn 32Bit download

     

    2. Mono.Data.Sqlite.dll --->  (this file is already in your system.., I am just giving the path for this.., )

    PATH - "C:\Program Files\Unity\Editor\Data\Mono\lib\mono\2.0\Mono.Data.Sqlite.dll"

     

    3. System.Data.dll --->  (this file is already in your system.., I am just giving the path for this.., )

    PATH - "C:\Program Files\Unity\Editor\Data\Mono\lib\mono\2.0\System.Data.dll"

     

    ------------------------------------------------------------------------|

    Now.. open Unity and create new project..., then create one empty game object and one C# script (like ScoresRecord.cs). Apply or add this C# Script to the empty gameobject.

    Create one new folder (name it as.. PLUGINS) in the ASSETS folder of your current Unity project.., and add the three .dll files in this Plugins folder.

    Then.., open SQLite Manager and create new database (ScoresDB.sqlite).., from Database menu bar.

    (Note : save this database file to ASSETS folder of your current Unity Project...)

    ------------------------------------------------------------------------|

    All things are done.. now only thing is required..., is the.. code behind for DB conectivity...,

    Now copy this code in your C# script..,

    using UnityEngine;
    using System;
    using System.Data;
    using Mono.Data.Sqlite;
    
    public class ScoresRecord : MonoBehaviour {
        
        private string conStr;
        
        void Start ()
        {
            conStr = "URI=file:" + Application.dataPath + "/ScoresDB.sqlite";
            GetScores ();
        }
        
        // 1. Establishing Connection
        private void GetScores()
        {
            IDbConnection con = null;
            try
            {
                con=new SqliteConnection(conStr);
                con.Open ();
                Debug.Log ("DATABASE connected..!");
            }
            catch(Exception ex)
            {
                Debug.Log (ex.ToString ());
            }
            finally
            {
                con.Close ();
            }
        }
    }

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: