New topic: Operation cannot be completed because the database is closed
<http://forums.realsoftware.com/viewtopic.php?t=46625> Page 1 of 1 [ 2 posts ] Previous topic | Next topic Author Message Sky Stream Post subject: Operation cannot be completed because the database is closedPosted: Sat Jan 19, 2013 10:22 pm Joined: Sun Nov 23, 2008 12:27 am Posts: 370 Location: New Jersey I am in the process of re-writing one of my file scanning console apps in which I decided to try something a bit different. For the most part, the console app will index folders and its contents to a rb database in which will allow the end user to perform certain operations on the indexed files. In the following code: dim dbRec as new DatabaseRecord dim dcm as new dicomClass dim rs as RecordSet, fileID, objectCount as Integer, fileObject, activeObject as FolderItem while app.copyBotDB.Connect = true rs = app.copyBotDB.SQLSelect("select b.file_id, a.folder_path || '\' || b.file_name [file_path] from folders a join files b on b.folder_id = a.folder_id where dicom_flg = 1 and is_dicom_processed = 0 limit 500") if rs.RecordCount = 0 then exit ' if file list is empty then exit. rs.MoveFirst do fileID = rs.Field("file_id").IntegerValue fileObject = GetFolderItem(rs.Field("file_path").StringValue) if dcm.checkDicom(fileObject) = true then ' if file object is dicom dbRec.IntegerColumn("file_id") = fileID dbRec.Column("patient_id") = dcm.read("patientID") dbRec.Column("patient_name") = dcm.read("patientName") dbRec.Column("dob") = dcm.read("dob") dbRec.Column("gender") = dcm.read("gender") dbRec.Column("accession_number") = dcm.read("accessionNumber") dbRec.Column("study_date") = dcm.read("studyDate") dbRec.Column("study_time") = dcm.read("studyTime") dbRec.Column("modality") = dcm.read("modality") dbRec.Column("instance_number") = dcm.read("instanceNumber") dbRec.Column("institution_name") = dcm.read("institutionName") dbRec.Column("manufacture") = dcm.read("manufacture") dbRec.Column("manufacture_model") = dcm.read("manufactureModel") dbRec.Column("sop_instance_uid") = dcm.read("sopInstanceUID") dbRec.Column("series_instance_uid") = dcm.read("seriesInstanceUID") dbRec.Column("study_instance_uid") = dcm.read("studyInstanceUID") app.copyBotDB.InsertRecord "dicoms", dbRec end if if app.copyBotDB.Error then' Commit changes to db print "ERROR: " + app.copyBotDB.ErrorMessage else print "indexing - " + str(fileID) + " - " + fileObject.AbsolutePath app.copyBotDB.SQLExecute(("update files set is_dicom_processed = 1 where file_id = " + str(fileID))) app.copyBotDB.Commit end if rs.MoveNext loop until rs.EOF wend I get mix results with data being inserted in its designation table. Either the data is inserted in or it outputs an error code of: Operation cannot be completed because the database is closed. any suggestions as to why the db connection closes? Also, I noticed that it sometimes does not loop through all the recordsets. thank you in advance. _________________ - Rich Top Dale Post subject: Re: Operation cannot be completed because the database is clPosted: Sun Jan 20, 2013 12:04 am Joined: Thu Mar 01, 2007 2:02 pm Posts: 219 Location: Sunny (generally!) Southern California What you are doing is Quote:while app.copyBotDB.Connect = true [...stuff deleted...] wend and that can cause problems because you are opening new connections each time through the loop. A better way is to do something like if app.copyBotDB.Connect = true then 'do all your stuff ' close the database when you are done with it. end if - Dale _________________ ----- Real Studio 2012r1 on Windows 7 (64 bit) ----- It has been said that politics is the second oldest profession. I have learned that it bears a striking resemblance to the first. - Ronald Reagan Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 2 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
