Zeal Posted February 7 Share Posted February 7 I am inserting data using below sequence. In this sequence Registry.strFileName[0] is my database path and name. The sequence runs fine and my data gets dump good. However after some time there is an error showing unable to connect database. After restarting the sequence manually same error prevails. But after restarting Daq Factory project the sequence starts working normally again and data inserting works ok. while(1) if (AutoCycleRunning == 1) dbase = db.OpenEx("Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\Zeal\Hitachi\DB\"+Registry.strFileName[0]+".mdb;Uid=Admin;Pwd=;") db.Execute(dbase,"INSERT INTO Data_(A1,A2,A3,A4,A5,A6) values ('"+ FormatDateTime("%Y-%m-%d %H:%M:%S", SysTime()) +"','"+Angle_PV[0]/10+"','"+ Torque[0] +"','"+ DC_Current[0]/100 +"','"+ AC_Current[0]/100 +"','"+ PresentCount[0] +"')") db.Close(dbase) endif if (AutoCycleRunning == 0) delay(1) db.Close(dbase) endseq(S3) endif delay(0.01) endwhile Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted February 7 Share Posted February 7 I do not recommend opening and closing the database. Just open it once outside the loop or in an AutoStart sequence and leave it open. There is no reason to close the connection. DAQFactory will do this automatically when it quits. Is the name of this sequence S3? Quote Link to comment Share on other sites More sharing options...
Zeal Posted February 8 Author Share Posted February 8 Yes the name of my sequence is S3. We will implement your suggestion and will inform about the result. I think this will surely work. Quote Link to comment Share on other sites More sharing options...
AzeoTech Posted February 8 Share Posted February 8 I asked because you should replace the endseq(S3) with just return: if (AutoCycleRunning == 0) delay(1) db.Close(dbase) return endif There is no reason to tell a sequence to stop itself using endseq() Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.