【发布时间】:2018-06-10 09:23:43
【问题描述】:
我有一个运行良好的移动应用 (android/ios),但 Google 要求开发人员现在使用 targetSdkVersion 26(我的到目前为止是 19)。 现在我使用 26,我有一个错误 #3125:
SQLError: 'Error #3125: Unable to open the database file.', details:'Connection closed.', operation:'open', detailID:'1001'
这是我打开数据库的代码:
static private function openDatabase(datebaseName:String) {
sqlCon = new SQLConnection();
dbDir = File.documentsDirectory.resolvePath("ZANORG");
dbDirFile = File.documentsDirectory.resolvePath("ZANORG/" + datebaseName + ".db");
if (dbDirFile.exists) {
trace("File exists");
sqlCon.addEventListener(SQLEvent.OPEN, onDatabaseOpen);
sqlCon.open(dbDirFile); // Error #3125 is here
} else {
trace("File does not exist");
if (!dbDir.exists){
trace("Folder doesn't exist > Create");
try{
dbDir.createDirectory();
}catch (error:Error){
trace("ERROR");
return;
}
}
sqlCon.addEventListener(SQLEvent.OPEN, onDatabaseCreationOpen);
sqlCon.open(dbDirFile);
var strReq:String = "CREATE TABLE IF NOT EXISTS gamedata (Score INT)";
sqlquery(strReq);
strReq = "INSERT INTO gamedata (Score) values(0)";
sqlquery(strReq);
}
}
【问题讨论】:
-
大概是这个:stackoverflow.com/questions/39103863/… 如果不是,那我还是觉得是权限问题而不是代码问题。
-
您可能会发现此链接对SQLError #3125 有帮助,其中 这是预期的行为。数据库不会代表您创建文件夹。要解决此问题,您只需添加一些代码以确保该目录已经存在。例如:
File.applicationStorageDirectory.resolvePath("db").createDirectory(); -
我已经尝试过这些解决方案,但没有效果。我真的不明白为什么更改 targetSdkVersion 会导致这个错误!
标签: android sqlite actionscript-3 air