{"id":215,"date":"2010-11-17T23:17:26","date_gmt":"2010-11-17T23:17:26","guid":{"rendered":"https:\/\/greladesign.co\/blog\/?p=215"},"modified":"2011-01-05T23:50:37","modified_gmt":"2011-01-05T23:50:37","slug":"sqlite-open-and-openasync-methods-not-create-folders-for-created-database-file","status":"publish","type":"post","link":"https:\/\/greladesign.co\/blog\/2010\/11\/17\/sqlite-open-and-openasync-methods-not-create-folders-for-created-database-file\/","title":{"rendered":"SQLite \u2013 open and openAsync methods NOT create folders for created database file"},"content":{"rendered":"<p>If you run into problems with connecting to the database and you are using open or openAsync with CREATE mode then check if folder location exists for your database file,<\/p>\n<p>following code will generate SQLError<\/p>\n<pre>\r\nSQLError: \u2019Error #3125: Unable to open the database file.\u2019, \r\ndetails:\u2019Connection closed.\u2019, operation:\u2019open\u2019, detailID:\u20191001\u2019\r\n<\/pre>\n<p><!--more--><\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nimport flash.data.SQLConnection;\r\nimport flash.data.SQLMode;\r\nimport flash.filesystem.File;\r\n\r\nvar m_oAppStorageDir:File = File.documentsDirectory.resolvePath(&quot;myFolder\/structure&quot;);\/\/my documents or sdcard\r\n\r\nvar m_oConnection:SQLConnection = new SQLConnection();\r\n\r\ntry\r\n{\r\n\tm_oConnection.open(m_oAppStorageDir.resolvePath(&quot;myDb.db&quot;), SQLMode.CREATE);\r\n}\r\ncatch (e:Error)\r\n{\r\n\ttrace(e.getStackTrace());\r\n}\r\n<\/pre>\n<p>it is because differently then in FileStream class the SQLConnection creates only database file and not entire folder structure. To fix it call createDirectory method of the File instance.<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nimport flash.data.SQLConnection;\r\nimport flash.data.SQLMode;\r\nimport flash.filesystem.File;\r\n\r\nvar m_oAppStorageDir:File = File.documentsDirectory.resolvePath(&quot;myFolder\/structure&quot;);\/\/my documents or sdcard\r\ntry\r\n{\r\n\tm_oAppStorageDir.createDirectory();\r\n}\r\ncatch (e:Error)\r\n{\r\n\ttrace(e.getStackTrace());\r\n}\r\n\r\nvar m_oConnection:SQLConnection = new SQLConnection();\r\n\r\ntry\r\n{\r\n\tm_oConnection.open(m_oAppStorageDir.resolvePath(&quot;myDb.db&quot;), SQLMode.CREATE);\r\n}\r\ncatch (e:Error)\r\n{\r\n\ttrace(e.getStackTrace());\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you run into problems with connecting to the database and you are using open or openAsync with CREATE mode then check if folder location exists for your database file, following code will generate SQLError SQLError: \u2019Error #3125: Unable to &hellip; <a href=\"https:\/\/greladesign.co\/blog\/2010\/11\/17\/sqlite-open-and-openasync-methods-not-create-folders-for-created-database-file\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":""},"categories":[17,47,9,58],"tags":[12,39,50,56,53,52,55,51,54],"_links":{"self":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/215"}],"collection":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/comments?post=215"}],"version-history":[{"count":8,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/215\/revisions"}],"predecessor-version":[{"id":238,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/215\/revisions\/238"}],"wp:attachment":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/media?parent=215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/categories?post=215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/tags?post=215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}