|
-
Sep 16th, 2005, 08:12 AM
#1
Thread Starter
Junior Member
[RESOLVED] detecting a missing database
hi guys;;
am working on a library system.am using ADO and the application gets the database from within its folder.so far everything is working fine but i want to trap the error message brought up when the database is not detected!!!ie missing and possibly give an appropriate message! and exit the application
am using a dataenvironment connection!
so how do i do that?
-
Sep 16th, 2005, 08:30 AM
#2
Re: detecting a missing database
VB Code:
On Error Goto ErrTrap
'your database code
Exit Sub
ErrTrap:
Msgbox "An Error has occurred. That error is: " & Err.Number & " " & Err.Description
End Sub
-
Sep 16th, 2005, 08:39 AM
#3
Hyperactive Member
Re: detecting a missing database
To expand on Hack's response, try this
VB Code:
On Error Goto ErrTrap
'your database code
Exit Sub
ErrTrap:
If Err.Number = -2147220992 Then
MsgBox ("Database not found")
'Put your cleaning up and closing routines here
Exit Sub
End If
End Sub
-
Sep 16th, 2005, 08:42 AM
#4
Re: detecting a missing database
To expand on anguswalker's response: 
VB Code:
On Error Goto ErrTrap
'your database code
Exit Sub
ErrTrap:
If Err.Number = -2147220992 Then
MsgBox ("Database not found")
'Put your cleaning up and closing routines here
Else
'in case you encounter an error other than missing database
Msgbox "An Error has occurred. That error is: " & Err.Number & " " & Err.Description
End If
End Sub
I actually wanted to put the error number for missing database in my first post, but I couldn't remember what it was.
-
Sep 16th, 2005, 08:53 AM
#5
Hyperactive Member
Re: detecting a missing database
... and my suggestion wasn't really an error handler, was it.
Ah well.
-
Sep 16th, 2005, 08:54 AM
#6
Re: detecting a missing database
Yes it was....Just a very specific error handler.... HAck kept that part and added a generic section.
-tg
-
Sep 16th, 2005, 08:55 AM
#7
Re: detecting a missing database
 Originally Posted by anguswalker
... and my suggestion wasn't really an error handler, was it.
Ah well.
Sure it was. It would have prevented a runtime error which would have popped the user back to the desktop. That is error trapping.
-
Sep 16th, 2005, 09:03 AM
#8
Re: detecting a missing database
I normaly do the following code:
VB Code:
Set FSys = New FileSystemObject
If gstrDBLoc = "" Then gstrDBLoc = App.Path
If gstrDBName <> "" And FSys.FileExists(gstrDBLoc & "\" & gstrDBName) Then
OpenDB
Else
fDBLoc.Show
Exit Sub
End If
If Not FSys Is Nothing Then Set FSys = Nothing
If the database is not there I open a form and allow the user to point me to the new database location. Altough I do not use the data controls you can just exit out with a message if the database is required to be in a specific place.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Sep 16th, 2005, 09:23 AM
#9
Hyperactive Member
Re: detecting a missing database
With that approach, does the new form (fDBLoc) write to some sort of .ini file to store the amended filename for the future, and does gstrDBName come from reading that .ini file?
-
Sep 16th, 2005, 09:26 AM
#10
Re: detecting a missing database
Actually I post the database name into the Registry. Before the code above I do a getsettings call for the database name and set it into the global variable gstrDName. The fDBLoc is a form that lets you find the database on your system or the network. When you set it on the form it will set the variable and do a savesetting to the registry so that next time you start the app it will look for that database. This allows the user to rename the db if they want to.
Last edited by GaryMazzone; Sep 16th, 2005 at 09:31 AM.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Sep 16th, 2005, 09:32 AM
#11
Re: detecting a missing database
 Originally Posted by GaryMazzone
If the database is not there I open a form and allow the user to point me to the new database location.
Regardless of what method you end up selecting davypipes, this is an outstanding idea! 
(BTW: Why did you double post this question? )
-
Sep 17th, 2005, 09:32 AM
#12
Thread Starter
Junior Member
-
Sep 18th, 2005, 01:08 AM
#13
Re: detecting a missing database
If you subscribe to your threads, when you go into your UserCP, there will be a list of threads that have had a reply since last visit.
-tg
-
Sep 19th, 2005, 07:38 AM
#14
Thread Starter
Junior Member
Re: detecting a missing database
thanks techgnome...didnt know it was that simple!!!..so much for my ignorance!!!
so does anyone know about my stated problem?
-
Sep 19th, 2005, 07:51 AM
#15
Re: detecting a missing database
I've never used the dataenvirnoment, but it seems to me that error trapping should work regardless of how you are connecting. Did you try it?
-
Sep 20th, 2005, 04:41 AM
#16
Thread Starter
Junior Member
Re: detecting a missing database
yeah...ive tried the "on error_goto" statement on form load but it seems as if the connections are first done b4 it loads.now what am trying to find out is what procedure is called first, which i think is associated with the dataenvironment object and maybe from there ill be able to bypass/trap that error! so far i think its the "DataEnvironment_Initialize()" procedure thats been called first when the application runs(.....i pasted a message and it was displayed before the main form was loaded!) now all i need to figure out is how to trap the error from there!! hopefully ill get one and definately paste it right here in the forum!!!
Last edited by davypipes; Sep 20th, 2005 at 04:45 AM.
-
Sep 20th, 2005, 07:48 AM
#17
Re: detecting a missing database
Why not use my suggestion (repsonse number 8) in a Sub Main. Call the sub main to open the app. Test if your Acess DB is were you think it should be. If not Put up a messagebox saying that the DB is missing and then exit the app.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Sep 22nd, 2005, 09:56 AM
#18
Thread Starter
Junior Member
Re: detecting a missing database
GaryMazzone....implemented your code and....IT WORKED FINE!! thanks. how does someone put the database name in the registry?
and whats this part for:?
If Not FSys Is Nothing Then Set FSys = Nothing
-
Sep 22nd, 2005, 10:02 AM
#19
Re: detecting a missing database
Look at GetSetting and SaveSetting. The If Not FSysy line if to clean up after my self. I never exit with a procdure or function with any obect left set if I don't need it somewhere. Garbage cleanup manually I guess.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Sep 22nd, 2005, 10:08 PM
#20
Re: detecting a missing database
 Originally Posted by davypipes
hi guys;;
am working on a library system.am using ADO and the application gets the database from within its folder.so far everything is working fine but i want to trap the error message brought up when the database is not detected!!!ie missing and possibly give an appropriate message! and exit the application
am using a dataenvironment connection!
so how do i do that?
Just curious, since you said it is getting the database from within its folder why would there be a case when a database is not detected? Will it be a case when somebody deleted it or something? Perhaps you may want to set the connectionstring at run-time and determine if you could open it or not...
-
Sep 23rd, 2005, 07:11 AM
#21
Thread Starter
Junior Member
Re: detecting a missing database
yeah...just incase the user deletes it somehow!!!
as for the connection string...thats what am working on right now..as my library application consists of 3 programs..one will be on the same computer(folder) as the database while the other 2 will be on different computers which will access this shared folder over the LAN inorder to get the database!!! so i have decided to connect by code for the other 2 programs. i want to use an open dialog control to save the path of the database for this 2 applications hence get the path from a text file at run time!!.am not to sure on how to do that,but if i get in a rut ill sure ask you guys for help(btw thanks for your help guys! :-))
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|