zoukankan      html  css  js  c++  java
  • 【紧急提问】:MySql存储过程脚本中含有预处理语句时,不能执行脚本

    ## 不含预处理的存储过程

    ## 存储过程 CustomCount.sql : 取各个表的记录数

    Drop Procedure If Exists CustomCount;

    Create Procedure CustomCount

     (  

         out RowNum bigint

    )

    Not Deterministic

    SQL Security Definer

    Comment ''

    Begin  

         Select Count(*) Into RowNum From uc_members;

    End;

    ------------------------------------------------------------------------

    ## 含预处理的存储过程

    ## 存储过程GetCount.sql: 传入表名,取某个表的记录数 Drop Procedure If Exists GetCount;

    Create Procedure GetCount

     (  

         TableName varchar(100)  

         , out RowNum bigint

    )

    Not Deterministic

    SQL Security Definer

    Comment ''

    Begin  

         Declare SQLStr varchar(2000) default '';

         Set SQLStr = Concat('Select Count(*) Into @MyNum From ', TableName);

         Set @ResultSQL = SQLStr;  

         Prepare preSQL From @ResultSQL;  

         Execute PreSQL;

         Deallocate Prepare preSQL;    

         Set RowNum = @MyNum;

    End;

    -------------------------------------------------------------------------

    上述两个存储过程脚本,在C#中读取文件内容后,运行,含预处理的存储过程执行失败。是什么原因呢??

    附件是 .NET Framework 4.0的WinForm运行脚本源码示例,含这两个存储过程。

    请修改您的MySql连接字符串即可。

    CustomCount.sql中的uc_members表名变可改成您的表名。

    点此下载

    备注:

    1. 制作Web安装包时,需要用程序运行MySql脚本,而这些脚本中,经常含有 预处理脚本。

    2. 使用这个预处理脚本主要是为了 在动态执行SQL 时取得输出参数的值(类似GetCount.sql中取值)。

    3. 不要建议说,使用mysql.exe这个命令一个一个的运行,或者说是调用其它 MySql的.dll或.exe这种方式,因为Web安装时,经常是没有权限取得本地文件的执行权限的。

    4. 主要是需要在虚拟主机下进行Web安装。

    谢谢。

  • 相关阅读:
    利用outlook发送邮件的代码,其实就一句话,哈哈~~
    一个或多个数据库无法访问,因而不会在数据库访问选项卡中显示
    窗口碰壁弹回的浮动广告代码
    DataFormatString格式化数据及格式化时间失效的问题
    弹出并转向代码
    常用运行命令
    post和get
    自己总结的手动生成gridview导出excel的方法
    Spring boot download file
    RESTful WebService 入门实例
  • 原文地址:https://www.cnblogs.com/liuweitoo/p/2261466.html
Copyright © 2011-2022 走看看