in

System.Data.SQLite

An open-source, enhanced version of the SQLite database engine for Windows

Using the .NET Provider on WindowsCE

Last post 02-27-2008 10:30 PM by Dave. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 02-20-2008 3:39 PM

    Using the .NET Provider on WindowsCE

    I have run into some issues getting this to work on WindowsCE and it is probably something simple that I am missing.  I'm just trying to use the SQLite database on WindowsCE using C#.

    Here is the code: 

    abstract class DataTransaction
    {
      
    private string _connStr;
      
    private SQLiteConnection _conn;
      
    protected SQLiteCommand _cmd;

      
    public DataTransaction()
       {
         
    string databaseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + @"\Data";
          
    string databaseFilePath = databaseDir + @"\OPDB.db3";

          if (!Directory.Exists(databaseDir))
          {
             
    Directory.CreateDirectory(databaseDir);
          }

          _connStr = @"Data Source=" + databaseFilePath + "; Password=xxxx";
          _conn =
    new SQLiteConnection(_connStr);
          _cmd =
    new SQLiteCommand();
         
    _cmd.Connection = _conn;
          _cmd.CommandType =
    CommandType.Text;
       }
    }

    class TxGetAllCourseMapIds : DataTransaction
    {
      
    public Collection<string> ExecuteTransaction()
       {
         
    Collection<string> courseMapIds = new Collection<string>();
         
    try
         
    {
             _cmd.CommandText =
    "SELECT MapId FROM Course";
             _cmd.Connection.Open();  [!!!! Here is where the error is occuring...!!!!]
            
    SQLiteDataReader dr = _cmd.ExecuteReader();

             if (dr.HasRows)
             {
               
    while (dr.Read())
                {
                   courseMapIds.Add(dr[
    "Name"].ToString());
                }
             }
          }
          catch (Exception)
          {
            
    throw;
          }
          finally
          {
            
    if (_cmd.Connection.State == System.Data.ConnectionState.Open)
             {
                _cmd.Connection.Close();
             }
          }
         
    return courseMapIds;
       }
    }

     

     

    Everything compiles fine.  When I test it and it is deployed to the windows CE emulator, I get the:

    'Can't find an Entry Point 'sqlite3_open_interop' in a PInvoke DLL 'System.Data.SQLite.DLL'.' error.

    First, I tried using the precompiled assembly in the 'bin\CompactFramework' directory of the zip file containing the binaries (SQLite-1.0.48.0-binaries).

    Then I tried this:

    1. Downloaded the source files
    2. Opened the solution
    3. Changed the platform to the 'Compact Framework' option.
    4. Right clicked the 'System.Data.SQLite - Compact' project then selected 'Change Target Platform' and changed it to 'Windows CE'.
    5. I did a 'Rebuild All' on the solution.

    the result is still the same.

     Any ideas?

    Filed under: ,
  • 02-20-2008 4:49 PM In reply to

    • Nate
    • Top 10 Contributor
    • Joined on 08-28-2005
    • Fort Collins, CO
    • Posts 64

    Re: Using the .NET Provider on WindowsCE

    Build the solution and use the System.Data.Sqlite.dll located in SQLite-1.0.48.0-source\bin\CompactFramework NOT  SQLite-1.0.48.0-source\System.Data.SQLite\bin\CompactFramework.

    SQLite-1.0.48.0-source\bin\CompactFramework has the merged module. The merged module will be over 500k.

    Does that help?

  • 02-26-2008 4:37 PM In reply to

    • Dave
    • Top 500 Contributor
    • Joined on 02-26-2008
    • Posts 4

    Re: Using the .NET Provider on WindowsCE

    Hi,

    I am also getting the same PInvoke errors on a HP device running WindowsCE 5.0, using build 1.0.48.0

    As with the OP, I used the precompiled dll from installed by SQLite-1.0.48.0-setup.exe at C:\Program Files\SQLite.NET\bin\CompacFramework\System.Data.SQLite.DLL  and got the same error. (The size of this file is 497Kb).

    So I built the source code as above, and have used the dll you mentioned from SQLite-1.0.48.0-source\bin\CompactFramework, and still got the same error (file size is also 497Kb).

    In my application, the stack trace is as follows:

    APPLICATION ERROR AT 26/02/2008 11:21:28 PM: Unhandled Exception:
    Can't find PInvoke DLL 'System.Data.SQLite.DLL'.

    System.MissingMethodException

    Stack Trace
    at System.Data.SQLite.SQLite3.Open()
    at System.Data.SQLite.SQLiteConnection.Open()

     

    Also, I tried running testce.exe on my HP CE 5.0 device, and get the same error:

    Error

    TESTCE.EXE

    MissingMethodException

    Can't find PInvoke DLL 'System.Data.SQLite.DLL'.

    at System.Data.SQLite.SQLite3.Open()
    at System.Data.SQLite.SQLiteConnection.Open()
    at test.Program.Main()

     

    Any ideas?

  • 02-27-2008 5:03 AM In reply to

    • Dave
    • Top 500 Contributor
    • Joined on 02-26-2008
    • Posts 4

    Re: Using the .NET Provider on WindowsCE

     Hi,

    An update...I can get the "Can't find PInvoke DLL" error with testce.exe on the Windows CE 5.0 emulator, as well as the Windows CE 5.0 device (HP thin client..x86), but not on the Pocket PC 2003 emulator. Any reason why?

    I noticed in the build that if the solution is configured target the Compact Framework, the target platform for thje System Interop project is set to "Pocket PC 2003 (arm)". Would this have anything to do with it? Should the platform be set to something else for a x86 CE Device?

     

    Dave

     Edit: Oops, meant Pocket PC, not "Power PC"

  • 02-27-2008 9:29 AM In reply to

    • Nate
    • Top 10 Contributor
    • Joined on 08-28-2005
    • Fort Collins, CO
    • Posts 64

    Re: Using the .NET Provider on WindowsCE

    It sounds like what you need is the SQLite.Interop.dll compiled for x86 and the Compact Framework version of System.Data.SQLite.dll. None of the build configurations I see support such a combination.

    I do not know how you merge those combinations together (look at existing configs to figure that out), but you can change System.Data.SQLite.dll to use SQLite.Interop.DLL instead of itself by changing line 200 of UnsafeNativeMethods.cs


    #if !PLATFORM_COMPACTFRAMEWORK
      [SuppressUnmanagedCodeSecurity]
    #endif
      internal sealed class UnsafeNativeMethods
      {
    #if !USE_INTEROP_DLL
        private const string SQLITE_DLL = "System.Data.SQLite.DLL";
    #else
        private const string SQLITE_DLL = "SQLite.Interop.DLL";
    #endif

    The steps would be roughly

    • Change lines above to always use SQLite.Interop.DLL
    • Build targeting x86
    • Build targeting compact framework
    • Test by using the UNMERGED System.data.sqlite.dll (x86) and SQLite.Interop.DLL (compact) together.
    Make sense?
  • 02-27-2008 10:30 PM In reply to

    • Dave
    • Top 500 Contributor
    • Joined on 02-26-2008
    • Posts 4

    Re: Using the .NET Provider on WindowsCE

    Hi,

    Thanks for the tip. I am having trouble getting the System.Interop.dll compiled for x86 AND Windows CE.

    It seems that if I change the System.Interop C++ project to use the x86 Platform, the build then targets normal Windows and not Windows CE and fails. (The included Windows header files/libraries etc are no longer 'CE Aware')

    I added preprocessor definitions for _WIN32_WCE, UNDER_CE, WINCE etc but no difference.

     

    I then thought I could modiy the  Pocket PC platform configuration to target x86, but alas under Configuration Properites ->C/C++ ->Advanced -> Compile for Architecture I can only select ARM variants.

     

    So I am kind of stuck. Anyone managed to get this running on Windows CE 5.0 and an x86 device?

     

    Dave

     

Page 1 of 1 (6 items)
Powered by Community Server (Commercial Edition), by Telligent Systems