在C#中运行数据库脚本 [英] Running Database scripts in C#

查看:115
本文介绍了在C#中运行数据库脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在c#中运行数据库脚本(MySql db scripts)。



谢谢,
sirni。

解决方案

使用脚本作为输入,分叉子进程并执行 mysql 命令行客户端。

尝试将脚本读取为一个文件并在其中逐个执行SQL命令是很有诱惑力的,但是在SQL脚本中有许多语句无法以此方式执行。



所以你必须重复mysql客户端的代码,以便运行SQL脚本。你自己喜欢和使用已经为此目的设计的程序。


How to run database scripts(MySql db scripts) in c#.

Thanks, sirni.

解决方案

Fork a child process and execute the mysql command-line client, using the script as input.

It's tempting to try to read the script as a file and execute the SQL commands within it one by one, but there are numerous statements in an SQL script that can't be executed that way.

So you'd have to duplicate the code of the mysql client anyway in order to run an SQL script. Do yourself a favor and use the program that is already designed for that purpose.

这篇关于在C#中运行数据库脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆