繁体   English   中英

无法使用消息“数据库已使用sqlite3在ios中锁定数据库”来打开数据库

[英]Failed to open database with message 'database is locked in ios using sqlite3

即使在打开数据库之前我已经明确关闭数据库,我仍然面临以下与iO中的sqlite数据库有关的问题,但是我仍然一次又一次地遇到相同的问题。

由于未捕获的异常“ NSInternalInconsistencyException”而终止应用程序,原因:“无法打开消息为“数据库已锁定”的数据库。

这是我的代码

sqlite3_stmt *statement;
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
{
    const char *insert_stmt = "INSERT INTO myusertbl (username,password) VALUES (?,?)";
    if(sqlite3_prepare_v2(contactDB, insert_stmt, -1, &statement, NULL)==SQLITE_OK)
    {
        sqlite3_bind_text( statement,1, [self.username UTF8String], -1, SQLITE_TRANSIENT);
        sqlite3_bind_text( statement,2, [self.userpass   UTF8String], -1, SQLITE_TRANSIENT);
    }
    if (sqlite3_step(statement) == SQLITE_DONE)
    {
        NSLog(@"You have Sucessfully saved!");
    }
    else
    {
        NSLog(@"Failed to Save!");
        NSAssert1(0, @"Failed to open database with message '%s'.",           sqlite3_errmsg(contactDB));
    }
    sqlite3_finalize(statement);
    statement = nil;
}

请帮我。

您确定要使用sqlite3_close API关闭数据库吗?

sqlite3_close(contactDB); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM