tags:

views:

4601

answers:

4

Hello people i've been struggling to use sqlite in my C#2.0 application and i, ve finally decided to get rid of assumptions and ask really basic questions.when i created a database say iagency with table users, from external tools like firefox plugging and another sqladmin tool i can't query it from sqlicommand inside vs2005.it displays "System.Data.SQLite.SQLiteException:Sqlite Error no such table users " please be assured that i've made reference to system.data.sqlite installed with SQLite-1.0.61.0-setup

when i do the opposite like create a database and a table from vs server explorer and vs database gui tools it can't be queried netheir but can be seen by other tools. but tables created through query from vs using stringbuilder eg create table bla bla.it can be display in a datagrid but none of the tools can see and display that table

WHAT DO I NEED EXACTLY TO MAKE SQLITE WORK IN MY APPLICATION?

i've tried to add sqlite3.dll of sqlitedll-3_6_14.zip downloaded from sqlite site under section precompiled binaries for windows as reference to my application but it fails "make sure it's accessible an it's a valid assembly or com component.

+2  A: 

Try opening up the database in the command line SQLite tool (from SQLite.org), and check the schema.

You can check the schema in this way:

.schema

This will dump out all the SQL necessary to create the tables in the database. Make sure the table is there, with the name you assume it should have.

You do not need the .dll file from SQLite.org, all you need is the assemblies from System.Data.SQLite.

Lasse V. Karlsen
thanks for the reply.Here is another stupid question.Where should i extract the exe app to?cos i've tried selected the database by this command .database to find the databases but nothing.after i copy the exe inside the my C# application folder and tried to select the database with this command "sqlite3 iagency".still nothing to show
black sensei
i solve the problem stated up here.see the comment i made for R Ubben.ishould use sqlite3 iagency.db i forgot the extension.i'm not getting very well what you meant by "you can check the schema in this way" from the cmd.exe i typed sqlite3 iagency.db to select and after i typed .schema or it should be followed by the table name like .schema users.thanks man
black sensei
A: 

You might try adding the location of the assembly and the db to the Path environment variable. The SQLite assembly contains both .Net and native code merged together, so you do not need the C dll. (the mergebin tool they include to do this is pretty interesting)

R Ubben
i did add the sqlite.exe path to the environment variable.did some test on my drive d by using the windows cmd.exe and i can query that table fine.now i change the directory to where my project and the database created earlier is. sqlite3 iagency and .schema commands doesn't not produce any output. i've tried .scheman ?users? but nothing.Am i missing anything?
black sensei
+2  A: 

I downloaded this SQLite-1.0.61.0-setup.exe Ran the installation then I wrote this to access the firefox favorites sqlite db.

using System.Data.SQLite;  // Dont forget to add this to your project references
                           // If the installation worked you should find it under
                           // the .Net tab of the "Add Reference"-dialog

namespace sqlite_test
{
    class Program
    {
        static void Main(string[] args)
        {
            var path_to_db = @"C:\places.sqlite"; // copied here to avoid long path
            SQLiteConnection sqlite_connection = new SQLiteConnection("Data Source=" + path_to_db + ";Version=3;New=True;Compress=True;");

            SQLiteCommand sqlite_command = sqlite_connection.CreateCommand();

            sqlite_connection.Open();

            sqlite_command.CommandText = "select * from moz_places";

            SQLiteDataReader sqlite_datareader = sqlite_command.ExecuteReader();

            while (sqlite_datareader.Read())
            {
                // Prints out the url field from the table:
                System.Console.WriteLine(sqlite_datareader["url"]);
            }
        }
    }
}
Nifle
+2  A: 

For me - this link helped a lot at start.

Was harder to get subsonic work, to make database accessible through web application -
but that's another story.

Arnis L.