New topic: String connection. Where to put the code?. need help
<http://forums.realsoftware.com/viewtopic.php?t=46021> Page 1 of 1 [ 4 posts ] Previous topic | Next topic Author Message Antonio Post subject: String connection. Where to put the code?. need helpPosted: Thu Nov 22, 2012 1:38 pm Joined: Sat Feb 04, 2012 1:26 pm Posts: 26 Hi, I have created a database front end program; it works but I think it is way far to be written in the correct way . This is what I mean. The program connects to a single *.mdb file containings several tables. I put the connection string along the Dim declaration in several part of the code. this is the code: Dim db as ODBCDatabase db=New ODBCDatabase dim percors as FolderItem = SpecialFolder.CurrentWorkingDirectory db.datasource ="DRIVER=Microsoft Access Driver (*.mdb); UID=admin; UserCommitSync=Yes; Threads=3;SafeTransactions=0;PageTimeout=5;MaxScanRows=8;MaxBufferSize=512;ImplicitCommitSync=Yes;FIL=MS Access;DriverId=25;DefaultDir=" + percors.AbsolutePath + ";DBQ=" + percors.AbsolutePath + "\DBFile.MDB" I put this code inside the main windows before the db.sqlselect..... which loads the result inside a listbox, and inside other controls too. I mean i put that portion of code inside any control containing SQL commands. for example I put the same comnection string code inside a pushbutton which updates some field selected by another SQL code. and so on. I counted that code in over than 10 different controls among windows, buttons etc. Is that way correct?. Is there a way i can put it just once inside my program? thanks for helping. Top timhare Post subject: Re: String connection. Where to put the code?. need helpPosted: Thu Nov 22, 2012 3:21 pm Joined: Fri Jan 06, 2006 3:21 pm Posts: 11829 Location: Portland, OR USA There are 2 other possibilities: Make db a property of the window Connect to it in Window.Open Make db a property of a Module Connect to it in app.Open Remove all the Dim statements, so you're dealing with the global variable, not a local variable. Top Antonio Post subject: Re: String connection. Where to put the code?. need helpPosted: Thu Nov 22, 2012 5:12 pm Joined: Sat Feb 04, 2012 1:26 pm Posts: 26 Tim, thanks for you help. After some playing around i have almost done. program generally works but it stops at the old if db.connect then... maybe i have to put the if db.connect then..... inside the app.open I'll try tomorrow. it's almost midnight here. Top Bimal Post subject: Re: String connection. Where to put the code?. need helpPosted: Fri Nov 23, 2012 1:29 am Joined: Mon Jan 16, 2012 8:08 am Posts: 145 Location: India Antonio wrote:After some playing around i have almost done. program generally works but it stops at the old if db.connect then... maybe i have to put the if db.connect then..... inside the app.open Yes u can do one thing like u will get the database file in App.open event as tim said and before doing any database transaction u can connect to the database and after finishing the transaction u can close the connection in a particular method or event or module. It might be helpful. Like If app.DatabaseName.Connect Then DeleteQuery = "DELETE FROM Table1 WHERE id = " + Str(Id1) App.DatabaseName.SQLExecute(DeleteQuery) If App.DatabaseName.Error Then MsgBox "Error : " + app.DatabaseName.ErrorMessage Return Else app.DatabaseName.Commit app.DatabaseName.Close End If Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 4 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]
