in

System.Data.SQLite

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

Creating a new SQLite database file

Last post 11-09-2008 11:49 AM by rhencke. 17 replies.
Page 1 of 2 (18 items) 1 2 Next >
Sort Posts: Previous Next
  • 11-21-2005 8:30 AM

    Creating a new SQLite database file

    Locked Reply Contact

    SQLite database files are really easy to create.  The rule is, if the file doesn't exist, SQLite will create it.  However, if you want to explicitly create the file beforehand, here's how:

    using System;

    using System.Data;

    using System.Data.Common;

    using System.Data.SQLite;

     

    namespace test

    {

    class Program

    {

    static void Main(string[] args)

    {

    SQLiteConnection.CreateFile("c:\\mydatabasefile.db3");

    }

    }

    }

    The filename can be anything you like and the extension is irrelevent.

     

  • 03-09-2006 12:00 PM In reply to

    Re: Creating a new SQLite database file

    When creating a new file using the CreateFile() method, the file can't be read by SQLite3.exe command line tool.
    Working with existing databases on the other hand, works out fine : )

    The error message is:
    "Incomplete SQL: SQLite format 3......"

    Am I missing any parameters?
  • 03-09-2006 12:17 PM In reply to

    Re: Creating a new SQLite database file

    What command-line parameters are you passing to sqlite3.exe and what commands are you calling once it starts?

    Robert

     

  • 03-09-2006 12:25 PM In reply to

    Re: Creating a new SQLite database file

    Starting SQLite3.exe and typing ".read mydb.db" produces that message
  • 03-09-2006 2:19 PM In reply to

    Re: Creating a new SQLite database file

    CreateFile() just creates a blank empty file ... there's nothing in the file for the command-line utility to query on.  Is there any reason you need to run the command-line utility on an empty database?  The command-line utility can create databases on its own as well...

    Robert

     

  • 03-10-2006 2:02 AM In reply to

    Re: Creating a new SQLite database file

    Thnx for a quick response : )
    I was just checking for compatibility. Created a db file using the data provider and it could not open with SQLite3.exe.
    Tried the other way and it worked. I'm gonna stick with the sqlite data provider anyway for my blog project.
    SQLite seems to be perfect for packaging a lightweight database with web projects and ADO.NET SQLite is a great way of working with it : )
  • 03-10-2006 7:48 AM In reply to

    Re: Creating a new SQLite database file

    I'll see if there's a way I can force sqlite to write the master page when creating a file.

    Robert

     

  • 05-16-2006 4:29 AM In reply to

    Re: Creating a new SQLite database file

    is there any way to delete the data file programmatically?

    instead of .CreateFile to use .DeleteFile ?

    grtz

  • 05-16-2006 6:22 AM In reply to

    Re: Creating a new SQLite database file

    ... it's a file, so just use System.IO.File.Delete() to delete it.

    Robert

     

  • 08-01-2006 7:49 AM In reply to

    Re: Creating a new SQLite database file

    So what is the difference between using System.IO.File.Create() to create the file?
  • 08-01-2006 9:18 AM In reply to

    Re: Creating a new SQLite database file

    No difference.  Some people just couldn't wrap their brains around the idea that the SQLite engine would create the file for you automatically if it didn't exist on the first call to SQLiteConnection.Open()

    Robert

     

  • 08-25-2006 12:58 PM In reply to

    • Hei
    • Top 500 Contributor
    • Joined on 08-25-2006
    • Posts 2

    Re: Creating a new SQLite database file

    I have tried the code above on my Pocket PC (Mobile 2003). If I use Sharpdevelop to compile it on the desktop and then move the files to the Pocket PC, it works just fine.
    However, I have PocketC# installed on my Pokcet PC and if I compile it on the Pocket PC, I get the following error message:
    called object is not a method or delegate.

    I am new to this - any ideas?
  • 08-25-2006 1:47 PM In reply to

    Re: Creating a new SQLite database file

    I have never used nor even heard of a Pocket C# compiler ... why would you want to compile on the device?

     

  • 08-25-2006 1:53 PM In reply to

    Re: Creating a new SQLite database file

    Ok I looked up Pocket C#.  It doesn't support .NET CF 2.0, which this SQLite data provider requires.

    Robert

     

  • 08-25-2006 2:08 PM In reply to

    • Hei
    • Top 500 Contributor
    • Joined on 08-25-2006
    • Posts 2

    Re: Creating a new SQLite database file

    Sorry, I didn't think about that. Thank you!

    I have the source code for PocketC#. So I guess I could try and compile it for use with CF 2.0??

    The reason I prefer to compile on the device, is that the family computer might be used by others and I like sitting outside or in a comfy chair (the laptop has a bad power connection - repaired once, so I prefer to leave it in one place).

Page 1 of 2 (18 items) 1 2 Next >
Powered by Community Server (Commercial Edition), by Telligent Systems