日期:2014-05-16  浏览次数:20933 次

C#中无法设置delimiter?
C# code

using (System.Data.Odbc.OdbcConnection cnn = new System.Data.Odbc.OdbcConnection())
            {
                cnn.ConnectionString = "...";//连接字符串没问题,这里省略
                cnn.Open();
                System.Data.Odbc.OdbcCommand command = cnn.CreateCommand();
                command.CommandText = "DELIMITER |";
                command.ExecuteNonQuery();
            }


为啥会暴异常呢?

------解决方案--------------------
这个delimiter是交互环境下的命令,不是mysql的客户端接口。
------解决方案--------------------
测试如下。

C# code
using System;
using MySql.Data.MySqlClient;
using System.Data;
using System.Data.OracleClient;
using System.Globalization;
using System.Collections;


.....
        static void Main(string[] args)
        {
            string sMySQLConnStr = "Database='csdn';Data Source='localhost';User Id='root';Password='123'";
            MySqlConnection mysqlCnn = new MySqlConnection(sMySQLConnStr);
            mysqlCnn.Open();
            MySqlCommand cmd = new MySqlCommand("DROP PROCEDURE IF EXISTS sp_test;create procedure sp_test() begin select 1; end ;", mysqlCnn);
            cmd.ExecuteNonQuery();
        }