Results 1 to 21 of 21

Thread: [RESOLVED] detecting a missing database

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2005
    Posts
    23

    Resolved [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?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: detecting a missing database

    VB Code:
    1. On Error Goto ErrTrap
    2. 'your database code
    3. Exit Sub
    4. ErrTrap:
    5. Msgbox "An Error has occurred.  That error is: " & Err.Number & " " & Err.Description
    6. End Sub

  3. #3
    Hyperactive Member
    Join Date
    May 2005
    Posts
    324

    Re: detecting a missing database

    To expand on Hack's response, try this
    VB Code:
    1. On Error Goto ErrTrap
    2. 'your database code
    3. Exit Sub
    4. ErrTrap:
    5.     If Err.Number = -2147220992 Then
    6.         MsgBox ("Database not found")
    7.         'Put your cleaning up and closing routines here
    8.         Exit Sub
    9.     End If
    10. End Sub

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: detecting a missing database

    To expand on anguswalker's response:
    VB Code:
    1. On Error Goto ErrTrap
    2. 'your database code
    3. Exit Sub
    4. ErrTrap:
    5.     If Err.Number = -2147220992 Then
    6.         MsgBox ("Database not found")
    7.         'Put your cleaning up and closing routines here
    8.     Else
    9.         'in case you encounter an error other than missing database
    10.         Msgbox "An Error has occurred.  That error is: " & Err.Number & " " & Err.Description
    11.     End If
    12. 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.

  5. #5
    Hyperactive Member
    Join Date
    May 2005
    Posts
    324

    Re: detecting a missing database

    ... and my suggestion wasn't really an error handler, was it.
    Ah well.

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: detecting a missing database

    Yes it was....Just a very specific error handler.... HAck kept that part and added a generic section.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: detecting a missing database

    Quote 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.

  8. #8
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: detecting a missing database

    I normaly do the following code:
    VB Code:
    1. Set FSys = New FileSystemObject
    2. If gstrDBLoc = "" Then gstrDBLoc = App.Path
    3. If gstrDBName <> "" And FSys.FileExists(gstrDBLoc & "\" & gstrDBName) Then
    4.     OpenDB
    5. Else
    6.     fDBLoc.Show
    7.     Exit Sub
    8. End If
    9.  
    10. 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

  9. #9
    Hyperactive Member
    Join Date
    May 2005
    Posts
    324

    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?

  10. #10
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    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

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: detecting a missing database

    Quote 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? )

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Jun 2005
    Posts
    23

    Re: detecting a missing database

    sorry for double posting!!! how can i check all my posts(new+old) the moment i log in?is there such a link,coz sometimes i end up searching for my posts using advanced search!!

    anyhooo... thanks guys for all your help...though i dont think the above codes will work with what i have since ive used the built in connectin objects provided by VB(dataenvironment..connection1..ie:have not used code to connect)
    For the database path, i only put the database name,which surprisingly regardless of where i put the folder ,the application still sees the database...coz its within the same folder! now my only problem is to detect and inform the user when the database is missing!!! so guys...emmm...how do i do that in this kind of scenario?
    Last edited by davypipes; Sep 17th, 2005 at 09:37 AM.

  13. #13
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Jun 2005
    Posts
    23

    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?

  15. #15
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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?

  16. #16

    Thread Starter
    Junior Member
    Join Date
    Jun 2005
    Posts
    23

    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.

  17. #17
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    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

  18. #18

    Thread Starter
    Junior Member
    Join Date
    Jun 2005
    Posts
    23

    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

  19. #19
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    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

  20. #20
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: detecting a missing database

    Quote 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...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  21. #21

    Thread Starter
    Junior Member
    Join Date
    Jun 2005
    Posts
    23

    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
  •  



Click Here to Expand Forum to Full Width