954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

help with MySQL

I hope someone can helkp me. This is driving me nuts. I have the following code that produces this error " Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'selfmadeBrowser'."

The entire code is as follows
(please note, this script came DIRECTLY off of http://www.expertrating.com/courseware/DotNetCourse/DotNet-ASP.Net-4-3.asp ,

I also am able to cnnect to this same Mysql database through other pages, but I am only able to connect, I can't edit or delete, stangely enough I can insert, but I have the same connection for all of them. I just need to know why this page gives me the user login failed, when i use the same user/password for the other pages and they work - partially....

<%@ Page language="VB" Debug=true %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %> 
<html>
<head>
 <title>Untitled</title>
</head>
<body>

<% 
Dim dbConn As SqlConnection 
Dim sqlComm As SqlCommand 
Dim dbReader As SqlDataReader 
dbConn = New SqlConnection( "Server=localhost;uid=selfmadeBrowser;pwd=bpass;database=cacdb" ) 
dbConn.Open() 
sqlComm = New SqlCommand( "Select * From users", dbConn ) 
dbReader = sqlComm.ExecuteReader() 
While dbReader.Read() 
Response.Write(“<li>" ) 
Response.Write(dbReader( "Name" ) ) 
End While 
dbReader.Close() 
dbConn.Close() 
%> 
 
</body>
</html>


Basically, the end result is I need to be able to connect, edit, update, delete and insert into a MySQL database.

Also, it might be worth it to mention, I am not using Visual Developer 2005 YET, i am trying to learn the hand coding method first.

PLease, any help is GREATLY appreciated....

ps, this is the code for the MY SQL that is allowiong me to insert, so I can prove the username and pasword is the same....

Sub btnInsert_Click(Sender As Object, E As CommandEventArgs)
 
        
 Dim ConnectionString As String = "DRIVER={MySQL ODBC 3.51 Driver};" _ 
& "SERVER=localhost;" _ 
& "DATABASE=cacdb;" _ 
& "UID=selfmadeBrowser;" _ 
& "PWD=bpass;" _ 
& "OPTION=" & 1 + 2 + 8 + 32 + 2048 + 16384 
Dim CommandText As String = "Insert Into addresses (FirstName, LastName, email, birthday, address, city, state, zip, cellphone) " _
  & " values ('" & fname.Text & "','" & lname.Text & "','" & email.Text & "','" & birthday.Text & "','" & address.Text & "','" & city.Text & "','" & state.Text & "','" & zip.Text & "','" & cellphone.Text & "')"
Dim myConnection As New OdbcConnection(ConnectionString) 
Dim myCommand As New ODBCCommand(CommandText, myConnection) 
myConnection.Open() 
dgEmps.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection) 
dgEmps.DataBind() 
   
End Sub
someoneelse
Newbie Poster
14 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

You're probably getting an error because you're trying to connect to a MySQL Server using the SQL providers.

Try downloading the MySQL Connector from mySql.com: http://dev.mysql.com/downloads/connector/net/5.0.html

I think all you need to do is replace every instance of SQL with MySql in your code, but check the documentation to be sure: http://dev.mysql.com/doc/refman/5.0/en/connector-net.html

Cheers,
Blackred.

Blackred
Newbie Poster
10 posts since Apr 2007
Reputation Points: 10
Solved Threads: 2
 

Blackred is right.

dbConn = New SqlConnection( "Server=localhost;uid=selfmadeBrowser;pwd=bpass;database=cacdb" )

Here you are using ADO and Microsoft Sql server specific objects you can't use these classes to connect to MySql

Dim myConnection As New OdbcConnection(ConnectionString)

here where it is working you are using ODBC instead of ADO and these objects can connect to MySql using the MySql ODBC Driver.

hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You