100分在线急求 程序中执行.sql脚本 mysql的 如果有存储过程,直接点击button时执行相关存储。如果没有存储过程,单独放进一个文本文件吧,要执行的时候读文件传sql过去!不过怎么感觉这是在多此一举啊。后缀为sql的文件就算是查询分析器打开也不是会自动执行的。你还是得调用执行的命令对象。和一般写法没多大区别的啊。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我的网站现在卡在这里了 其它功能不好动 只能在程序中后台处理.sql脚本的执行了 就是说我现在有一个aaa.sql的脚本文件 我想在.net的程序中把它给执行了 导入其中的数据到已经建好的数据库中 我也知道执行MySQl.exe 关键是线在不想这样做 你不调用执行sql的命令对象好像是做不到的吧。那我就实在是没办法了。 string s = "--host=localhost --user=root --password=root lanqiu -r \"" + string.Format("{0}", @"d:\dabao.sql") + "\"";System.Diagnostics.Process.Start(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqldump.exe", s); 这个是导出的执行语句 导入得怎么弄啊 其中 用户root 密码root 数据库lanqiu 导出路径d:\dabao.sql 楼主,能不能换种方式,把要执行的SQL语句放到页面的PageLoad中,要执行哪句SQL就打开那个窗口,执行完返回原来窗口 直接执行*.SQL很难,SQL语句是可以的,或者写成存储过程再执行 不懂,没见过怎么执行.sql文件呢,来学习一下 http://topic.csdn.net/u/20080730/10/7373a572-8ec8-40d3-bc8e-eac092b3d78c.html?seed=1111677487你看看这里的贴子,好像是可以解决的。 还不如将AAA.SQL写入一个存储过程。。然后执行存储过程 关键是客户提供过来的是.sql文件 在我这里汇总啊 各个.sql文件都不一样 我要写多少个存储过程啊 必须在程序里运行的话,考虑12楼的建议把要么创建一个批处理文件,只要有新的.sql文件,就把批处理文件更新,然后执行批处理文件。OSQL..命令好像是执行.sql文件的。好久没弄 记不太清楚 using System;using System.Data;using System.Collections;using System.Xml;using System.IO;using System.Text;using System.Diagnostics; namespace sym{ public class symConsole { [STAThread] static void Main(string[] args) { string sqlQuery = "osql.exe /uSa /p123 /s192.192.132.229 /dNorthWind /i yoursql.sql"; string strRst = ExeCommand(sqlQuery); Console.WriteLine(strRst); Console.ReadLine(); } public static string ExeCommand(string commandText) { Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; string strOutput = null; try { p.Start(); p.StandardInput.WriteLine(commandText); p.StandardInput.WriteLine("exit"); strOutput = p.StandardOutput.ReadToEnd(); p.WaitForExit(); p.Close(); } catch(Exception e) { strOutput = e.Message; } return strOutput; } }}对于osql命名的参数如下:===================== 用法: osql [-U login id] [-P password] [-S server] [-H hostname] [-E trusted connection] [-d use database name] [-l login timeout] [-t query timeout] [-h headers] [-s colseparator] [-w columnwidth] [-a packetsize] [-e echo input] [-I Enable Quoted Identifiers] [-L list servers] [-c cmdend] [-D ODBC DSN name] [-q "cmdline query"] [-Q "cmdline query" and exit] [-n remove numbering] [-m errorlevel] [-r msgs to stderr] [-V severitylevel] [-i inputfile] [-o outputfile] [-p print statistics] [-b On error batch abort] [-X[1] disable commands [and exit with warning]] [-O use Old ISQL behavior disables the following] [-? show syntax summary] 大哥 我说了 我的库是 MYSql 不是Sql Server 不想用查询,把.sql写成.bat,执行一下.哈哈,莫名其妙的问题! string s=@"mysql -uroot -pyourpassword yourdatabasename < c:\aaa.sql";System.Diagnostics.Process.Start(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysql.exe", s); 不太明白你的意思,我想你可以用MVC的方式做 svn服务器端的汉化版 怎么提取关键词搜索相关内容? 用了UpdatePanel后,javascript脚本找不到函数,出现缺少对象错误 想去读取一个ASP页面的HTML代码? 问一个数据库数据导入到word的问题,如能解决,再加200分 如何在自定义服务器控件中添加在设计时添加静态项的特性 DataGrid怎么合并页脚 或合并某行 某列 生成一个动态菜单该怎么做啊? 推荐一个能够较好的把VB.Net代码转换为C#代码的工具 网上找的网页播放器,通用的,就是不知道怎么用。 急急急,在线等待.gridview绑定下拉列表并根据用户权限及条件操作数据库. 谁来帮我写这个的正则
那我就实在是没办法了。
你看看这里的贴子,好像是可以解决的。
要么创建一个批处理文件,只要有新的.sql文件,就把批处理文件更新,然后执行批处理文件。
OSQL..命令好像是执行.sql文件的。好久没弄 记不太清楚
using System.Data;
using System.Collections;
using System.Xml;
using System.IO;
using System.Text;
using System.Diagnostics;
namespace sym
{
public class symConsole
{
[STAThread]
static void Main(string[] args)
{
string sqlQuery = "osql.exe /uSa /p123 /s192.192.132.229 /dNorthWind /i yoursql.sql";
string strRst = ExeCommand(sqlQuery);
Console.WriteLine(strRst);
Console.ReadLine();
}
public static string ExeCommand(string commandText)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
string strOutput = null;
try
{
p.Start();
p.StandardInput.WriteLine(commandText);
p.StandardInput.WriteLine("exit");
strOutput = p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
}
catch(Exception e)
{
strOutput = e.Message;
}
return strOutput;
}
}
}对于osql命名的参数如下:
=====================
用法: osql [-U login id] [-P password]
[-S server] [-H hostname] [-E trusted connection]
[-d use database name] [-l login timeout] [-t query timeout]
[-h headers] [-s colseparator] [-w columnwidth]
[-a packetsize] [-e echo input] [-I Enable Quoted Identifiers]
[-L list servers] [-c cmdend] [-D ODBC DSN name]
[-q "cmdline query"] [-Q "cmdline query" and exit]
[-n remove numbering] [-m errorlevel]
[-r msgs to stderr] [-V severitylevel]
[-i inputfile] [-o outputfile]
[-p print statistics] [-b On error batch abort]
[-X[1] disable commands [and exit with warning]]
[-O use Old ISQL behavior disables the following]
[-? show syntax summary]