Connecting to MySQL database- Run-time error 3001
Hi,
I'm developing a VB6 application connecting to a MySQL database. I'm getting run-time error 3001: arguments are of the wrong type, are out of an acceptable range, or are in conflict of each other.
I'm using the ODBC driver from MySQL. I would appreciate if anyone could spot where I'm going wrong as this is the first time I'm using VB6 to connect to a DB.
Private Sub Command1_Click()
Dim dbuser As String, password As String, dbname As String, hostname As String
Dim sql As String
Open App.Path & "\settings.txt" For Input As #1
Line Input #1, dbuser
Line Input #1, password
Line Input #1, dbname
Line Input #1, hostname
Close #1
Set conn = New ADODB.Connection
Set login = New ADODB.Recordset
conn.Open "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=" & hostname & ";" & "DATABASE=" & dbname & ";" & "UID=" & dbuser & ";" & "PWD=" & password & ";"
sql = "SELECT * FROM tblUser WHERE user=& txtUsername.Text & AND password=& txtPassword.Text;"
login.Open conn, sql
End Sub
Cheers,
bsewell
Junior Poster in Training
56 posts since Sep 2009
Reputation Points: 10
Solved Threads: 1
Where is the name??? When you create an ODBC DSN you give it a name. I see where you supply which driver but not its name.
Then, since you are using ADO, you could if you wanted, use a DSN Less connection string... see http://www.connectionstring.com
Good Luck
vb5prgrmr
Posting Virtuoso
1,912 posts since Mar 2009
Reputation Points: 156
Solved Threads: 296
Your select statement is incorrect. Try the following -
'Your Sql Statement
sql = "SELECT * FROM tblUser WHERE user=& txtUsername.Text & AND password=& txtPassword.Text;"
'Try
sql = "SELECT * FROM tblUser WHERE user=" & "'" & txtUsername.Text & "'" & " AND password=" & "'" & txtPassword.Text & "'" & ";"
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350