Rqgg Page 1/2

minedesertSoftware and s/w Development

Oct 31, 2013 (3 years and 7 months ago)


Unity3d iPhone SQLite database is empty when launch the app in iOS Device
Asked by
on 2013-03-29T05:33:02-04:00
I am creating database connection in my Unity3d game and i am deploying it on iOS device.
Database connection is working fine but my database is empty though i have pre-fill it before launch.

I am using Unity 4.0.1 Pro and my xCode 4.6 and code in C# language.

Here is my code in c#

void Start () { string connectionString; if (Application.platform ==
RuntimePlatform.IPhonePlayer) { connectionString = "URI=file:" + Application.persistentDataPath
+ "/Database.db"; } else { connectionString = "URI=file:Database.db"; } Debug.Log
("Connection String = " + connectionString); IDbConnection dbcon; dbcon = (IDbConnection)new
SqliteConnection (connectionString); dbcon.Open (); Debug.Log ("Start DB"); IDbCommand
dbcmd = dbcon.CreateCommand (); string sql = "SELECT * from Test "; dbcmd.CommandText =
sql; IDataReader reader = dbcmd.ExecuteReader (); while (reader.Read()) { Debug.Log ("IN
WHILE"); string FirstName = reader.GetString (0); // Print to Console Debug.Log (FirstName); } //
clean up reader.Close (); reader = null; dbcmd.Dispose (); dbcmd = null; dbcon.Close (); dbcon
= null; }
and i am getting following error in console.

SqliteException: SQLite error no such table: Test at Mono.Data.Sqlite.SQLite3.Prepare
(Mono.Data.Sqlite.SqliteConnection cnn, System.String strSql, Mono.Data.Sqlite.SqliteStatement
previous, UInt32 timeoutMS, System.String& strRemain) [0x00000] in
:0 at
Mono.Data.Sqlite.SqliteCommand.BuildNextCommand () [0x00000] in
Please help me.

Best Answer
Answer by
Nicolas Dai
on 2013-03-29T06:17:10-04:00
Try to run add this before your query:

SqliteCommand dbCommand = dbcon.CreateCommand(); string cmdText = "CREATE TABLE
Test (ID INTEGER PRIMARY KEY AUTOINCREMENT)"; dbCommand.CommandText = cmdText;
Mar 29th, 2013
Week 13, 2013
March, 2013
Custom empty cells in UITabelView
Not able to insert array value in database in iphone
Creating database for an iOS application
Does data fetch from data base effects speed of application in iOS development
How to Connect Database in Phonegap API for Android and iOS
Page 1/2
Unity3d iPhone SQLite database is empty when launch the app in iOS Device
ios app user authentication
How to catch a database exception in ios?
Ship app with DataBase iOS and Android
Passing variable to remote php file for JSON data
How to call a php method, using Xcode iOS app (can be used to connect to MYSQL database from
iOS app)
View Online
Page 2/2