Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Error #3119: Database file is currently locked in SQLite DB

Posted on 2011-05-09
7
Medium Priority
?
1,753 Views
Last Modified: 2012-05-11
Hi,

I am getting Error #3119: Database file is currently locked. ..in sqlite DB

I my application i am connecting to dB from two different places....

How can i use a single connection..
Or should i have to close the DB Connection

Is there any point which i should keep in mind while working with sqlite DB...within complete application..when i connect from diff places from application....
0
Comment
Question by:SreeramojuPradeep
  • 4
  • 3
7 Comments
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 35720487
Well your problem is that sql lite doesn't support using one DB file from multiple Programs. If you are using it from two places inside the same application the singleton-pattern might help you, but if you are using multiple programs, then you will have to use a real SQL database instead.
0
 

Author Comment

by:SreeramojuPradeep
ID: 35726514
I used singleton class...
But once the database is open i will be performing different actions in different pages...
Before using singleton
 
var dbCaseFileListing:File = File.applicationStorageDirectory.resolvePath("scheduler.db");
				trace(dbCaseFileListing.nativePath);
				sqlC.openAsync(dbCaseFileListing);
				sqlC.addEventListener(SQLEvent.OPEN, onDatabaseOpen);
				sqlC.addEventListener(SQLErrorEvent.ERROR, errorAlert);
				sqlC.addEventListener(SQLErrorEvent.ERROR, errorAlert);


private function onDatabaseOpen(event:SQLEvent):void{
				// when the database is opened we need to link the SQLStatment to our SQLConnection, so that sql statments for the right database.
				// if you don't set this connection you will get an error when you execute sql statment.
				sqlS.sqlConnection = sqlC;
				// in property text of our SQLStatment we write our sql command. We can also combine sql statments in our text property so that more than one statment can be executed at a time.
				// in this sql statment we create table in our database with name "test_table" with three columns (id, first_name and last_name). Id is an integer that is auto incremented when each item is added. First_name and last_name are columns in which we can store text
				// If you want to know more about sql statments search the web.
				sqlS.text = "CREATE TABLE IF NOT EXISTS SCHEDULER_MASTER (CLIENT_ID INTEGER PRIMARY KEY AUTOINCREMENT, FOLDER_NAME VARCHAR(300));"
				// after we have connected sql statment to our sql connection and writen our sql commands we also need to execute our sql statment.
				// nothing will change in database until we execute sql statment.
				sqlS.execute();
				refresh();
			}


private function refresh(e:TimerEvent = null):void
			{
				// timer object which we need if sql statment is still executing so that we can try again after 10 milliseconds.
				var timer:Timer = new Timer(10,1);
				timer.addEventListener(TimerEvent.TIMER, refresh);
				
				if ( !sqlS.executing )// we need to check if our sql statment is still executing our last sql command. If so we use Timer to try again in 10 milliseconds. If we wouldn't check we could get an error because SQLStatment can't execute two statments at the same time.
				{
					var sql:String ="INSERT INTO SCHEDULER_MASTER values(null,'"+ userCN + userCT +"')";	
					sqlS.text = sql;
					sqlC.begin();
					sqlS.addEventListener(SQLEvent.RESULT, statResult);
					sqlS.execute();
					sqlC.commit();
				}
				else
				{
					timer.start();
				}
			}

Open in new window


After using single ton
On database open i will be performing different actions either insert or select but...when i am using single how to handle this

 
package model
{
	import flash.data.SQLConnection;
	import flash.events.SQLErrorEvent;
	import flash.events.SQLEvent;
	import flash.filesystem.File;
	
	import mx.controls.Alert;

	//import vo.LoginVO;
	
	[Bindable]
	public class ModelLocator
	{
		private static var instance:ModelLocator=null;
		
		public static function getInstance():ModelLocator
		{
			if (instance == null)
				instance=new ModelLocator();
			return instance;
		}
		
		public function ModelLocator()
		{
			if (instance != null)
			{
				throw new Error("Cannot Create Instance Of Singleton Class ModelLocator");
			}
			instance=this;
			initModels();
		}
		
		public var bareacts:String;
		
		private var sqlC:SQLConnection = new SQLConnection();
		
		/*---------------------------------- VO Variables Declaration------------------- */
		//initialize the login variable - LoginVO instance 
		//public var login:LoginVO=new LoginVO();
		
		
		/* -------------------------- VARIABLES INITIALIZATION-------------------------- */
		public function initModels():void
		{
			var lawpadDBFile:File = File.applicationStorageDirectory.resolvePath("scheduler.db");
			trace(lawpadDBFile.nativePath);
			sqlC.openAsync(lawpadDBFile);
			sqlC.addEventListener(SQLEvent.OPEN, onDatabaseOpen);
			sqlC.addEventListener(SQLErrorEvent.ERROR, errorAlert);
		}
		
		private function errorAlert(e:SQLErrorEvent):void
		{
			Alert.show(e.error.errorID + "\n\n" + e.error.message + "\n" + e.error.details);
		}
	}
}

Open in new window

0
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 35726699
You don't need a singleton in the Flex client, but on the server-side.
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Comment

by:SreeramojuPradeep
ID: 35728264
u mean on server side...But i am connecting to sqlite DB from air application only.....
Is this not right approach.....
0
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 35728308
Ok ... sorry for that ... I've never used an ActionScript Internal DB ;-)

I had a little look at your code, you don't have a commit or roleback in your primary operation in onDatabaseOpen ... I think the timer is then starting a second parallel operation and this is causing your problems.
0
 

Author Comment

by:SreeramojuPradeep
ID: 35728348
I am desktop application...
Thats ok...
But i would like to know..
I dont want to set this below  code snippet in singleton...
Bec from diff pages i willperform diff actions on DB open...
So how to handle it....
 
sqlC.addEventListener(SQLEvent.OPEN, onDatabaseOpen);

Open in new window

0
 
LVL 20

Accepted Solution

by:
ChristoferDutz earned 1000 total points
ID: 35728358
Well another option would be not to use the async mode but the synchronous mode ... then you don't have any problems with callbacks.
http://www.peterelst.com/blog/2008/04/07/introduction-to-sqlite-in-adobe-air/
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
Moore’s Law has proven itself time and time again since it was first introduced. So what’s next? Will Moore’s law continue to remain relevant, or will new technology take over and bring us the next big advancement in computing?
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question