# Interrupting the testing process makes it work

**URL:** <https://forum.kirupa.com/t/interrupting-the-testing-process-makes-it-work/327641>\
**Category:** flash\
**Created:** [March 16, 2012, 2:28am UTC](https://forum.kirupa.com/t/interrupting-the-testing-process-makes-it-work/327641 "2012-03-16T02:28:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![joesafe](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@joesafe](https://forum.kirupa.com/u/joesafe)\
**Post date:** [March 16, 2012, 2:28am UTC](https://forum.kirupa.com/t/interrupting-the-testing-process-makes-it-work/327641/1 "2012-03-16T02:28:46Z")

</div>

Hello,  
I’m using Flash CS5.5 to connect to an SQLite database called “base.db”.

The connection works fine and it can return values from the database, but only if i interrupt the test by clicking ctrl+enter again and then clicking “no” when it asks me to cancel.

IF i just let the test run then I get the following error:

Error: Error #3104: A SQLConnection must be open to perform this operation.  
at Error$/throwError()  
at flash.data::SQLStatement/checkAllowed()  
at flash.data::SQLStatement/checkReady()  
at flash.data::SQLStatement/execute()  
at AdobeExamples\_fla::MainTimeline/frame1()[AdobeExamples\_fla.MainTimeline::frame1:36]  
at runtime::ContentPlayer/loadInitialContent()  
at runtime::ContentPlayer/playRawContent()  
at runtime::ContentPlayer/playContent()  
at runtime::AppRunner/run()  
at ADLAppEntry/run()  
at global/runtime::ADLEntry()  
the database opened successfully  
[UnloadSWF] AdobeExamples.swf  
Test Movie terminated.

Here is the code:

```auto

import flash.data.SQLConnection; 
import flash.data.SQLMode; 
import flash.data.SQLResult; 
import flash.data.SQLStatement; 
import flash.errors.SQLError;
import flash.events.SQLErrorEvent; 
import flash.events.SQLEvent; 
import flash.filesystem.File; 

import flash.data.SQLConnection; 
             
            import flash.events.SQLErrorEvent; 
            import flash.events.SQLEvent;
     
var conn:SQLConnection = new SQLConnection(); 
     
conn.addEventListener(SQLEvent.OPEN, openHandler); 
conn.addEventListener(SQLErrorEvent.ERROR, errorHandler); 
     
// The database file is in the application storage directory 
var folder:File = File.applicationDirectory; 
var dbFile:File = folder.resolvePath("base.db"); 
     
conn.openAsync(dbFile, SQLMode.UPDATE); 
        
var selectStmt:SQLStatement = new SQLStatement(); 
     
// A SQLConnection named "conn" has been created previously 
selectStmt.sqlConnection = conn; 
     
selectStmt.text = "SELECT id, letter1, letter2, letter3 FROM tablewords"; 
     
selectStmt.addEventListener(SQLEvent.RESULT, resultHandler); 
selectStmt.addEventListener(SQLErrorEvent.ERROR, errorHandler); 
     
selectStmt.execute(); 
     
function resultHandler(event:SQLEvent):void 
{ 
    var result:SQLResult = selectStmt.getResult(); 
     
    var numResults:int = result.data.length; 
    for (var i:int = 0; i < numResults; i++) 
    { 
        var row:Object = result.data*; 
        var output:String = "id: " + row.id; 
        output += "; letter1: " + row.letter1; 
        output += "; letter2: " + row.letter2; 
        output += "; letter3: " + row.letter3;
        trace(output); 
    } 
} 
     
     function openHandler(event:SQLEvent):void 
{ 
    trace("the database opened successfully"); 
}

     
function errorHandler(event:SQLErrorEvent):void 
{ 
    
}

```

Can anyone tell me why this is happening?

I can’t help thinking that these last few days i’ve been going round in circles, and i might have had it right the first time.
