我可以ATTACH数据库并将所有数据从一个数据库复制到另一个数据库。但最后我无法使用相同的代码将其分离。
var connection = new SQLiteConnection(connection)
connection.Open();
sqlAttachCommand = "ATTACH database '" + fileLoc + "' AS toMerge";
var cmd= new SQLiteCommand(sqlAttachCommand);
cmd.Connection = connection;
cmd.ExecuteNonQuery();
...
sqlAttachCommand = "DETACH database '" + fileLoc + "'";
例外是:
SQL逻辑错误或缺少数据库没有这样的数据库:C:\ temp \ database.db"。
这很奇怪,因为我确实附上了它,我从这个数据库中复制了所有数据。
答案 0 :(得分:1)
The DETACH DATABASE
command takes a schema-name as parameter, not a database file.
So your detach command should be like this:
sqlAttachCommand = "DETACH database toMerge";
as in your ATTACH command you named the thing toMerge
.
In the SQL Exception the missing database isn't referring to the fact that SQLite lost that file, it is mere trying to tell that you're using a schema-name that doesn't exist.