Solved

How to obtain info about missing database elements

Posted on 2001-06-20
4
152 Views
Last Modified: 2010-05-02
Hi,

With missing database elements I mean a table that the app expects to be there and that isn't or a column that is expected to be in a table and that isn't. I'm using the ADO functionality to access a database and what I want to achieve is to provide detailed information if database access fails due to a missing element. Is it possible to provide detailed information, for instance to say that table <tablename> is missing in database <databasename>, or that column <columnname> is missing in table <tablename> in database <databasename>, or that <columnname> is missing in view <viewname> in database <databasename> ? If I'm able to provide this detailed information, often it will be much easier to establish a proper diagnose, will in turn will result in quicker resolution of herefore mentioned problems. Please try to be precise if you come up with suggestions or solutions.

thanks,
Henk
0
Comment
Question by:hge
4 Comments
 
LVL 1

Expert Comment

by:barendb
ID: 6213236
Henk,

I would use On Error Resume Next and then after calling the table or column check if error occurred.  You can do this once when opening the table or database so that you don't have to check it every time you read/write it.

Barend
0
 
LVL 50

Accepted Solution

by:
Ryan Chong earned 100 total points
ID: 6214414
Hi, to find whether a table exists in a database, you can use the ADOX library:

Private Sub Command1_Click()
   Dim cnn As ADODB.Connection
   Dim cat As ADOX.Catalog
   Dim tblTable As ADOX.Table
   Dim blnExists As Boolean
   Set cnn = New ADODB.Connection
   Set cat = New ADOX.Catalog
   cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\testbed\cremosa2k.mdb;Persist
Security Info=False"
   cnn.Open
   cat.ActiveConnection = cnn.ConnectionString
   For Each tblTable In cat.Tables
       If tblTable.Name = "MyTable" Then
           blnExists = True
           Exit For 'as we have found it
       End If
   Next
   cnn.Close
   Set cat.ActiveConnection = Nothing
   Set cat = Nothing
   Set cnn = Nothing
   MsgBox "Table : MyTable " & IIf(blnExists, "Exists", "Does Not Exist")
End Sub

OR

Alternatively using Data Control

Data1.RecordSource = "Select * from Lead"
   Data1.Refresh
   For i = 1 To Data1.Database.TableDefs.Count
       List2.AddItem Data1.Database.TableDefs(i - 1).Name
   Next i

'Hope will help.

Original link: http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20134594
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7139601
Hi hge,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Accept ryancys's comment(s) as an answer.

hge, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:Computer101
ID: 7173277
Comment from expert accepted as answer

Computer101
E-E Moderator
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question