CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Join Date
    Nov 2011
    Location
    England
    Posts
    17

    Unknown Error | Can Anyone Help?

    Not doing it the way that the error was giving me anymore, check the bottom of this thread to see what I'm doing now, as I still need help!
    Last edited by BreShiE; November 18th, 2011 at 07:38 AM.

  2. #2
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Unknown Error | Can Anyone Help?

    It seems your connection string does not conatin a valid reference to your database.
    Please show the code or method respectively you use to open the db connection.

  3. #3
    Join Date
    Nov 2011
    Location
    England
    Posts
    17

    Re: Unknown Error | Can Anyone Help?

    Sure, here you go:

    Code:
    Dim strDatabaseName As String
    Dim strDBCursorType As String
    Dim strDBLockType As String
    Dim strDBOptions As String
    Dim rs As ADODB.Recordset
    Dim cn As ADODB.Connection
    
    Private Sub Command1_Click()
    On Error GoTo Command1_Click_Error
    Dim b As Long
    strDBCursorType = adOpenDynamic  'CursorType
    strDBLockType = adLockOptimistic   'LockType
    strDBOptions = adCmdText         'Options
    
    Set cn = New ADODB.Connection
    Me.MousePointer = 11
    
    cn.Open ConnectString()
        
        With cn
            .CommandTimeout = 0
            .CursorLocation = adUseClient
        End With
    
        Set rs = New ADODB.Recordset       'Creates record set
    
        strSQL = "<Your SQL Here>"
        
        rs.Open strSQL, cn, strDBCursorType, strDBLockType, strDBOptions
        
    
    If rs.EOF Then
       GoTo ExitSub
    Else
        For b = 1 To rs.RecordCount
        '<do whatever you need to do with the data here>
        Next b
    End If
        
    ExitSub:
    
    rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
    
    On Error GoTo 0
    Exit Sub
    
    Command1_Click_Error:
        MsgBox "Error " & Err.Number & " (" & Err.Description & ")"
        
        Form2.Show
        Form1.Hide
    End Sub
    
    Private Function ConnectString() As String
    Dim strServerName As String
    Dim strDatabaseName As String
    Dim strUserName As String
    Dim strPassword As String
    
        'Change to IP Address if not on local machine
        'Make sure that you give permission to log into the
        'server from this address
        'See Adding New User Accounts to MySQL
        'Make sure that you d/l and install the MySQL Connector/ODBC 3.51 Driver
    
    strServerName = "localhost"
    strDatabaseName = "mydbname"
    strUserName = "mydbuser"
    strPassword = "mydbpass"
    
    ConnectString = "DRIVER={MySQL ODBC 3.51 Driver};" & _
                    "SERVER=" & strServerName & _
                    ";DATABASE=" & strDatabaseName & ";" & _
                    "USER=" & strUserName & _
                    ";PASSWORD=" & strPassword & _
                    ";OPTION=3;"
    
    End Function
    
    Private Sub Command2_Click()
    MsgBox "Please login with your XBLForums.net account, this is just a security feature as I do not want anyone using this who hasn't signed up to the site.", vbInformation, "Info"
    End Sub

    I've just noticed something, should I change the "localhost" to the IP of my website?

  4. #4
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Unknown Error | Can Anyone Help?

    Not to your IP address but to the address of the actual server.

    Also you ought to enter proper strings to strDatabaseName, strUserName and strPassword.

  5. #5
    Join Date
    Nov 2011
    Location
    England
    Posts
    17

    Re: Unknown Error | Can Anyone Help?

    Quote Originally Posted by WoF View Post
    Not to your IP address but to the address of the actual server.

    Also you ought to enter proper strings to strDatabaseName, strUserName and strPassword.
    I'll point it towards my servers IP now. Also how do you mean "proper strings"?

    Just a quick question, with that code there, will that make it so if the username/password is incorrect, it wont show?

    If not do you think you could help me make a login form which does that?


    EDIT: Pointed it to my servers IP, still doesn't work. :-/
    Last edited by BreShiE; November 17th, 2011 at 12:40 PM.

  6. #6
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Unknown Error | Can Anyone Help?

    Seems to me, that your website's IP address may change, at which point the app wouldn't be able to connect in that manner anyway.

    Why not just put a script on your website which returns a specific string to denote a valid user, then simply use CSocket or Winsock to access the page, passing it a query with the user name and password?

    If the user has been validated, you can then enable the appropriate menu items, buttons, etc. Additional checks could be employed if you feel your app may be a target for hacking.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  7. #7
    Join Date
    Nov 2011
    Location
    England
    Posts
    17

    Re: Unknown Error | Can Anyone Help?

    Quote Originally Posted by WizBang View Post
    Seems to me, that your website's IP address may change, at which point the app wouldn't be able to connect in that manner anyway.

    Why not just put a script on your website which returns a specific string to denote a valid user, then simply use CSocket or Winsock to access the page, passing it a query with the user name and password?

    If the user has been validated, you can then enable the appropriate menu items, buttons, etc. Additional checks could be employed if you feel your app may be a target for hacking.
    Suprisingly, I was already doing this, I've got the PHP side covered. Just not sure how I'd actually connect the program to the page, I know I'd have to add in the Winsock 6.0 Control but I don't know what to put in the code.

    If you can help me out I'd be forever grateful, and will give you credits in the "Info".

  8. #8
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Unknown Error | Can Anyone Help?

    Quote Originally Posted by BreShiE View Post
    Suprisingly, I was already doing this, I've got the PHP side covered. Just not sure how I'd actually connect the program to the page, I know I'd have to add in the Winsock 6.0 Control but I don't know what to put in the code.

    If you can help me out I'd be forever grateful, and will give you credits in the "Info".
    Sure, I've posted example code for the winsock control, to do the very thing we're talking about. A search should locate them. The advanced search allows you to search for posts by a specific member. I also uploaded an example showing how to send a GET query.

    Here is an example showing how to send a GET query:
    http://www.codeguru.com/forum/showth...433#post996433

    Here is an example showing how to send a POST query:
    http://www.codeguru.com/forum/showth...013#post701796
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  9. #9
    Join Date
    Nov 2011
    Location
    England
    Posts
    17

    Re: Unknown Error | Can Anyone Help?

    Okay so I used the code:

    Code:
    Private Sub Command1_Click()
    
    Winsock1.RemoteHost = "http://xblforums.net/vb/login.php"
    Winsock1.RemotePort = 80
    FormData = "A=test&username=guest"
    WebPage = "POST /yourpage.asp HTTP/1.0" & vbCrLf
    WebPage = WebPage & "Content-Type: application/x-www-form-urlencoded" & vbCrLf
    WebPage = WebPage & "Accept-Encoding: gzip, deflate" & vbCrLf
    WebPage = WebPage & "Host: " & Winsock1.RemoteHost & vbCrLf
    WebPage = WebPage & "Connection: Keep-Alive" & vbCrLf
    WebPage = WebPage & "Content-Length: " & CStr(Len(FormData)) & vbCrLf & vbCrLf
    WebPage = WebPage & FormData & vbCrLf & vbCrLf
    Winsock1.Connect
    End Sub
    
    Private Sub Winsock1_Connect()
    Winsock1.SendData WebPage
    End Sub
    So how would I make it so you have to have an account on my site to login?

    Also do I have to have the login page on my site for it to post the data to?

  10. #10
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Unknown Error | Can Anyone Help?

    Quote Originally Posted by BreShiE View Post
    So how would I make it so you have to have an account on my site to login?
    Set the FormData string to the name and password (along with any other pertinent data you want) like:
    Code:
    FormData = "user=" & YourUsernameString & "&pass=" & YourPasswordString
    Then, the page would return a string denoting whether or not the user and password combination is valid. The winsock control will receive the string, and your program would use that to determine if the user should be given full access to all features and functions.
    Also do I have to have the login page on my site for it to post the data to?
    Yes, although it doesn't need to be a page that visitors would know about, if you do not want it to be. The page only needs to return a string dependent on the validity of the user/pass combination. So a simple "yes" or "no" would suffice, or you can return whatever data you want. If you'll be allowing site visitors to login to the site, that can be a separate page, or you could use the same page the program would use, accept the program could pass a different set of parameters, so the page would know it was the program and not a regular site visitor.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  11. #11
    Join Date
    Nov 2011
    Location
    England
    Posts
    17

    Re: Unknown Error | Can Anyone Help?

    Quote Originally Posted by WizBang View Post
    Yes, although it doesn't need to be a page that visitors would know about, if you do not want it to be. The page only needs to return a string dependent on the validity of the user/pass combination. So a simple "yes" or "no" would suffice, or you can return whatever data you want. If you'll be allowing site visitors to login to the site, that can be a separate page, or you could use the same page the program would use, accept the program could pass a different set of parameters, so the page would know it was the program and not a regular site visitor.
    Sorry, I worded that wrong. I had just woke up when I posted that.

    What I meant:

    Would the page have to be an actual login page, rather than the PHP just connecting to the database? Would I have to create two textboxes and the submit button?

    Also, for the FormData, would this work?:

    Code:
    FormData = "user=" & Text1.Text & "&pass=" & Text2.Text

    EDIT: Here's the PHP script I'm using by the way:

    PHP Code:
    <?php

    /**
     * @author priv0te95
     * @copyright 2010
     */
     
    $db_host "localhost";            
    $db_user "tfgyh";
    $db_pass "tfgyhuj";        
    $db_name "rftgyh";        
    //
    $tb_user "mybb_users";        
    //
    $sqlConnect mysql_connect($db_host$db_user$db_pass);
    if(!
    $sqlConnect)
        DIE();
    mysql_select_db($db_name$sqlConnect);
    // 
    if($_SERVER['HTTP_USER_AGENT'] != $u_agent)
        DIE();
        
    $vbUsername mysql_real_escape_string(stripslashes($_REQUEST['vbUsername']));
    $vbPassword mysql_real_escape_string(stripslashes($_REQUEST['vbPassword']));

    $vbResults mysql_query("SELECT * FROM `{$tb_user}`");
    if(
    $vbResults){
        while(
    $vbData mysql_fetch_array($vbResults)){
            if((
    $vbData["username"] == $vbUsername) && ($vbData["password"] == $vbPassword) && ($vbData["active"] == "YES")){
                print(
    "USER_ACCEPTED");
            }
        }
    }

    ?>
    Last edited by BreShiE; November 19th, 2011 at 11:49 AM.

  12. #12
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Unknown Error | Can Anyone Help?

    Quote Originally Posted by BreShiE View Post
    Sorry, I worded that wrong. I had just woke up when I posted that.

    What I meant:

    Would the page have to be an actual login page, rather than the PHP just connecting to the database? Would I have to create two textboxes and the submit button?
    No, there doesn't need to be any actual form. Simply the script which accepts form data, tests the login details against the database, and returns a string indicating validity.
    Also, for the FormData, would this work?:

    Code:
    FormData = "user=" & Text1.Text & "&pass=" & Text2.Text
    Yes, that will do, although certain characters might interfere with or compromise the validation process. So I'd recommend doing some filtering on the strings entered by the user before submitting it. For instance, disallowing quote marks, ampersands, question marks, etc.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  13. #13
    Join Date
    Nov 2011
    Location
    England
    Posts
    17

    Re: Unknown Error | Can Anyone Help?

    I've just tried that, and it came up with a syntax error. I can't seem to see what's wrong.

    Also how would I use a IF Statement to check if it has succeeded or not?

  14. #14
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Unknown Error | Can Anyone Help?

    Post what you've got in all the winsock events.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  15. #15
    Join Date
    Nov 2011
    Location
    England
    Posts
    17

    Re: Unknown Error | Can Anyone Help?

    The Whole Code So Far:

    Code:
    Private Sub Command1_Click()
    
    Winsock1.RemoteHost = "http://xblforums.net/vb/login.php"
    Winsock1.RemotePort = 80
    FormData = "user=" & Text1.Text & "&pass=" Text2.Text
    WebPage = "POST /yourpage.asp HTTP/1.0" & vbCrLf
    WebPage = WebPage & "Content-Type: application/x-www-form-urlencoded" & vbCrLf
    WebPage = WebPage & "Accept-Encoding: gzip, deflate" & vbCrLf
    WebPage = WebPage & "Host: " & Winsock1.RemoteHost & vbCrLf
    WebPage = WebPage & "Connection: Keep-Alive" & vbCrLf
    WebPage = WebPage & "Content-Length: " & CStr(Len(FormData)) & vbCrLf & vbCrLf
    WebPage = WebPage & FormData & vbCrLf & vbCrLf
    Winsock1.Connect
    End Sub
    
    Private Sub Winsock1_Connect()
    Winsock1.SendData WebPage
    End Sub
    
    Private Sub Command2_Click()
    MsgBox "Please login with your XBLForums.net account, this is just a security feature as I do not want anyone using this who hasn't signed up to the site.", vbInformation, "Info"
    End Sub

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured