Trap an errors in the ADODC control

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...  
strongdAsked:
Who is Participating?
 
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
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
 
strongdAuthor Commented:
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
 
strongdAuthor Commented:
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
 
Carl TawnSystems and Integration DeveloperCommented:
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
 
strongdAuthor Commented:
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
All Courses

From novice to tech pro — start learning today.