Quantcast
Channel: MySQL Forums - Connector/NET and C#, Mono, .Net
Viewing all articles
Browse latest Browse all 1451

not declaring variables returns a byte array instead of a varchar in .Net app (2 replies)

$
0
0
Hi

I posted this problem as a bug:
http://bugs.mysql.com/bug.php?id=62435

Does anyone had the same problem?




We changed from a MYSQL5.0.26 to a MYSQL5.1.49 server on a Debian server.
The stored procedure worked ok on the 5.0.26 but when i moved to 5.1.49 the problem
appeared.




The core of the problem is that running a stored procedure in 5.0.26 returns a different data type in 5.1.49

--------------------------------------------------------------
(((Mysql 5.0.26)))
mysql> call pruebados('');
Field 1: `a`
Catalog: `def`
Database: ``
Table: ``
Org_table: ``
Type: VAR_STRING <<<<<<<<<<<<<<<<<<<<<<<expected data type =)!
Collation: latin1_swedish_ci (8)
Length: 8192
Max_length: 2
Decimals: 31
Flags:

+------+
| a |
+------+
| 01 |
+------+
1 row in set (0.00 sec)
---------------------------------------------------------------

(((Mysql 5.1.49)))
mysql> call pruebados('');
Field 1: `a`
Catalog: `def`
Database: ``
Table: ``
Org_table: ``
Type: MEDIUM_BLOB <<<<<<<<<<<<<<<<<<<<<<<wrong data type, expecting varchar
Collation: latin1_swedish_ci (8)
Length: 16777215
Max_length: 2
Decimals: 31
Flags:

+------+
| a |
+------+
| 01 |
+------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)
--------------------------------------------------------------





Description of the problem:
===========================
.Net won't understand the result of the Stored procedure as a varchar, while setting a
variable inside of a stored procedure without declaring the variable before. It receives
a Byte array containing the the chars of the varchar that should had been returned.

This is the section of the SProcedure that isn't working in 5.1.49 for .net:
----------------------------------------------------
CREATE DEFINER=`bancaria`@`%` PROCEDURE `pruebados`(par1 varchar(2))
BEGIN
set @a = lpad('1',2,'0');
select @a as "a";
END;
----------------------------------------------------

This is the app in .net:
----------------------------------------------------

Dim sqlCommand As New MySqlCommand
sqlCommand.Connection = ConectarToMySql(True)
sqlCommand.CommandType = CommandType.StoredProcedure
sqlCommand.CommandText = "pruebados"
sqlCommand.Parameters.AddWithValue("par1", "1")
Dim adapt = New MySqlDataAdapter(sqlCommand)
adapt.Fill(dt)
----------------------------------------------------
The result in dt is 'System.Byte[]' which contains a 48,49 instead of '01' as it should.

If I change the Stored procedure by adding the declaration of the variable, it works ok:
----------------------------------------------------
CREATE DEFINER=`bancaria`@`%` PROCEDURE `pruebados`(par1 varchar(2))
BEGIN
declare a varchar(2);
set a = lpad('1',2,'0');
select a as "a";
END;

How to repeat:
CREATE DEFINER=`bancaria`@`%` PROCEDURE `pruebados`(par1 varchar(2))
BEGIN
set @a = lpad('1',2,'0');
select @a as "a";
END;
----------------------------------------------------

This is the app in .net:
----------------------------------------------------

Dim sqlCommand As New MySqlCommand
sqlCommand.Connection = ConectarToMySql(True)
sqlCommand.CommandType = CommandType.StoredProcedure
sqlCommand.CommandText = "pruebados"
sqlCommand.Parameters.AddWithValue("par1", "1")
Dim adapt = New MySqlDataAdapter(sqlCommand)
adapt.Fill(dt)
----------------------------------------------------
The result in dt is 'System.Byte[]' which contains a 48,49 instead of '01' as it should.

Suggested fix:
it can be fixed by declaring all the variables before using them, but i would like to
know why this is happening.



THANK YOU FOR UR TIME!

Viewing all articles
Browse latest Browse all 1451

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>