【问题标题】:sqlite attached database problemsqlite附加数据库问题
【发布时间】:2011-05-14 20:47:45
【问题描述】:

当我尝试访问具有内置架构的有效 SQLiteConnection 上的附加 db 文件时,我收到“没有这样的表”错误。

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

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.

但是,当我尝试插入文件时,我在这篇文章的末尾收到错误消息。

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

干杯,
浆果

测试“SQLiteTesting.Helpers.QueryTests.Director_if_Tim_Burton_query_should_return_one_movie”失败:QueryTests 中的 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() 在 SQLiteTesting.Helpers.SQLiteLoader._copyTableData(SQLiteConnection conn, String source, String destination) 在 C:\Users\Lord & Master\Documents\Projects\Data\NHib projects\Cookbook\SQLiteTesting\Helpers\SQLiteLoader.cs:line 68 在 SQLiteTesting.Helpers.SQLiteLoader.ExportData(SQLiteConnection conn, String dataFile) 在 C:\Users\Lord & Master\Documents\Projects\Data\NHib projects\Cookbook\SQLiteTesting\Helpers\SQLiteLoader.cs:line 30 在 C:\Users\Lord & Master\Documents\Projects\Data\NHib projects\Cookbook\SQLiteTesting\Helpers\QueryTests.cs:line 25 中的 SQLiteTesting.Helpers.QueryTests.OnFixtureSetUp() 在 C:\Users\Lord & Master\Documents\Projects\Data\NHib projects\Cookbook\SQLiteTesting\Helpers\BaseFixture.cs:line 23 中的 SQLiteTesting.Helpers.BaseFixture.FixtureSetUp() 2010-11-23 18:15:36,835 DEBUG ATTACH '...\bin\Debug\testData.db3' AS asd 2010-11-23 18:18:12,935 调试插入 asdf.ActorRole SELECT * FROM ActorRole

【问题讨论】:

    标签: c# nhibernate sqlite


    【解决方案1】:

    线索是:

    SQLite error no such table: asdf.ActorRole at
    

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

    仔细检查您的文件路径并在您的目录中寻找一个新的空 sq3 文件。

    【讨论】:

    • 嗨詹姆斯。假设附件自动将架构从现有连接复制到附件数据库中是否不正确?如果是这样,我需要手动复制所有表,最好的方法是什么?干杯
    • 我不是这么说的!如果您指定一个不存在的文件,sqlite 将创建一个具有空架构的新文件。
    • 您确实说过它将是空的,这确实帮助我意识到 ATTACH 并没有像我想象的那样复制数据库。创建表后,一切正常。我认为澄清新信息的后续问题是一件好事,你不同意吗?
    • 这被标记为答案,理解为完整和附加不会复制现有连接上的数据库。詹姆斯提到的陷阱并不比任何其他使用误解更多。干杯
    • 谢谢 -- 很高兴能提供帮助,尽管这不是您问题的确切答案!
    【解决方案2】:

    您需要 AS {1} 语句吗?强制使用数据库名称似乎会混淆它。

    【讨论】:

    • 我认为是这样,因为我们的想法是复制同一个数据库的两个副本,一个在内存中,一个在文件中。因此,当引用将在两个数据库中的表时,SQLite 有一种方法来区分哪个是哪个。
    猜你喜欢
    • 1970-01-01
    • 2013-05-06
    • 2012-10-19
    • 2014-07-11
    • 2011-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-10
    相关资源
    最近更新 更多