Solved

Suppress oracle logon dialog in VB4

Posted on 1998-05-27
3
369 Views
Last Modified: 2012-06-21
Hi
  I have trying to do a ODBC Oracle Connection using the logon screen created by VB forms and command button and textboxes.
I have a command button named connect.it contain the following codes:

connect="ODBC;....DSn......"
set db=opendatabase("",false,false,connect)

I'm supposed to use my logon screen to capture user id and password,
but the moment I key in an invalid oracle user id and password, oracle logon screen will be invoked.What I want is that my logon screen will be invoked (to let user try again) instead of the oracle logon.So is there anyway we can suppress that oracle logon.Please help.
0
Comment
Question by:ssptkt
3 Comments
 
LVL 1

Expert Comment

by:terencebeh
ID: 1461851
1. Put a error trapping. In the sub that you have the OpenDatabase statement, add in the following:

Private Sub ...
On Error Goto ErrorHandler
..
connect="ODBC;....DSn......"
set db=opendatabase("",false,false,connect)


ErrorHandler:
' Try to find out what is the error number that represent the  invalid login
    For iCnt = 0 to Errors.Count - 1
        msgbox errors(iCnt).Number
        msgbox errors(iCnt).Description
    Next

' Once you have find out the error number use the following:
    for iCnt = 0 to Errors.Count - 1
        if Errors(iCnt).Number = ???
              frmLogin.Show
        endif
    next
End Sub

Try stepping through your code by using F8 key.



0
 

Author Comment

by:ssptkt
ID: 1461852
Hi terencebeh:
   I haved tried your codes, but it doesn't seems to work.

Private Sub Command1_Click()
Dim gstr_connect As String
Dim gdb_data As Database
Dim iCnt As Integer
On Error GoTo ErrorHandler

gstr_connect$ = "ODBC;DSN=oracle;UID=" & text1.Text & " ;PWD=" & text2.Text & ";"
Set gdb_data = OpenDatabase("", False, False, gstr_connect$)

//The moment I finish stepping through the above step
//set gdb_data=......., my oracle logon screen will invoke
//There is no way I can reach the error handler unless I click //cancel at the oracle logon screen. It's only then I got the error number 3059 and message "Operation canceled by user"      
     
ErrorHandler:
For iCnt = 0 To Errors.Count - 1
MsgBox Errors(iCnt).Number
MsgBox Errors(iCnt).Description
Next iCnt
     
End Sub
0
 
LVL 7

Accepted Solution

by:
tward earned 100 total points
ID: 1461853
Use Oracle Objects for OLE and you can use the following Module, if you have any problems with it just let me know:

  Option Explicit

  ' Oracle setup '
  Public OraSession As Object
  Public oraDatabase As Object

  ' Oracle Connect String (Used in DatabaseOpen) '
  Public CONNECT$

  ' Oracle Database String (Used in DatabaseOpen) '
  Public DATABASE$

  ' Oracle SQL String (Used in OpenDynaset) '
  Public SQL$
 
  Public gTimesTried As Integer
 
  Public DynaSetOpenError As Boolean

'''''''''''''''''''''''''''''''''''''''''''''''''''
'    Function:  DatabaseOpen(CONNECT$,DATABASE$)  '
'                                                 '
' Description:  Opens the Database Passed to it   '
'               in DATABASE using the             '
'               NAME/PASSWORD in CONNECT.         '
'                                                 '
'       Input:   CONNECT$ - "NAME/PASSWORD"       '
'               DATABASE$ - "X:ORA_DB_SRV:ORCL"   '
'                           "PROD"                '
'                                                 '
'      Output:  Message Box on Error, otherwise   '
'               an Open Database Object.          '
'                                                 '
'     Returns:   True = Database was Opened.      '
'               False = Database Open Failed.     '
'                                                 '
'''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function DatabaseOpen(ByVal CONNECT$, ByVal DATABASE$) As Boolean
 
  DatabaseOpen = True
 
  ' Setup The Oracle Session '
  On Error Resume Next
  Set OraSession = CreateObject("oracleinprocserver.xorasession")
  If Err.Number <> 0 Then
   
    MsgBox "Oracle Error:  " & Err.Description, vbOKOnly + vbCritical, "Database Session Error..."
    DatabaseOpen = False
    On Error GoTo 0
    Exit Function
   
  End If
 
  ' Setup The Oracle Connection '
  On Error Resume Next
  Set oraDatabase = OraSession.dbopendatabase(DATABASE$, CONNECT$, 0&)
 
  If Err.Number <> 0 Then
   
    MsgBox "Oracle Error:  " & Err.Description, vbOKOnly + vbCritical, "Database Connection Error..."
    DatabaseOpen = False
   
  End If
 
  On Error GoTo 0
 
End Function


'''''''''''''''''''''''''''''''''''''''''''''''''''
'    Function:  DatabaseClose()                   '
'                                                 '
' Description:  Closes an Open Oracle Database.   '
'               Database should have been opened  '
'               using OpenDatabase.               '
'                                                 '
'       Input:  NONE.                             '
'                                                 '
'      Output:  Clears OraSession and oraDatabase.'
'                                                 '
'     Returns:  NONE.                             '
'                                                 '
'''''''''''''''''''''''''''''''''''''''''''''''''''
Public Sub DatabaseClose()
 
  Set OraSession = Nothing
  Set oraDatabase = Nothing

End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''''
'    Function:  OpenDynaset(SQL$)                 '
'                                                 '
' Description:  Opens a Dynaset using the SQL$    '
'               SQL Statement passed to it.       '
'                                                 '
'       Input:  SQL$ - Any valid SQL Statement.   '
'                                                 '
'      Output:  An Open Dynaset, Use CloseDynaset '
'               to Close Dynasets.                '
'                                                 '
'     Returns:  The OpenDynaset Object.           '
'                                                 '
'''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function OpenDynaSet(ByVal SQL$) As Object
 
  On Error Resume Next
 
  DynaSetOpenError = False
 
  Set OpenDynaSet = oraDatabase.DBCREATEDYNASET(SQL$, 0&)
 
  If Err.Number <> 0 Then
 
    Call MsgBox("Error #" & Err.Number & ":  " & Err.Description, vbCritical + vbOKOnly, "SQL Query Error.....")
    DynaSetOpenError = True
   
  End If
  On Error GoTo 0
 
End Function

'''''''''''''''''''''''''''''''''''''''''''''''''''
'    Function:  CloseDynaSet()                    '
'                                                 '
' Description:  Closes the Open Dynaset.          '
'                                                 '
'       Input:  None.                             '
'                                                 '
'      Output:  None.                             '
'                                                 '
'     Returns:  Nothing into the DynaSet Object.  '
'                                                 '
'''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function CloseDynaSet() As Object

  Set CloseDynaSet = Nothing

End Function


0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…

708 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

12 Experts available now in Live!

Get 1:1 Help Now