find bug in this vb6.0 code ?
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 SubHere , 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
Replies
-
safwanAny buddy ?? Please solve this .
-
sookieHi 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. ๐ -
safwanHay sokie I got your point and I tried it also but its not working .Its giving same errore .
-
sookie
What username and password , you are entering in your textboxes?safwanHay sokie I got your point and I tried it also but its not working .Its giving same errore .
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 ? -
safwanSokii 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 .๐ก ๐ -
Guttu
Ummmmmmmmmm..safwanI 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
replace
username = Trim([B]txtusrname[/B].Text)
with
username = Trim([B]txtusername[/B].Text)
-
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
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. ๐ -
safwan
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 issookie@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. ๐
"[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 . -
gsxraddictPrivate 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. -
safwanThanks GXRADDICT Your cod is working well Actually the & was missing so I did it and it worked. AThanks sokii and Guttu for your help.
-
sookie
Did I tell something in FRENCH ? ๐safwanThanks GXRADDICT Your cod is working well Actually the & was missing so I did it and it worked. -
safwan
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 . ๐sookieDid I tell something in FRENCH ? ๐
You are reading an archived discussion.
Related Posts
If you're looking to monitor your network and Internet speed, track overall bandwidth usage, and get several other very useful utilities, you'd do well to download the free NetWorx. With...
In BitTorrent protocols , what is meant by 'seeding and leeching'. Can anyone give me the proper definition of this two terms.
There were some queries a while back about liquids and the Venturi effect; why pressure is lower when a fluid is compressed through a smaller aperture, etc.
This is easier...
Its official now. Google has launched their own programming language called 'Go'. Go is said to have taken up all the goodies from C++ & Python. As expected, Go is...
Here's official video from Google:
[youtube]wwoWei-GAPo[/youtube]