0

I am using MySql 5.6 Server, client, C# Connector and Workbench on a Ubuntu 16.04 Lenovo ThinkStation desktop. I am experiencing a problem with the following stored procedure shown below when it is programmatically invoked with the MySQL C# Connector API:

CREATE PROCEDURE spAddInto_TableOne_and_TableTwo(
     IN now datetime not null,
     IN quantity int not null,
     IN desc nvarchar(32) not null)
   BEGIN

     call spAddInto_TableOne(now,quantity,desc);
     call spAddInto_TableTwo(now,quantity,desc);

   END;

where MySql TableOne looks like this:

CREATE TABLE TableOne(
EventDateTime datetime NOT NULL, 
Quantity smallint NULL,
Description nvarchar(32) NULL,
ID int AUTO_INCREMENT NOT NULL,
PRIMARY KEY (ID)
)

and Table 2 looks like this:

CREATE TABLE TableOne(
EventDateTime datetime NOT NULL, 
Quantity smallint NULL,
Description nvarchar(32) NULL,
ID int AUTO_INCREMENT NOT NULL,
PRIMARY KEY (ID)
)

and

MySql stored procedures spAddInto_TableOne and spAddInto_TableTwo are very similar atomic insert statements using implicit transactions as shown here:

    INSERT INTO TableOne
           (    EventDateTime
           ,    Type
           ,    Description)
     VALUES
           (    _eventDateTime
           ,    _type
           ,    ltrim(rtrim(_description))) 

and

  INSERT INTO TableTwo
           (    EventDateTime
           ,    Type
           ,    Description)
     VALUES
           (    _eventDateTime
           ,    _type
           ,    ltrim(rtrim(_description))) 

With this background, here I state my problem which I was hoping an clever programmer could fix:

When the stored procedure , spAddInto_TableOne_and_TableTwo, is programmatically invoked with the MySQL C# Connector API, only TableTwo is inserted into and TableOne remains empty.

It is interesting to note that when I run spAddInto_TableOne_and_TableTwo in MySql Workbench, I noticed it functions okay by inserting a row into TableOne and TableTwo.

This is my C# MySql Connector framework code:

SqlConnection conn = new SqlConnection(MyConnectionString);

conn.Open();
SqlCommand cmd = new SqlCommand(sProc, conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("eventDateTime", eventDate);
cmd.Parameters.AddWithValue("eventtype", type);
cmd.Parameters.AddWithValue("description", desc.Trim())

cmd.ExecuteNonQuery();

Should I use C# MySqlConnection.BeginTransaction() and MySqlConnection.Commit() in the C# code directly above?

Any help is greatly appreciated.

Frank
  • 1,406
  • 2
  • 16
  • 42
  • I don't work with MySql but I do work with ADO.Net and I think you have to prefix your parameters with `@` or `?` even with MySql. – Crowcoder Jul 16 '16 at 11:14
  • You are using the wrong classes, no? See what I answered [Here](http://stackoverflow.com/a/38089869) – Drew Jul 16 '16 at 11:35
  • @Drew, Thank you for your comment. I am using the right MySQL Connector classes because I aliased MySQLConnection and MySQLCommand as SQLConnection and SQLCommand respectively. – Frank Jul 16 '16 at 12:08
  • bundle up a zip of the .cs and the .sql for create tables and I will test it – Drew Jul 16 '16 at 12:09
  • @Crowcoder, Thank you for your comment. You have to prefix your parameters with @ with Microsoft SQLServer. I did not preface MySQLParameter with ? or @. – Frank Jul 16 '16 at 12:17
  • @Drew, May I ask how to send the zip of the .cs and the sql for the stored procedures and tables? Thank you. – Frank Jul 18 '16 at 01:55
  • @Crowcoder, You are entirely correct about prefixing parameters with @ and MySQL on Ubuntu 16.04 with C#. Thank you. – Frank Jul 18 '16 at 01:57
  • Please do not be misled by the article, How can I see the command string when using MySqlCommand parameters?, with URL as follows on Ubuntu Linux 16.04 , http://stackoverflow.com/questions/20205550/how-can-i-see-the-command-string-when-using-mysqlcommand-parameters – Frank Jul 18 '16 at 02:00
  • Based on the environment that I have (seen in the 2nd comment up there) I am happy to test anything within reason. In other words, if it fits my .NET environment without some install. My email address is drewpierce747 @ gmail – Drew Jul 18 '16 at 02:19
  • @Drew, I am about to email you now. I went to college in Boston and lived there until a year ago in Arlington Heights, Massachuetts. Thank you. – Frank Jul 18 '16 at 09:22

0 Answers0