CrazyEngineers
  • find bug in this vb6.0 code ?

    safwan

    Member

    Updated: Oct 26, 2024
    Views: 2.8K
    I have created a login form for connecting vb6 to oracle .The following code I have wrote in click event of button login.

    Private Sub cmdlogin_Click()
    Dim con As New ADODB.Connection
    Dim constr As String
    Dim username As String
    Dim pwd As String
    username = Trim(txtusrname.Text)
    pwd = Trim(txtpwd.Text)
    constr = "provider = MSDAORA;user id = username; password = pwd;"
    con.Open constr
    If con.State = adStateOpen Then
     MsgBox ("oracle connected")
     Else
       MsgBox ("oracle not connected")
     End If
    End Sub
    Here , we are taking username and pwd from user. when I run program I get error saying ""username or pwd invalid. but when I alter the code and use below code I get correct output why ? what is the reason ?

    Private Sub cmdlogin_Click()
     Dim con As New ADODB.Connection
     Dim constr As String
    
    
     constr = "provider = MSDAORA;user id = system; password = system;"
     con.Open constr
      If con.State = adStateOpen Then
            MsgBox ("oracle connected")
      Else
            MsgBox ("oracle not connected")
      End If
    
    End Sub
    
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • safwan

    MemberNov 11, 2009

    Any buddy ?? Please solve this .
    Are you sure? This action cannot be undone.
    Cancel
  • sookie

    MemberNov 11, 2009

    Hi safwan,

    I guess the problem is in first case, you are trying to use 'username' and 'pwd' as user-defined variables while in second case 'system' is both username and passowrd for connecting to the database. So check if your first case work if I use it like following

    constr = "provider = MSDAORA;user id = "& username &"; password = "& pwd &";"


    I assumed that whatever username and password user enters from UI is valid one. 😀
    Are you sure? This action cannot be undone.
    Cancel
  • safwan

    MemberNov 12, 2009

    Hay sokie I got your point and I tried it also but its not working .Its giving same errore .
    Are you sure? This action cannot be undone.
    Cancel
  • sookie

    MemberNov 12, 2009

    safwan
    Hay sokie I got your point and I tried it also but its not working .Its giving same errore .
    What username and password , you are entering in your textboxes?

    Just a request for helping us in tracing the error- Can you display the value user is getting in 'username' and 'pwd' variable ? Try adding msgboxes for it and display the value of 'username' and 'pwd' you are getting in program. Also try to display entire 'constr' string in your program. What value it displays ?
    Are you sure? This action cannot be undone.
    Cancel
  • safwan

    MemberNov 12, 2009

    Sokii I enter the username = system and password=system .
    Both are set by me for oracle 10 g. in my pc.
    Sokii when I entered the following code .

    Private Sub cmdlogin_Click()
    Dim con As New ADODB.Connection
    Dim constr As String
    Dim username As String
    Dim pwd As String
    username = Trim(txtusrname.Text)
    pwd = Trim(txtpwd.Text)
    constr = "provider = MSDAORA;user id = Trim(txtusrname.Text); password = Trim(txtpwd.Text);"
    MsgBox ("you have entered" + " " + "username as " + username + " " + "password as" + " "+ pwd)
    MsgBox (constr)
    con.Open constr
    If con.State = adStateOpen Then
     MsgBox ("oracle connected")
     
     Else
     
       MsgBox ("oracle not connected")
       MsgBox (pwd + userid)
       
     End If
    End Sub
    
    when I enter user name as "system" ( not in double quotes) and same "system" in password text box I get first message box as :
    "you have entered username as system password as system"

    In second messagebox I get following message :

    " provider = MSDAORA;user id = Trim(txtusrname.Text); password = Trim(txtpwd.Text)"

    Now what should I do .😡 😔
    Are you sure? This action cannot be undone.
    Cancel
  • Guttu

    MemberNov 12, 2009

    safwan
    I have created a login form for connecting vb6 to oracle .The following code I have wrote in click event of button login.

    Private Sub cmdlogin_Click()
    Dim con As New ADODB.Connection
    Dim constr As String
    Dim username As String
    Dim pwd As String
    username = Trim(txtusrname.Text)
    pwd = Trim(txtpwd.Text)
    constr = "provider = MSDAORA;user id = username; password = pwd;"
    con.Open constr
    If con.State = adStateOpen Then
     MsgBox ("oracle connected")
     Else
       MsgBox ("oracle not connected")
     End If
    End Sub
    Here , we are taking username and pwd from user. when I run program I get error saying ""username or pwd invalid. but when I alter the code and use below code I get correct output why ? what is the reason ?

    Private Sub cmdlogin_Click()
     Dim con As New ADODB.Connection
     Dim constr As String
    
    
     constr = "provider = MSDAORA;user id = system; password = system;"
     con.Open constr
      If con.State = adStateOpen Then
            MsgBox ("oracle connected")
      Else
            MsgBox ("oracle not connected")
      End If
    
    End Sub
    
    Ummmmmmmmmm..
    replace
    username = Trim([B]txtusrname[/B].Text)
    with


    
    
    username = Trim([B]txtusername[/B].Text)
    Are you sure? This action cannot be undone.
    Cancel
  • sookie

    MemberNov 13, 2009

    @safwan: Can you please try to change red coloured line in your following code with my line shown in first post?

    Private Sub cmdlogin_Click()
    Dim con As New ADODB.Connection
    Dim constr As String
    Dim username As String
    Dim pwd As String
    username = Trim(txtusrname.Text)
    pwd = Trim(txtpwd.Text)
    [COLOR="Red"]constr = "provider = MSDAORA;user id = Trim(txtusrname.Text); password = Trim(txtpwd.Text);"
    [/COLOR]MsgBox ("you have entered" + " " + "username as " + username + " " + "password as" + " "+ pwd)
    MsgBox (constr)
    con.Open constr
    If con.State = adStateOpen Then
     MsgBox ("oracle connected")
     
     Else
     
       MsgBox ("oracle not connected")
       MsgBox (pwd + userid)
       
     End If
    End Sub
    
    Replace red colour line with following
    constr = "provider = MSDAORA;user id = "& username &"; password = "& pwd &";"
    I couldn't understand why you are using Trim(txtusrname.Text) and Trim(txtpwd.Text) instead of using 'username' and 'pwd' variable. If you are not using these 'username' and 'pwd' variables then why saving textboxes value in them? I am not getting why you are putting dumb logics even if we are telling you how to correct it. Creating unnecessarily bugs for yourself and discussion for rest of us. 😕
    Are you sure? This action cannot be undone.
    Cancel
  • safwan

    MemberNov 13, 2009

    sookie
    @safwan: Can you please try to change red coloured line in your following code with my line shown in first post?

    Private Sub cmdlogin_Click()
    Dim con As New ADODB.Connection
    Dim constr As String
    Dim username As String
    Dim pwd As String
    username = Trim(txtusrname.Text)
    pwd = Trim(txtpwd.Text)
    [COLOR=Red]constr = "provider = MSDAORA;user id = Trim(txtusrname.Text); password = Trim(txtpwd.Text);"
    [/COLOR]MsgBox ("you have entered" + " " + "username as " + username + " " + "password as" + " "+ pwd)
    MsgBox (constr)
    con.Open constr
    If con.State = adStateOpen Then
     MsgBox ("oracle connected")
     
     Else
     
       MsgBox ("oracle not connected")
       MsgBox (pwd + userid)
       
     End If
    End Sub
    
    Replace red colour line with following

    I couldn't understand why you are using Trim(txtusrname.Text) and Trim(txtpwd.Text) instead of using 'username' and 'pwd' variable. If you are not using these 'username' and 'pwd' variables then why saving textboxes value in them? I am not getting why you are putting dumb logics even if we are telling you how to correct it. Creating unnecessarily bugs for yourself and discussion for rest of us. 😕
    Sokii First of all I thank you for your Help .I am still student So I may commit mistakes for coding and logic. ( As I am not a professional).when I used your direction given in above quote I but its giving following message in first message I get same message second message box I get message as " False" title name as VBoracon(which is my project name) and third message box I get is
    "[Microsoft][ODBC Driver Manager] Data source Name not found and no defult driver found" .

    I used (txtusrname.text ) because I want to get user names entered by user .
    Are you sure? This action cannot be undone.
    Cancel
  • gsxraddict

    MemberNov 19, 2009

    Private Sub cmdlogin_Click()
    Dim con As New ADODB.Connection
    Dim constr As String
    Dim username As String
    Dim pwd As String
    username = Trim(txtusrname.Text)
    pwd = Trim(txtpwd.Text)
    constr = "provider = MSDAORA;user id = " & username & "; password = " & pwd & ";"
    MsgBox ("you have entered username as " & username & " password as " & pwd & ".")
    MsgBox (constr)
    con.Open constr
    If con.State = adStateOpen Then
    MsgBox ("oracle connected")

    Else

    MsgBox ("oracle not connected")
    MsgBox (pwd & " " & userid)

    End If
    End Sub


    Use the & when connecting strings.
    Are you sure? This action cannot be undone.
    Cancel
  • safwan

    MemberNov 20, 2009

    Thanks GXRADDICT Your cod is working well Actually the & was missing so I did it and it worked. AThanks sokii and Guttu for your help.
    Are you sure? This action cannot be undone.
    Cancel
  • sookie

    MemberNov 20, 2009

    safwan
    Thanks GXRADDICT Your cod is working well Actually the & was missing so I did it and it worked.
    Did I tell something in FRENCH ? 😐
    Are you sure? This action cannot be undone.
    Cancel
  • safwan

    MemberNov 21, 2009

    sookie
    Did I tell something in FRENCH ? 😐
    I am sorry !! but 😲 But when I used your code It was not working and giving error so I thought its wrong but after posting my above post I got realized that it is same as what you have told . 😔
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register