Connector/Net parameter markers bug?
Posted by: Chris Sinclair
Date: December 07, 2006 05:05AM

I've been trying MySQL Connector/Net 5.0.2 and I've found something.

The following code works with 5.0.1:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

dbF = New MySql.Data.MySqlClient.MySqlClientFactory
strConnectionString = "Database=membership;Data Source=localhost;User Id=user;Password=password"

MsgBox(GetUserNameByEmail(""))

End Sub

Public Function GetUserNameByEmail(ByVal email As String) As String

Dim conn As DbConnection = dbF.CreateConnection()
conn.ConnectionString = strConnectionString

Dim cmd As DbCommand = dbF.CreateCommand()
cmd.CommandText = "MEM_GetUserNameByEmail"
cmd.Connection = conn

cmd.CommandType = CommandType.StoredProcedure

Dim username As String = ""

AddParamToCmd(cmd, "?iEmail", DbType.String, 128, ParameterDirection.Input, "")
AddParamToCmd(cmd, "?iApplicationName", DbType.String, 255, ParameterDirection.Input, "")

AddParamToCmd(cmd, "RETURN_VALUE", DbType.String, 255, ParameterDirection.ReturnValue, username)

conn.Open()
cmd.ExecuteNonQuery()
conn.Close()

username = cmd.Parameters("RETURN_VALUE").Value

Return username
End Function

Protected Sub AddParamToCmd(ByVal sqlCmd As DbCommand, ByVal paramId As String, ByVal sqlType As DbType, ByVal paramSize As Integer, ByVal paramDirection As ParameterDirection, ByVal paramvalue As Object)

If sqlCmd Is Nothing Then
Throw New ArgumentNullException("sqlCmd")
End If

If paramId = String.Empty Then
Throw New ArgumentOutOfRangeException("paramId")
End If

Dim newSqlParam As DbParameter = dbF.CreateParameter

newSqlParam.DbType = sqlType
newSqlParam.Direction = paramDirection
newSqlParam.ParameterName = paramId

If paramSize > 0 Then
newSqlParam.Size = paramSize
End If

If Not paramvalue Is Nothing Then
newSqlParam.Value = paramvalue
End If

sqlCmd.Parameters.Add(newSqlParam)

End Sub

However the same code with connector 5.0.2 gives "Parameter '?ETURN_VALUE' not found in the collection."

Specifying the parameter as "?RETURN_VALUE" gives "Parameter '?RETURN_VALUE' not found in the collection." in 5.0.2 and " #42000You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '''=MEM_GetUserNameByEmail ('', '')' at line 1" with 5.0.1

I'm guessing this change is related to the new requirement for parameter markers but I can't seem to find the code to confirm it.

Thanks for your help,

Chris...

[edit: this post was about two different problems, but it seems they were just aspects of the same problem so I've removed the extra bits]



Edited 1 time(s). Last edit at 12/07/2006 06:14AM by Chris Sinclair.

Options: ReplyQuote


Subject
Written By
Posted
Connector/Net parameter markers bug?
December 07, 2006 05:05AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.