in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

SpatiaLite error

Last post 03-25-2009 10:15 AM by axel. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 03-25-2009 10:15 AM

    • axel
    • Not Ranked
    • Joined on 03-25-2009
    • Posts 1

    SpatiaLite error

     Hi all!

    I'm trying to access my SpatiaLite db using System.Data.SQLite. 

    I first tryed to access without using the SpatiaLite extension to access non-spatial data and it worked correctly. Then i put SpatiaLite's dll into the Release folder, added the following 2 lines:

    cmd.CommandText = "SELECT load_extension('libspatialite-2.dll');";
    cmd.ExecuteNonQuery();

     

    I recompiled, executed without debug and it appears the following error message:

     
    Eccezione non gestita: System.Data.SQLite.SQLiteException: SQLite error
    not authorized
       in System.Data.SQLite.SQLite3.Reset(SQLiteStatement stmt)
       in System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)
       in System.Data.SQLite.SQLiteDataReader.NextResult()
       in System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavi
    or behave)
       in System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
       in System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()
       in test.Program.Main(String[ args) in D:\Visual Studio 2008\Projects\090325\
    090325\Program.cs:riga 27

     

    Can anyone help me? I paste the complete source of my simple program.Thanks very much,

    Axel

     

     

     using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.SQLite;
    using System.Data;
    using System.Data.Common;

    namespace test
    {
        class Program
        {

            static void Main(string[ args)
            {

     
                // Create a connection and a command
                using (DbConnection cnn = new SQLiteConnection("Data Source=test.sqlite"))
                using (DbCommand cmd = cnn.CreateCommand())
                {

                    // Open the connection. If the database doesn't exist,
                    // it will be created automatically
                    cnn.Open();
                    cmd.CommandText = "SELECT load_extension('libspatialite-2.dll');";
                    cmd.ExecuteNonQuery();
                    cmd.CommandText = "SELECT * FROM mytable";
                    using (DbDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Console.WriteLine(String.Format("ID = {0}, value = {1}", reader[0], reader[1]));
                        }

                    }

                }

                Console.ReadKey();

            }

        }

    }

     

     

    Filed under: , ,
Page 1 of 1 (1 items)
Powered by Community Server (Commercial Edition), by Telligent Systems