English 中文(简体)
• 如何执行我的剪辑申请。
原标题:How to execute *.sql mysql file in my c# application
  • 时间:2012-01-13 18:13:46
  •  标签:
  • c#
  • .net
  • mysql

我在一份档案中有我的手脚,我需要能够从我的剪切申请中执行。 下面是文字的样本:

USE osae;

-- Set DB version 
CALL osae_sp_object_property_set( SYSTEM ,  DB Version ,  0.3.5 ,   ,   );
CALL osae_sp_object_property_set( SYSTEM ,  Debug ,  FALSE ,   ,   );
CALL osae_sp_object_type_property_add ( Prune Logs , Boolean , TRUE , SYSTEM ,0);
CALL osae_sp_object_property_set ( SYSTEM , Prune Logs , TRUE ,  ,  );

DELIMITER $$

DROP PROCEDURE IF EXISTS osae_sp_object_event_script_update$$
CREATE DEFINER =  root @ localhost 
PROCEDURE osae_sp_object_event_script_update(IN pobject varchar(200), IN pevent varchar(200), IN ptext text)
BEGIN
DECLARE vObjectCount INT;
DECLARE vObjectID INT;
DECLARE vObjectTypeID INT;
DECLARE vEventCount INT;
DECLARE vEventID INT;
    SELECT COUNT(object_id) INTO vObjectCount FROM osae_object WHERE UPPER(object_name)=UPPER(pobject);
    IF vObjectCount > 0 THEN
              SELECT object_id,object_type_id INTO vObjectID,vObjectTypeID FROM osae_object WHERE UPPER(object_name)=UPPER(pobject);
        SELECT COUNT(event_id) INTO vEventCount FROM osae_object_type_event WHERE object_type_id=vObjectTypeID AND (UPPER(event_name)=UPPER(pevent) OR UPPER(event_label)=UPPER(pevent));
        IF vEventCount = 1 THEN     
            SELECT event_id INTO vEventID FROM osae_object_type_event WHERE object_type_id=vObjectTypeID AND (UPPER(event_name)=UPPER(pevent) OR UPPER(event_label)=UPPER(pevent));
            UPDATE osae_object_event_script SET event_script=ptext WHERE object_id=vObjectID AND event_id=vEventID;
         -- CALL osae_sp_debug_log_add(CONCAT( Updated  ,vObjectID,  -  ,vEventID,ptext),  );  
        END IF;
    END IF; 
END
$$

DELIMITER ;

由于你可以看到,它有一条混合线,要求储存程序,有些下降,并编制更新其他储存程序的声明。

我尝试了两种不同的方法来执行文字,这两种方法都失败了:

MySqlScript script = new MySqlScript(connection, File.ReadAllText("script.sql"));
script.Execute();

这 exception倒了例外:指数超出了阵列的范围。

MySqlCommand upgCommand = new MySqlCommand();
upgCommand.Connection = connection;
upgCommand.CommandText = File.ReadAllText("script.sql");
upgCommand.ExecuteNonQuery();

这使我的一个例外是,我的yn子有错误。

当我手工操作整个录像带时,它完全执行。 我如何能够从我的C#附录中正确执行这一文字。

最佳回答

查询rel=“nofollow noretinger”>here。 您应具体指明MySql标语(因为你在那里储存了程序)。 你的问:

-- Set DB version 
CALL osae_sp_object_property_set( SYSTEM ,  DB Version ,  0.3.5 ,   ,   )$$
CALL osae_sp_object_property_set( SYSTEM ,  Debug ,  FALSE ,   ,   )$$
CALL osae_sp_object_type_property_add ( Prune Logs , Boolean , TRUE , SYSTEM ,0)$$
CALL osae_sp_object_property_set ( SYSTEM , Prune Logs , TRUE ,  ,  )$$



DROP PROCEDURE IF EXISTS osae_sp_object_event_script_update$$
CREATE DEFINER =  root @ localhost 
PROCEDURE osae_sp_object_event_script_update(IN pobject varchar(200), IN pevent varchar(200), IN ptext text)
BEGIN
DECLARE vObjectCount INT;
DECLARE vObjectID INT;
DECLARE vObjectTypeID INT;
DECLARE vEventCount INT;
DECLARE vEventID INT;
    SELECT COUNT(object_id) INTO vObjectCount FROM osae_object WHERE UPPER(object_name)=UPPER(pobject);
    IF vObjectCount > 0 THEN
              SELECT object_id,object_type_id INTO vObjectID,vObjectTypeID FROM osae_object WHERE UPPER(object_name)=UPPER(pobject);
        SELECT COUNT(event_id) INTO vEventCount FROM osae_object_type_event WHERE object_type_id=vObjectTypeID AND (UPPER(event_name)=UPPER(pevent) OR UPPER(event_label)=UPPER(pevent));
        IF vEventCount = 1 THEN     
            SELECT event_id INTO vEventID FROM osae_object_type_event WHERE object_type_id=vObjectTypeID AND (UPPER(event_name)=UPPER(pevent) OR UPPER(event_label)=UPPER(pevent));
            UPDATE osae_object_event_script SET event_script=ptext WHERE object_id=vObjectID AND event_id=vEventID;
         -- CALL osae_sp_debug_log_add(CONCAT( Updated  ,vObjectID,  -  ,vEventID,ptext),  );  
        END IF;
    END IF; 
END
$$

接着,你的法典:

MySqlScript script = new MySqlScript(connection, File.ReadAllText("script.sql"));
script.Delimiter = "$$";
script.Execute();
问题回答

你可以单独开展执行文字的工作。 例如:

Process.Start("mysql < script.sql");

也许你们需要与它一道做些什么,这多少取决于你们的环境,把通往可执行我的手法或手稿的道路包括在内。

贵国如何将贵方言放在储存程序中? 如果你仍然希望使用这一方式,将 s子档案作为申请资源(档案)的档案,并像以下那样加以执行:

MySql.Data.MySqlClient.MySqlCommand cmdMySQL = newMySqlConnection.CreateCommand();
cmdMySQL.CommandText = (System.String)globalResource.your_file_name;

我不是100%地确定MySql syntax的原住者是什么,但当我们为Sql服务器发挥类似功能时,我们必须根据字面价值(<条码>GO)将 s子分解成只供查询员使用(Sql服务器管理Console)使用的chu。

我怀疑您的上述请求中可能载有类似的资料,例如法国统计局的声明。

确切了解MySql所抱怨的内容将有助于改进解决办法。

工作:

connectOb.conn.Open();
MySqlScript script = new MySqlScript(connectOb.conn, 
"SET @num := 0; 
UPDATE serving_table SET Id = @num := (@num + 1);
ALTER TABLE serving_table AUTO_INCREMENT = 1;");
script.Execute();
connectOb.conn.Close();




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签