- Home /
Issue running standalone using SQLite
We're working on a game that needs access to a SQLite .db file. We can't use PlayerPrefs so we're sticking with the SQLite solution. The problem that we are running into is that it works in the editor but we get the following debug crash when we try to load the .db in a stand alone player.
ArgumentOutOfRangeException: Argument is out of range. Parameter name: options at System.Text.RegularExpressions.Regex.validate_options (RegexOptions options) [0x00000] in :0 at System.Text.RegularExpressions.Regex..ctor (System.String pattern, RegexOptions options) [0x00000] in :0 at DbLinq.Vendor.Implementation.SqlProvider..cctor () [0x00000] in :0 Rethrow as TypeInitializationException: An exception was thrown by the type initializer for DbLinq.Vendor.Implementation.SqlProvider at DbLinq.Sqlite.SqliteSqlProvider..ctor () [0x00000] in :0 at DbLinq.Sqlite.SqliteVendor..ctor () [0x00000] in :0 at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (object,object[],System.Exception&) at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0 Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation. at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0 at System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0 at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in :0 at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in :0 at System.Activator.CreateInstance (System.Type type) [0x00000] in :0 at DbLinq.Data.Linq.DataContext.GetVendor (System.String& connectionString) [0x00000] in :0 at DbLinq.Data.Linq.DataContext..ctor (System.String connectionString) [0x00000] in :0 at ContentManager.LoadDatabase (System.String sFileName, System.String sGameID, System.String sEnableFlags, System.String sDisableFlags) [0x00000] in :0 at BoardAttributes.Start () [0x00000] in :0
Our LoadDatabase function takes a string and we're passing it: ContentMan.LoadDatabase(@"C:\Content\2010\GameContent.db");
Our ContentMan then attempts to load the .db using the following code
Table<ContentFilesTable> FilesTable;
Table<FileTagsTable> TagsTable;
SQLiteConnectionStringBuilder csb = new SQLiteConnectionStringBuilder();
csb.Add("data source", sFileName);
csb.Add("DbLinqProvider", "sqlite");
SQLiteConnection connection = new SQLiteConnection(csb.ConnectionString);
DataBase = new DataContext(connection);
FilesTable = DataBase.GetTable<ContentFilesTable>();
TagsTable = DataBase.GetTable<FileTagsTable>();
//Grab the indexs with only the gameID we want
var query = from n in TagsTable where n.tags.Contains("test") == true select n;
List<FileTagsTable> MyList = query.ToList();
We're at a loss of why this successfully works in the editor and not at runtime, we're only basically just shotgunning ideas on how to fix it so any and all suggestions are welcome. Thanks!
Did you copied your database file into the data folder of your build? because a SQLite db file is not an asset that unity recognise and it won't be included in the build (like every asset that isn't referenced by anything). And make sure the path is correct for your build, i guess you use a relative path?
The poster says he's loading from an absolute path on drive C: -- something he'll need to resolve for deployment, but should still work when running his build locally.
Answer by Oksana Iashchuk · Sep 10, 2012 at 07:14 PM
http://u3d.as/content/orange-tree/sqlite-kit/3ka That is 100% managed code, full SQLite3 support, all platforms. No native dependencies.
Answer by yoyo · Feb 01, 2011 at 06:47 PM
Just trying to make head or tails of the error -- it's coming from the DataContext constructor, in a call to GetVendor.
Turns out source code for DataContext.cs is available online. It uses the vendor info in the connection string (or defaults in your case) to determine which assembly to load and what class to load from the assembly.
It appears the default assembly is DbLinq.SqlServer.dll -- perhaps this Dll is missing from your standalone build? I'd review all the SQLite assemblies you're using and make sure they are all available in the standalone build.
Answer by Matt 6 · Feb 01, 2011 at 07:48 PM
So with just guessing and trying we came up with what the issue was. Turns out our problem was the player setting Api Compatibility Level being set to .NET 2.0 subset. A change to just .NET 2.0 resolved this issue.
I'm trying to connect to a db.sqlite with basic unity and a IOS license to develop an app for the iphone 4. (I don't use Unity3d pro, I use the basic version).
When I try to build as IOS platform it return me an error, in play mode no error.
I put the dlls (System.Data and $$anonymous$$ono.Data.SqliteClient)in the Assets/Plugins folder and the database in project_name folder. (I work con $$anonymous$$ac, no Windows).
When I try to build as iOS platform it return me an error.
This is an extract of my code:
import System.Data;
import $$anonymous$$ono.Data.SqliteClient;
private var connectionString: String;
private var dbcon : SqliteConnection; //the instantiation of this creates errors
function Start () {
connectionString = "URI=file:Assets/gate.sqlite";
dbcon = new SqliteConnection ( connectionString );
dbcon.Open();
...
...
}
and the error:
Error building Player: SystemException: System.Net.Sockets are supported only on Unity iPhone Advanced. Referenced from assembly '$$anonymous$$ono.Data.Tds'. UnityEditor.HostView:OnGUI()
Thanks for the help