Hi,
my hosted domain does not support MySql.Data.MySqlClient.
Compiler Error Message: CS0246:
The type or namespace name 'MySql'
could not be found
(are you missing a using directive or an assembly reference?)
I was instructed to use the odbc driver to connect to my mysql database and exec the stroed procedure.
I have never used this type of connection in the past and in fact I get this error
ERROR [HY000] [MySQL][ODBC 5.1 Driver][mysqld-5.7.36-39-log]
OUT or INOUT argument 2 for routine Sql1705329_1.prima_sp
is not a variable or NEW pseudo-variable in BEFORE trigger
How to do resolve this?
sProc
CREATE DEFINER=`root`@`%` PROCEDURE `sProc`(
IN pDateHH CHAR(100),
IN pSQL CHAR(100))
BEGIN
SET pSQL := NULL;
SET @s = CONCAT('SELECT * from dotable WHERE DAY(pDateHH) = ',pDateHH,';');
SET pSQL = pDateHH;
PREPARE stmt FROM @s;
EXECUTE stmt;
DEALLOCATE PREPARE `stmt`;
SELECT pSQL;
END
.cs
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.Odbc;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
try
{
using (OdbcConnection connection =
new OdbcConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString))
{
using (OdbcCommand cmd =
new OdbcCommand("{call sProc(?,?)}", connection))
{
cmd.Connection.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@pDateHH", "17");
cmd.Parameters.AddWithValue("@pSQL", OdbcType.VarChar).Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
cmd.Connection.Close();
string txt = cmd.Parameters["pSQL"].Value.ToString();
Response.Write(txt.ToString());
Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert",
"alert('txt >>> " + txt.ToString() + ".');", true);
}
}
}
catch (Exception ex)
{
throw new ApplicationException("operation failed!", ex);
}
finally
{
}
}
}
}