Results 1 to 11 of 11

Thread: MySQL Connection String Question[RESOLVED]

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Posts
    104

    Resolved MySQL Connection String Question[RESOLVED]

    Is there any reason at all that this code shouldnt work for a connection string? I cannot seem to get my web app to connect to a mySQL server.

    VB Code:
    1. Option Explicit On
    2. Public Class WebForm1
    3.     Inherits System.Web.UI.Page
    4.     Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    5.     Protected WithEvents Label2 As System.Web.UI.WebControls.Label
    6.     Protected WithEvents txtUsername As System.Web.UI.WebControls.TextBox
    7.     Protected WithEvents txtPassword As System.Web.UI.WebControls.TextBox
    8.     Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    9.     Protected WithEvents Button2 As System.Web.UI.WebControls.Button
    10.     Dim mySQL As ADODB.Connection
    11.     Public Username As String
    12.     Public perms As String
    13.  
    14. #Region " Web Form Designer Generated Code "
    15.  
    16.     'This call is required by the Web Form Designer.
    17.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    18.  
    19.     End Sub
    20.  
    21.     Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    22.         'CODEGEN: This method call is required by the Web Form Designer
    23.         'Do not modify it using the code editor.
    24.         InitializeComponent()
    25.     End Sub
    26.  
    27. #End Region
    28.  
    29.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    30.  
    31.         mySQL = New ADODB.Connection()
    32.         mySQL.ConnectionString = ("Provider=MSDASQL;Driver={MySQL ODBC 3.51 Driver};Database=workorder;Server=IP;UID=user;PWD=password;OPTION=147458")
    33.         mySQL.Open()
    34.     End Sub
    35.  
    36.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    37.         Response.Redirect("index.htm")
    38.     End Sub
    39.     Public Function UserCheck(ByVal strUserName As String, ByVal strPassword As String) As Boolean
    40.  
    41.         Dim rs As New ADODB.Recordset()
    42.  
    43.         rs.Open("SELECT username, password FROM users WHERE username = '" & strUserName & "'", mySQL, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockReadOnly)
    44.  
    45.         If Not rs.EOF Then
    46.             If rs.Fields("password") Is strPassword Then
    47.                 rs.Close()
    48.                 rs = Nothing
    49.                 UserCheck = True
    50.                 Exit Function
    51.             Else
    52.                 rs.Close()
    53.                 rs = Nothing
    54.                 UserCheck = False
    55.                 Exit Function
    56.  
    57.             End If
    58.         Else
    59.             rs.Close()
    60.             rs = Nothing
    61.             UserCheck = False
    62.             Exit Function
    63.         End If
    64.  
    65.     End Function
    66.  
    67.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    68.         Dim mrs As ADODB.Recordset
    69.         Dim permQuery As String
    70.         Dim writeQuery As String
    71.  
    72.         Username = txtUsername.Text
    73.  
    74.         permQuery = "SELECT permissions FROM users WHERE username = '" & Username & "'"
    75.  
    76.         mrs = New ADODB.Recordset()
    77.         mrs.Open(permQuery, mySQL, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockReadOnly)
    78.         If Not mrs.EOF Then
    79.             perms = mrs.Fields("permissions").Value
    80.             mrs.Close()
    81.             mrs = Nothing
    82.         End If
    83.         writeQuery = "INSERT INTO verify(username, permissions) VALUES ('" & Username & "', '" & perms & "')"
    84.         If UserCheck(txtUsername.Text, txtPassword.Text) = True Then
    85.             mySQL.Execute(writeQuery)
    86.             mySQL.Close()
    87.             mySQL = Nothing
    88.             Response.Redirect("menu.aspx")
    89.  
    90.         Else
    91.             Response.Redirect("Login.aspx")
    92.  
    93.  
    94.         End If
    95.     End Sub
    96.  
    97.  
    98. End Class
    New to ASP.NET by the way. Came over from VB6.0 and trying to migrate an application to the web. Any help is appreciated.
    Last edited by Polariss; Jul 6th, 2005 at 02:07 PM. Reason: [RESOLVED]

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