让代码执行MySQL例程时遇到问题。
不断弹出错误:
Procedure or function 'ShortenedURLS' cannot be found in database 'Get'.
例行程序

DELIMITER $$

USE `o7thurlshortner`$$

DROP PROCEDURE IF EXISTS `Get.ShortenedURLS`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `Get.ShortenedURLS`(IN `ID` BIGINT)
    NO SQL
SELECT `ShortID`, `ShortCode`, `URL`, `ClickThroughs`
FROM `Shortener`
WHERE `AccountID` = ID$$

DELIMITER ;

代码-访问和运行例程
    internal DbDataReader GetResults()
    {
        try
        {
            // check for parameters
            if (AreParams())
            {
                PrepareParams(_Cmd);
            }
            // set our connection
            _Cmd.Connection = _Conn;
            // set the type of query to run
            _Cmd.CommandType = _QT;
            // set the actual query to run
            _Cmd.CommandText = _Qry;
            // open the connection
            _Cmd.Connection.Open();
            // prepare the command with any parameters that may have gotten added
            _Cmd.Prepare();
            // Execute the SqlDataReader, and set the connection to close once returned
            _Rdr = _Cmd.ExecuteReader(CommandBehavior.CloseConnection);
            // clear out any parameters
            _Cmd.Parameters.Clear();
            // return our reader object
            return (!_Rdr.HasRows) ? null : _Rdr;
        }
        catch (DbException SqlEx)
        {
            _Msg += "Acccess.GetResults SqlException: " + SqlEx.Message;
            ErrorReporting.WriteEm.WriteItem(SqlEx, "o7th.Class.Library.Data.MySql.Access.GetResults", _Msg);
            return null;
        }
        catch (Exception ex)
        {
            _Msg += "Acccess.GetResults Exception: " + ex.Message;
            ErrorReporting.WriteEm.WriteItem(ex, "o7th.Class.Library.Data.MySql.Access.GetResults", _Msg);
            return null;
        }
    }

代码-关闭它
        IList<Typing> _T = Wrapper.GetResults<Typing>("Get.ShortenedURLS",
            System.Data.CommandType.StoredProcedure,
            new string[] { "?ID" },
            new object[] { 1 },
            new MySqlDbType[] { MySqlDbType.Int32 },
            false);

更新
一旦我启动了一个没有.的例程,就验证了它是否可以正常工作。
如果我的例程确实有.,我怎么能让它工作呢?我不能简单地重写与高流量网站相关的生产数据库中的现有程序……

最佳答案

为了调用您的存储过程,您必须将它的名称用反勾号括起来,因为它包含特殊字符.
但是,mysql连接器代码中存在一个错误,导致它再次转义。当您指定

cmd.CommandType = CommandType.StoredProcedure;

执行读取器期间的代码分支,如下所示。。。
if (statement == null || !statement.IsPrepared)
{
  if (CommandType == CommandType.StoredProcedure)
    statement = new StoredProcedure(this, sql);
  else
    statement = new PreparableStatement(this, sql);
}

// stored procs are the only statement type that need do anything during resolve
statement.Resolve(false); // the problem occurs here

Resolve的一部分功能是修复过程名。。
//StoredProcedure.cs line 104-112
private string FixProcedureName(string name)
{
    string[] parts = name.Split('.');
    for (int i = 0; i < parts.Length; i++)
        if (!parts[i].StartsWith("`", StringComparison.Ordinal))
            parts[i] = String.Format("`{0}`", parts[i]);
    if (parts.Length == 1) return parts[0];
    return String.Format("{0}.{1}", parts[0], parts[1]);
}

正如您在这里看到的,只要存储过程名有一个。在它中,存储过程的名称被分解成多个部分并单独转义,这将导致代码无法调用存储过程。
所以你唯一的解决办法是。。
1)用oracle打开一个bug来修复提供者(假设没有一个已经打开)
2)将存储过程的名称更改为不使用。
3)下载提供者的代码,修复它,重新编译
4)找到另一个连接器

关于c# - MySQL .Net连接器问题执行例程,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21483920/

10-12 16:11