Search Unity

  1. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  2. Unity 2017.1 is now released.
    Dismiss Notice
  3. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  4. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice

Yes, another DllNotFoundException: System.Data.SQLite.DLL post

Discussion in 'Scripting' started by kaine106, Nov 5, 2010.

  1. kaine106

    kaine106

    Joined:
    Oct 15, 2010
    Posts:
    5
    I get the following error when trying to run a built game. This works fine when running in Unity editor. I don't seem to get any database data from the built version and I get this message in the output_log.txt file. I do have the dll in the assets folder. It also shows up in the managed folder under the built app. It is a Windows build using Unity 3 indie version.

    DllNotFoundException: System.Data.SQLite.DLL at (wrapper managed-to-native) System.Data.SQLite.UnsafeNativeMethods:sqlite3_open_interop (byte[],int,intptr) at System.Data.SQLite.SQLite3.Open (System.String strFilename, SQLiteOpenFlagsEnum flags, Int32 maxPoolSize, Boolean usePool) [0x00000] in <filename unknown>:0 at System.Data.SQLite.SQLiteConnection.Open () [0x00000] in <filename unknown>:0 at (wrapper remoting-invoke-with-check) System.Data.SQLite.SQLiteConnection:Open () at GameManager.Awake () [0x00000] in <filename unknown>:0

    Does anyone have any ideas about this? It is driving me nuts!
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,596
    you need to provide the unmanaged sqllite.dll too, most database layers don't work without the unmanaged (native code) dll present, they are not "pure .net code"
     
  3. kaine106

    kaine106

    Joined:
    Oct 15, 2010
    Posts:
    5
    Thanks for the reply.

    Where do I get that from and where do I put it?
     
  4. kaine106

    kaine106

    Joined:
    Oct 15, 2010
    Posts:
    5
    Am I the only one that has ever had this problem?
     
  5. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,596
    You can use google to find out where you find the required files to interact with sqllite on mono
     
  6. kaine106

    kaine106

    Joined:
    Oct 15, 2010
    Posts:
    5
    If anyone else has this problem, copying the System.Data.SQLite.dll file in to the same folder as the built executable file worked for me. I don't understand why it has to be there when it is in the managed files folder.
     
  7. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,596
    because unity does not copy non-standard frameworks over unhappily. a postprocess build player script can do this.
     
  8. rambramdt

    rambramdt

    Joined:
    Jul 15, 2011
    Posts:
    14
    Sounds like I've found the people who know this stuff well. Thanks for sharing!

    Will this work on Android? Can either of you show me how to copy the files using the postprocess build player script on a Macbook Pro?

    I am developing for Android and I am following the example given in Javascript from http://www.unifycommunity.com/wiki/index.php?title=SQLite . After unzipping my apk package, I can see a Mono.Data.Sqlite.dll file in the Managed/ folder.

    However, I get the following error from the ddms log when I attempted to create a sqlite database on my Droid:

    07-15 13:27:33.550: INFO/Unity(31157): DllNotFoundException: sqlite3
    07-15 13:27:33.550: INFO/Unity(31157): at (wrapper managed-to-native) Mono.Data.Sqlite.UnsafeNativeMethods:sqlite3_open_v2 (byte[],intptr,int,intptr)
    07-15 13:27:33.550: INFO/Unity(31157): at Mono.Data.Sqlite.SQLite3.Open (System.String strFilename, SQLiteOpenFlagsEnum flags, Int32 maxPoolSize, Boolean usePool) [0x00000] in <filename unknown>:0
    07-15 13:27:33.550: INFO/Unity(31157): at Mono.Data.Sqlite.SqliteConnection.Open () [0x00000] in <filename unknown>:0

    Also, why would it say <filename unknown>?
     
  9. Morothar

    Morothar

    Joined:
    Dec 3, 2009
    Posts:
    18
    rambrandt: It's looking for the sqlite3.dll
    On Windows you would put the sqlite3.dll into the project's plugins folder for it to work correctly. Can't say anything about mac builds, but I'm on it.
    I'm also working on using sqlite on android as well as iOS. I'll keep you updated!
     
  10. rambramdt

    rambramdt

    Joined:
    Jul 15, 2011
    Posts:
    14
    Thanks, Morothar! This DLL business confused me quite a bit. I am from before .NET, so I didn't realize that Mono uses DLL as well. Can I use the windows DLL from sqlite.org? Or should I get it from somewhere else? I tried to include the DLL from sqlite.org in the Plugins/ or Plugins/Android/ folders, but it doesn't get included in the APK package. I suppose I need to copy it into the Managed/ folder using a "postprocess build player script" but I don't know how to do it. The example is in Perl! I switched to Python year's ago, and thought I would never use it again. Do I change the first line to "#!/opt/local/bin/perl" on a Macbook Pro? Where should I save the DLL so that it will get included in the APK and where do I copy it to? Any way, I am glad to meet someone who's working on the same problem, hurrah!
     
  11. Morothar

    Morothar

    Joined:
    Dec 3, 2009
    Posts:
    18
    Update: Sadly, as expected, my Mac Build of my app couldn't access sqlite. Will try again, but since the dll is win32 I already guessed it wouldn't work on mac. We would need a dylib there, no?

    rambrandt: Did you have success to access sqlite with a mac build?


    EDIT: Okay, it didn't work whe I built a mac build from windows, but when I build on mac, it works... I'm surprised. *checking for differences*
     
    Last edited: Jul 16, 2011
  12. rambramdt

    rambramdt

    Joined:
    Jul 15, 2011
    Posts:
    14
    The Mac standalone works without a plugin. I simply used Mono.Data.Sqlite in my Javascript.

    I am still confused about Mono and dll. According to this page: http://www.mono-project.com/DllNotFoundException, Mono uses .dll in its library names to maintain compatibility with Windows but it maps them to .so files in linux. However, I am seeing Mono.Data.Sqlite.dll in the APK package being executed by my Droid. I guess that's what "managed code" means?

    Since I can not get sqlite3.dll included in my APK by placing it in the Plugins folder. I tried to put a libsqlite.so I extracted from my Droid in there. It was included in my APK package, but I still get the DLLNotFoundException. I renamed it libsqlite3.so. It didn't help.

    I guess here is what I have to try next:

    1. find a sqlite3.dll that would work with the existing Mono.Data.Sqlite.dll in the APK and somehow include it in the APK as well.

    2. or, compile sqlite using android NDK and get a libsqlite3.so. I don't look forward to doing that, and I am not even sure that it would work with the existing Mono.Data.Sqlite.dll from Unity.
     
    Last edited: Jul 16, 2011
  13. Morothar

    Morothar

    Joined:
    Dec 3, 2009
    Posts:
    18
    Okay, so far every platform works except for android.
    Windows: remember to put sqlite3.dll into plugins folder
    Mac: Works without any additional work
    iOS: Works without any additional work

    Tomorrow I'll tackle Android.
     
  14. rambramdt

    rambramdt

    Joined:
    Jul 15, 2011
    Posts:
    14
    oh, Wow! That's a wonderful news! Keep it up, Morothar!
     
  15. Morothar

    Morothar

    Joined:
    Dec 3, 2009
    Posts:
    18
    I just wasted 4 hours on this to no avail.
    I have two options left:

    1. Build my own plugin, bridging the functionality between unity and java

    2. use NDK to build libsqlite3.so myself in hope that it kind of mysteriously fixes the problem.

    EDIT: I just filed a bug report for this. With a bit of luck the unity team can help...
     
    Last edited: Jul 18, 2011
  16. rambramdt

    rambramdt

    Joined:
    Jul 15, 2011
    Posts:
    14
    I understand your frustration. I've spent many more hours on this, but it has been a learning experience.

    So, your first option would be a C# wrapper for the existing libsqlite.so, replacing Mono.Data.Sqlite? I found a few examples online, but don't know how to adapt them for unity.

    As to your second option, you would still need a wrapper, don't you? Also, can you use JNI? or is there something for C#?
     
  17. cristoph1

    cristoph1

    Joined:
    Jul 18, 2011
    Posts:
    26
    guys, if you want a strong solution to store data locally take a look here: http://siaqodb.com/?p=482 (full disclosure- I'm involved in project), but we really see Unity3D developers need a solution that just works. Put dll in your scripts folder and use it, that's all!
     
  18. Morothar

    Morothar

    Joined:
    Dec 3, 2009
    Posts:
    18
    That's great! But sadly I can't leave the subject as my project is part of a bigger system and the sqlite db file get's regularly updated (the new one get's downloaded.)

    Because of that I'll keep working on getting sqlite to work on android.
     
  19. rambramdt

    rambramdt

    Joined:
    Jul 15, 2011
    Posts:
    14
    Yeah, sounds very nice. I'll check it out.
     
  20. atrakeur

    atrakeur

    Joined:
    Jun 14, 2011
    Posts:
    134
    sqlite3.dll have to be in a Plugins folder, inside your project's folder, then rebuild your app.

    I've done it a long time ago ant it worked fine...
     
  21. Morothar

    Morothar

    Joined:
    Dec 3, 2009
    Posts:
    18
    Are you talking about sqlite3 on Android?
     
  22. Rustam-Ganeyev

    Rustam-Ganeyev

    Joined:
    Jul 18, 2011
    Posts:
    29
    I tried, but it failed. Did you try on Android?

    Did anybody write to Unity developers about this problem?
     
    Last edited: Jul 20, 2011
  23. rambramdt

    rambramdt

    Joined:
    Jul 15, 2011
    Posts:
    14
    Mono.Data.Sqlite.dll is only a "data provider" for the sqlite engine. Looks like the version included in Unity works well with the sqlite3.dll currently available from sqlite.org (for Windows as a plugin). It also works with Mac and iPhone's native sqlite libraries.

    Android provides native sqlite support in libsqlite.so, which unfortunately is not compatible with the mono sqlite data provider included by Unity. I have contacted the Unity support team, but they just referred me to their sales department for premium support.

    To use a database on unity/android, we have to either get around this compatibility issue ourselves or use an alternative, like SiaqoDB.
     
    Last edited: Jul 23, 2011
  24. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,596
    thats to expect. Its not a unity feature and unity does not modify mono to use platform related stuff.
    The reason it works on iOS is more that iOS = OSX in such things, but Android is unhappily not like anything else at all thanks to SDK - NDK - hell, so on android you can be sure that stuff unity uses itself or that is within UnityEngine works and the rest is up to you (exception: Threading and System.XML work too but stuff like System.Data that requires plugins and alike anyway and won't work on webplayers for example is not supported by UT at all so either it works in mono from desktop or not at all)
     
  25. rambramdt

    rambramdt

    Joined:
    Jul 15, 2011
    Posts:
    14
    So, in the end it is a mono/android issue?
     
  26. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,596
    Yes or a fact that mono just does not support android at all (only mono for android which is not the open source public one)

    thats why you would end on the premium support, you would basically have to hire UT to integrate it / expand the implementation to handle android
     
  27. rambramdt

    rambramdt

    Joined:
    Jul 15, 2011
    Posts:
    14
    I assume the libsqlite.so from android is for java. Is it possible to make a C# wrapper around it?
     
  28. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,596
    Don't know.
    .so normally is native code.

    But there is a good chance google has an inhouse modified version of it cause it existed a while on android and the various limitations and missing min requirements might have forced them to cut some stuff and alike thats backfiring.
     
  29. Morothar

    Morothar

    Joined:
    Dec 3, 2009
    Posts:
    18
    Hi!
    Sorry, so far I had to take care of other things in my app. Will have to fix or at least fake it till friday.

    Dreamora: So, it comes really down to compiling our own sqlite.so and use it via DLLImport? Sounds a bit like hell.
    I guess a plugin bridging over to Java sqlitehandler for all sqlite stuff will be simpler...
     
  30. Rustam-Ganeyev

    Rustam-Ganeyev

    Joined:
    Jul 18, 2011
    Posts:
    29
    Morothar, writing plugin is not as easy as it sounds. Of course, it's ok, if you want just to make "insert", "update" queries, where answer is not too important, but on "select" query it's typical to get SqliteDataReader from Mono and android could bring just value types(strings, ints) and doesn't provide any way to make complex class objects. Now we're writing plugin and going to return result as json.
     
  31. Morothar

    Morothar

    Joined:
    Dec 3, 2009
    Posts:
    18
    I know, I really meant simpler than the other thing, but it's only a comparison. I'm pretty aware of the problems with passing complex data through the bridge. Won't be simple at all. But I don't see an acceptable alterative to writing a plugin here.
     
  32. Rustam-Ganeyev

    Rustam-Ganeyev

    Joined:
    Jul 18, 2011
    Posts:
    29
    You can try siaqodb, but it's just released and is not stable yet(we rejected that because of bugs). is there any alternative db?
     
    Last edited: Jul 25, 2011
  33. Morothar

    Morothar

    Joined:
    Dec 3, 2009
    Posts:
    18
    Sadly, I don't even have a choice concerning the db. It's a multiplatform app and it's part of a bigger system.
     
  34. cristoph1

    cristoph1

    Joined:
    Jul 18, 2011
    Posts:
    26
    @rganeyev the bug you reported on our forum is fixed now: http://forum.siaqodb.com/index.php?topic=329.0, also we fixed some issues on Android, you can download now the latest version.

    We've added also a lot of examples in the new build(see Examples project).

    We admit product is just released, but the recent release is for Unity3D only, we released version for MonoTouch and MonoAndroid earlier this year and also Siaqodb as product has a lot of satisfied customers for different platforms.

    We also want to let Unity3D developers know that we provide support and very important: support is very fast even by email or on our forum, and all possible issues, be sure we'll do the best to fix asap. No product is 100% bug free, but we want to provide to Unity3D developers a supported solid database solution and guarantee that can be used in production games.
     
    Last edited: Jul 26, 2011
  35. rambramdt

    rambramdt

    Joined:
    Jul 15, 2011
    Posts:
    14
    "We also want to let Unity3D developers know that we provide support and very important: support is very fast even by email or on our forum, and all possible issues, be sure we'll do the best to fix asap."

    I can testify to that. I have been in touch with the Siaqodb team and they are highly responsive.

    "Sadly, I don't even have a choice concerning the db. It's a multiplatform app and it's part of a bigger system."

    I was told Siaqodb has a beta version SyngProvider which syncs with major databases such as MySQL, etc. Maybe it will help when it is made available for Android.
     
  36. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,194
    Dumb question, but since sqlite is just to store in a single instance that is only accessable on the device, why not simply use player prefs?
     
  37. Rustam-Ganeyev

    Rustam-Ganeyev

    Joined:
    Jul 18, 2011
    Posts:
    29
    It's ok if we need to store a few things. But I need to store hundreds of objects containing a lot of fields. And I can't use siaqodb because of some reasons.

    The problem with android sqlite was solved in the following way: we wrote a plugin that sends sql queries to jni, and receive responce in json format. That json is decoded into Dictionary<List<string>, string>>. That's it!
     
  38. Rustam-Ganeyev

    Rustam-Ganeyev

    Joined:
    Jul 18, 2011
    Posts:
    29
  39. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,222
    You need to copy the sqlite3.dll folder into the same folder as your .exe file of your game build.

    This is for PC though, can't help you with the other platforms.