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.