sqlite附加数据库问题

时间:2010-11-24 02:52:30

标签: c# nhibernate sqlite

当我尝试访问带有构建模式的有效SQLiteConnection上的附加db文件时,我收到“没有这样的表”错误。

在“主”连接上保存一些测试数据后,我附加该文件,然后尝试将数据从“main”导出到该文件以供以后使用。以下是用于附加文件的代码:

private static void _attachDatabase(SQLiteConnection conn, string dataFile) {
var cmd = new SQLiteCommand(conn)
                  {
                      CommandText = string.Format("ATTACH '{0}' AS {1}", dataFile, ATTACHED_DB)
                  };
_log.Debug(cmd.CommandText);
cmd.ExecuteNonQuery();
}

命令的日志输出是

"...\bin\Debug\testData.db3' AS asdf" where testData.db3 is the file.

当我尝试插入文件时,我在本文末尾收到错误。

有没有从提供的信息中看到问题?顺便说一句,我是否应该能够在调试器中的某处看到附加的db(“asdf”)?

干杯,
Berryl

测试'SQLiteTesting.Helpers.QueryTests.Director_if_Tim_Burton_query_should_return_one_movie'失败:QueryFsts中的TestFixtureSetUp失败

TestFixture失败:System.Data.SQLite.SQLiteException:SQLite错误 没有这样的表:asdf.ActorRole    在System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn,String strSql,SQLiteStatement previous,UInt32 timeoutMS,String& strRemain)    在System.Data.SQLite.SQLiteCommand.BuildNextCommand()    在System.Data.SQLite.SQLiteCommand.GetStatement(Int32索引)    在System.Data.SQLite.SQLiteDataReader.NextResult()    在System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd,CommandBehavior表现)    在System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior行为)    在System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()    在C:\ Users \ Lord&中的SQLiteTesting.Helpers.SQLiteLoader._copyTableData(SQLiteConnection conn,String source,String destination) Master \ Documents \ Projects \ Data \ NHib projects \ Cookbook \ SQLiteTesting \ Helpers \ SQLiteLoader.cs:第68行    在C:\ Users \ Lord&中的SQLiteTesting.Helpers.SQLiteLoader.ExportData(SQLiteConnection conn,String dataFile)中Master \ Documents \ Projects \ Data \ NHib projects \ Cookbook \ SQLiteTesting \ Helpers \ SQLiteLoader.cs:第30行    在C:\ Users \ Lord&中的SQLiteTesting.Helpers.QueryTests.OnFixtureSetUp()中Master \ Documents \ Projects \ Data \ NHib projects \ Cookbook \ SQLiteTesting \ Helpers \ QueryTests.cs:第25行    在C:\ Users \ Lord&中的SQLiteTesting.Helpers.BaseFixture.FixtureSetUp()中Master \ Documents \ Projects \ Data \ NHib projects \ Cookbook \ SQLiteTesting \ Helpers \ BaseFixture.cs:第23行  2010-11-23 18:15:36,835 DEBUG ATTACH'... \ bin \ Debug \ testData.db3'AS asd  2010-11-23 18:18:12,935 DEBUG INSERT INTO asdf.ActorRole SELECT * FROM ActorRole

2 个答案:

答案 0 :(得分:2)

线索是:

SQLite error no such table: asdf.ActorRole at

如果你确实已经定义了表格,那么你已经遭遇了主要的(可能只有!)sqlite陷阱。如果数据库文件没有退出,它将静静地为您创建一个空数据库。

仔细检查文件路径并查找目录中出现的新空sq3文件。

答案 1 :(得分:0)

您需要 AS {1} 声明吗?强制数据库名称似乎让人感到困惑。

相关问题