Solved

Trap an errors in the ADODC control

Posted on 2004-08-13
5
309 Views
Last Modified: 2008-02-01
Using ADODC control to connect to SQL Server 2000....

I have a login form that takes the username and password from the user and then constructs a connection string, then connect to database and populates a datagrid if the username and password is right.

How do I trap an error that is given when the wrong username or password is put into the connectionstring?  Right now if I type in the wrong password or username it puts up a small messagebox.  The messagebox is titled "ADODC1"  the message is "Login failed for user 'ASD'"

ASD is just a bogus username...  
0
Comment
Question by:strongd
  • 3
  • 2
5 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 125 total points
Comment Utility
Hello again :o)

You can use the Error event of the ADO control to catch the error and prevent the default error dialog.

Something like:

Private Sub Adodc1_Error(ByVal ErrorNumber As Long, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, fCancelDisplay As Boolean)
   
    '// 3661 is 'login failed'
    If ErrorNumber = 3661 Then
        MsgBox "Username or password incorrect"
        fCancelDisplay = True
    End If
   
End Sub

Private Sub Command1_Click()

      On Error Resume Next     '<--- We need this because if the login fails the Refresh method will cause an error

      Adodc1.ConnectionString = "blah blah blah"
      Adodc1.Refresh

End Sub


Hope this helps.
0
 

Author Comment

by:strongd
Comment Utility
Carl, you're on a role..  You just helped me again... Thanks for everything...  This worked perfectly...

And you keep your title as "The Best!!!'

Thanks again...

0
 

Author Comment

by:strongd
Comment Utility
Carl, can you recommend a good book that will explain the ADO objects?

I have about 5 years of VB, but I moved to a different job and started doing Oracle stuff (PL/SQL) and this is the first time I have done any VB in a few years.  I am rusty.  

In my past VB prgramming days, I didn't do any database stuff with VB.  So ADO stuff is all new for me.  

0
 
LVL 52

Expert Comment

by:Carl Tawn
Comment Utility
Well, depending on how your feeling. Trawling MSDN will probably give you a good idea of the architecture and relationships between the different objects. Also the object browser in VB (press F2) will list all the objects, their properties/methods/events (although they can be a little vague).

Personally I like the Sams series of books (very straight forward, lots of sample code and explanations), Wrox are good too, although finding them is a bit trickier than it was after they went bust.

Also this site: http://www.w3schools.com/ado/default.asp  has a good range of tutorials. There nothing too in-depth but they'll at least give you a reasonable start.
0
 

Author Comment

by:strongd
Comment Utility
Ahh...ok thanks..

I am familar with w3schools.com.  I have used it before in the past.  I didn't think of looking there.

Thanks again.

Have a great weekend.

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now