SQLite / Mono trouble ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rick van Lieshout

    #1

    SQLite / Mono trouble ?

    Hi all,

    I'm trying to use the sql engine SQLite within my Visual C# project. I
    downloaded the mono version of the .NET framework so I could use
    Mono.Data.Sqlit eClient.dll , however I can't seem to be able to use the
    IDataReader object. Any suggestions ?

    Complete work directory:


    This is my code:
    -----------------------------
    using System;
    using System.Data;
    using Mono.Data.Sqlit eClient;

    namespace SqliteTest
    {
    /// <summary>
    /// Summary description for SqliteTestApp.
    /// </summary>
    class SqliteTestApp
    {
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main(string[] args)
    {
    string connectionStrin g = "URI=file:Sqlit eTest.db";
    IDbConnection dbcon;
    dbcon = new SqliteConnectio n(connectionStr ing);
    dbcon.Open();
    IDbCommand dbcmd;
    dbcmd = dbcon.CreateCom mand();
    dbcmd.Connectio n = dbcon;
    string sql = "CREATE TABLE test (nummer int)";
    dbcmd.CommandTe xt = sql;
    dbcmd.ExecuteNo nQuery();
    sql = "INSERT INTO test VALUES (12)";
    dbcmd.CommandTe xt = sql;
    dbcmd.ExecuteNo nQuery();
    sql = "SELECT nummer FROM test";
    dbcmd.CommandTe xt = sql;
    IDataReader reader;
    reader = dbcmd.ExecuteRe ader();
    while (reader.Read())
    {
    int nummer = reader.GetInt32 (0);
    Console.WriteLi ne(nummer);
    }
    reader.Close();
    reader = null;
    dbcmd.Dispose() ;
    dbcmd = null;
    dbcon.Close();
    dbcon = null;
    }
    }
    }

    Thanks in advance,

    Rick van Lieshout


  • Mark Fitzpatrick

    #2
    Re: SQLite / Mono trouble ?

    Don't create the reader on one line then set it the next. Instead you create
    it as a returned result on the same line:

    don't do:
    IDataReader reader;
    reader = dbcmd.ExecuteRe ader();

    Do this instead:
    IDataReader reader = dbcmd.ExecuteRe ader();


    Hope this helps,
    Mark Fitzpatrick
    Microsoft MVP - FrontPage


    "Rick van Lieshout" <r.van.lieshout @promo-it.nl> wrote in message
    news:4YwSa.3482 7$O9.1357360@ca stor.casema.net ...[color=blue]
    > Hi all,
    >
    > I'm trying to use the sql engine SQLite within my Visual C# project. I
    > downloaded the mono version of the .NET framework so I could use
    > Mono.Data.Sqlit eClient.dll , however I can't seem to be able to use the
    > IDataReader object. Any suggestions ?
    >
    > Complete work directory:
    > http://home.wanadoo.nl/hgvl/Copy%20of%20SqliteTest.zip
    >
    > This is my code:
    > -----------------------------
    > using System;
    > using System.Data;
    > using Mono.Data.Sqlit eClient;
    >
    > namespace SqliteTest
    > {
    > /// <summary>
    > /// Summary description for SqliteTestApp.
    > /// </summary>
    > class SqliteTestApp
    > {
    > /// <summary>
    > /// The main entry point for the application.
    > /// </summary>
    > [STAThread]
    > static void Main(string[] args)
    > {
    > string connectionStrin g = "URI=file:Sqlit eTest.db";
    > IDbConnection dbcon;
    > dbcon = new SqliteConnectio n(connectionStr ing);
    > dbcon.Open();
    > IDbCommand dbcmd;
    > dbcmd = dbcon.CreateCom mand();
    > dbcmd.Connectio n = dbcon;
    > string sql = "CREATE TABLE test (nummer int)";
    > dbcmd.CommandTe xt = sql;
    > dbcmd.ExecuteNo nQuery();
    > sql = "INSERT INTO test VALUES (12)";
    > dbcmd.CommandTe xt = sql;
    > dbcmd.ExecuteNo nQuery();
    > sql = "SELECT nummer FROM test";
    > dbcmd.CommandTe xt = sql;
    > IDataReader reader;
    > reader = dbcmd.ExecuteRe ader();
    > while (reader.Read())
    > {
    > int nummer = reader.GetInt32 (0);
    > Console.WriteLi ne(nummer);
    > }
    > reader.Close();
    > reader = null;
    > dbcmd.Dispose() ;
    > dbcmd = null;
    > dbcon.Close();
    > dbcon = null;
    > }
    > }
    > }
    >
    > Thanks in advance,
    >
    > Rick van Lieshout
    >
    >[/color]


    Comment

    • Rick van Lieshout

      #3
      Re: SQLite / Mono trouble ?

      Sorry, this didn't do the trick.. I guess it is the callback function.. I'll
      try a older DLL as soon as i can access the sqlite.org site again.



      "Mark Fitzpatrick" <markfitz@fitzm e.com> wrote in message
      news:OBWkHxtTDH A.3192@tk2msftn gp13.phx.gbl...[color=blue]
      > Don't create the reader on one line then set it the next. Instead you[/color]
      create[color=blue]
      > it as a returned result on the same line:
      >
      > don't do:
      > IDataReader reader;
      > reader = dbcmd.ExecuteRe ader();
      >
      > Do this instead:
      > IDataReader reader = dbcmd.ExecuteRe ader();
      >
      >
      > Hope this helps,
      > Mark Fitzpatrick
      > Microsoft MVP - FrontPage
      >
      >
      > "Rick van Lieshout" <r.van.lieshout @promo-it.nl> wrote in message
      > news:4YwSa.3482 7$O9.1357360@ca stor.casema.net ...[color=green]
      > > Hi all,
      > >
      > > I'm trying to use the sql engine SQLite within my Visual C# project. I
      > > downloaded the mono version of the .NET framework so I could use
      > > Mono.Data.Sqlit eClient.dll , however I can't seem to be able to use the
      > > IDataReader object. Any suggestions ?
      > >
      > > Complete work directory:
      > > http://home.wanadoo.nl/hgvl/Copy%20of%20SqliteTest.zip
      > >
      > > This is my code:
      > > -----------------------------
      > > using System;
      > > using System.Data;
      > > using Mono.Data.Sqlit eClient;
      > >
      > > namespace SqliteTest
      > > {
      > > /// <summary>
      > > /// Summary description for SqliteTestApp.
      > > /// </summary>
      > > class SqliteTestApp
      > > {
      > > /// <summary>
      > > /// The main entry point for the application.
      > > /// </summary>
      > > [STAThread]
      > > static void Main(string[] args)
      > > {
      > > string connectionStrin g = "URI=file:Sqlit eTest.db";
      > > IDbConnection dbcon;
      > > dbcon = new SqliteConnectio n(connectionStr ing);
      > > dbcon.Open();
      > > IDbCommand dbcmd;
      > > dbcmd = dbcon.CreateCom mand();
      > > dbcmd.Connectio n = dbcon;
      > > string sql = "CREATE TABLE test (nummer int)";
      > > dbcmd.CommandTe xt = sql;
      > > dbcmd.ExecuteNo nQuery();
      > > sql = "INSERT INTO test VALUES (12)";
      > > dbcmd.CommandTe xt = sql;
      > > dbcmd.ExecuteNo nQuery();
      > > sql = "SELECT nummer FROM test";
      > > dbcmd.CommandTe xt = sql;
      > > IDataReader reader;
      > > reader = dbcmd.ExecuteRe ader();
      > > while (reader.Read())
      > > {
      > > int nummer = reader.GetInt32 (0);
      > > Console.WriteLi ne(nummer);
      > > }
      > > reader.Close();
      > > reader = null;
      > > dbcmd.Dispose() ;
      > > dbcmd = null;
      > > dbcon.Close();
      > > dbcon = null;
      > > }
      > > }
      > > }
      > >
      > > Thanks in advance,
      > >
      > > Rick van Lieshout
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Frans Bouma

        #4
        Re: SQLite / Mono trouble ?

        "Mark Fitzpatrick" <markfitz@fitzm e.com> wrote in
        news:OBWkHxtTDH A.3192@tk2msftn gp13.phx.gbl:
        [color=blue]
        > Don't create the reader on one line then set it the next. Instead you
        > create it as a returned result on the same line:
        >
        > don't do:
        > IDataReader reader;
        > reader = dbcmd.ExecuteRe ader();
        >
        > Do this instead:
        > IDataReader reader = dbcmd.ExecuteRe ader();[/color]

        and why would that help? The first of his 2 lines declares an
        identifier in the local stackframe. The second line puts the reference
        address of the reader object as the value of the identifier. Same as your
        line.

        To Rick: as people on GoT already suggested, it might be a bug in
        SQLite.

        FB

        --
        Solutions Design : http://www.sd.nl
        My open source .NET Software : http://www.sd.nl/software
        My .NET Blog : http://weblogs.asp.net/FBouma
        -------------------------------------------------------------------------

        Comment

        Working...