System.Data.SQLite Table not found
I can insert/update/delete fine from tables like product and such but this code fails with saying that the table AppAttribute does not exist. As I said, other tables are working fine...
ExecuteNonQuery(BuildCommand(string.Format("DELETE FROM AppAttribute WHERE ProjectId={0};", ID)));
ExecuteNonQuery(BuildCommand(string.Format("DELETE FROM CSVField WHERE ProjectId={0};", ID)));
ExecuteNonQuery(BuildCommand(string.Format("DELETE FROM ExtraAttribute WHERE ProjectId={0};", ID)));
I have the following schema in my database:
BEGIN TRANSACTION;
CREATE TABLE AppAttribute (ProjectID NUMERIC, Name TEXT, Value TEXT);
CREATE TABLE AppData (PKey INTEGER PRIMARY KEY, KeyNo TEXT, FullName TEXT, EmailAddress TEXT, PostalCode TEXT, MagePassword TEXT, MageUserName TEXT, DomainName TEXT, ProductSheetTemplate TEXT);
INSERT INTO "AppData" VALUES(1,'','','','','MageCatPrinter','MageCatPrinter','http://www.ecosmartlight.com','Z:\dennisdecoene On My Mac\Documents\ML Solutions\EcoSmartLight\Productfiches\Voorbeeld van site\Sjabloon.html');
CREATE TABLE CSVField (ProjectID NUMERIC, Name TEXT, ExampleData TEXT);
CREATE TABLE ExtraAttribute (ProjectID NUMERIC, Name TEXT, PrintInTable NUMERIC);
CREATE TABLE Product (SKU TEXT, ProjectId NUMERIC, N开发者_开发百科ame TEXT, AttributeSet INTEGER);
CREATE TABLE ProductAttribute (SKU TEXT, ProjectId NUMERIC, Key TEXT, Value TEXT);
CREATE TABLE Project (PKey INTEGER PRIMARY KEY, Name TEXT);
CREATE TABLE Template (Id INTEGER PRIMARY KEY, ProjectId NUMERIC, Type NUMERIC, Name TEXT, TemplateText TEXT);
COMMIT;
I'm also sure this is the schema the app is working with because it is my app that generated the dump.
It was a very strange problem. My connection string was this:
string _connectionString = @"Data Source=./Foo.db";
BUT!!! (Here it comes)
On the form I have an OpenFileDialog control. Now for some sick evil twisted reason, after opening the dialog and selecting a file, the current path is changed. If you then make a new connection, the "." in the connection string points to somewhere else.
So I changed my connection string to:
string _connectionString = @"Data Source=" + Application.StartupPath + "\\Foo.db";
The sky cleared up immediately...
PS I wasted half a day on this :(
Maybe you need to define a PK for table AppAttribute?
精彩评论