How can I use SQL scripts in a database project with the System.Data.SQLite data provider?

I have a project where I am trying to use SQLite through System.Data.SQLite . In my attempts to keep the database under version control, I went ahead and created a database project in my VS2008. Sounds okay, right?

I created my first create script table and tried to run it by right clicking-> Run on script and I get this error message:

This operation is not supported by the provider or data source you are using.

Does anyone know if there is an automatic way to use scripts that are part of a database project for SQLite databases referenced by databases using the provider provided by the System.Data.SQLite installation?

I've tried all the options I can think of trying to run the script using the default Run or Run as default commands. Here the script in it is the most verbose and probably the wrong form:

USE Characters
GO

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'U' AND name = 'Skills')
  BEGIN
    DROP Table Skills
  END
GO

CREATE TABLE Skills
(
   SkillID INTEGER PRIMARY KEY AUTOINCREMENT,
   SkillName TEXT,
   Description TEXT
)
GO

      

Please note that this is my first attempt at using a database, and also the first time I have ever touched SQLite. In my attempts to make it work, I stripped everything and everything except the CREATE TABLE command.

UPDATE: Ok, as Robert Harvey points out below, this looks like a SQL Server Stored Procedure. I went into Server Explorer and used my connection (from the Database project) to do what he suggested to create the table. I can generate SQL to create the table and it turns out like this:

CREATE TABLE [Skills] (
    [SkillID] integer PRIMARY KEY NOT NULL,
    [SkillName] text NOT NULL,
    [Description] text NOT NULL
);

      

I can easily copy this and add it to the project (or add it to another project that handles the rest of my data access), but is there anyway to automate this on build? I suppose since SQLite is single file in this case, I could also keep an embedded versioned database.

Thoughts? Best practices for this instance?

UPDATE: I think since I am planning on using Fluent NHibernate I can just use the auto-resilient model to keep my database sniffed and control the source code efficiently. Thoughts? Traps? I think I'll have to separately add the original inserts to the original block, but it should work.

0


a source to share


2 answers


I built my database using a SQLite SQL script and then pipe it to the sqlite3.exe console program like this.

c: \ sqlite3.exe mydatabase.db <FileContainingSQLiteSQLCommands



John

+1


a source


Ok, your script looks like a SQL Server stored procedure. SQLite most likely doesn't support this because

  • It doesn't support stored procedures and
  • He doesn't understand SQL Server T-SQL

SQL is actually a pseudo standard. It differs between vendors and sometimes between different versions of a product within the same vendor.

However, I see no reason why you cannot run any (SQLite-compliant) SQL statement on a SQLite database by opening connection and command objects, just like with SQL Server.



Since you're new to databases and SQLite, here's how you should get started. I am assuming you already have SQLite installed

  • Create a new Windows application in Visual Studio 2008. The database application will be useless for you.

  • Open Server Explorer by pulling down the View menu and choosing Server Explorer.

  • Create a new connection by right clicking on the data connections node in the server explorer and clicking Add New Connection ...

  • Click the "Change" button

  • Select a SQLite provider

  • Give your database a filename.

  • Click OK.

A new data connection should appear in the server explorer. You can create your first table by right clicking on the tables node and choosing Add New Table.

0


a source







All Articles