c# export server 调用sql_[转]使用C#调用cmd来执行sql脚本
本文转自:https://blog.csdn.net/tvmerp/article/details/1822669
下面是使用C#调用cmd来执行osql实现脚本的执行。
using System;
using System.Data;
using System.Collections;
using System.Xml;
using System.IO;
using System.Text;
using System.Diagnostics;
namespace ZZ
{
public class ZZConsole
{
[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]
具体参考
http://www.588188.com/netbook/sqlserver2000/coprompt/cp_osql_1wxl.htm
或者sql server 2000帮助文档
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1769232
原文:https://www.cnblogs.com/freeliver54/p/8990573.html
c# export server 调用sql_[转]使用C#调用cmd来执行sql脚本相关推荐
- Oracle调用接口(OCI)源码剖析(2):执行SQL语句并获取结果
概述 接着上一篇文章<Oracle调用接口(OCI)源码剖析(1):创建数据库连接>,我们继续对OCI中执行SQL语句并获取结果的源码进行剖析.该操作主要是由两个函数完成的:CDbExec ...
- java直接调用并执行sql脚本
1.背景:项目本身功能简单,不想使用开源框架引入过多不需要的依赖,避免程序部署时,人工忘记执行sql脚本文件问题 2.此demo为使用mybatis中脚本执行工具类org.apache.ibatis. ...
- java调用MySQL脚本_Java调用SQL脚本执行常用的方法示例
前言 大家都知道,在Java中调用SQL脚本的方式有多种,在这里只记录一种自己常用的方式,个人觉得挺实用方便的. 运用ScriptRunner这个类. ScriptRunner类用于执行SQL语句,例 ...
- SQL server 定时自动执行SQL存储过程
当一个存储过程是为了生成报表,并且是周期性的,则不需要人工干预,由SQL作业定时自动执行些SQL存储过程即可. 本示例,假设已需要定时执行的存储过程为:Pr_test 工具/原料 SQL Server ...
- aws rds监控慢sql_使用本机备份的AWS RDS SQL Server迁移
aws rds监控慢sql In this article, we will review how to migrate database from on-premises SQL Server in ...
- centos7 安装sql_在Linux Distribution CentOS 7上安装SQL Server vNext CTP
centos7 安装sql .polje { font-family:'Courier New'; } .polje { font-family:'Courier New'; } It was a p ...
- java按钮调用 后台方法_onclick怎么调用后台中的一个方法
javaScript函数中执行C#代码中的函数: 方法一:1.首先建立一个按钮,在后台将调用或处理的内容写入button_click中; 2.在前台写一个js函数,内容为document.getEle ...
- oracle创建包 和调用,oracle创建函数和调用存储过程和调用函数的例子(区别)...
创建函数: 格式:create or replace function func(参数 参数类型) Return number Is Begin --------业务逻辑--------- End; ...
- java 调用casperjs_Java程序去调用并执行shell脚本及问题总结(推荐)
摘要: 该文章来自阿里巴巴技术协会(ATA)精选集 背景 我们在开发过程中,大部分是java开发, 而在文本处理过程中,主要就是脚本进行开发. java开发的特点就是我们可以很早地进行TDDL, ME ...
最新文章
- JAVA(IO流)知识整理
- 如何优雅的导出Excel
- 读excel文件至DataTable
- 2019年6月26 突然想到的代码优化
- 新浪的股票接口 c#
- mysql对测试如何_我如何对MySQL进行基准测试?
- Struts使用细节
- 创造与魔法最新服务器怎么进,创造与魔法进不了服务器 | 手游网游页游攻略大全...
- CodeForces - 589A
- [WPF自定义控件库] 自定义控件的代码如何与ControlTemplate交互
- echarts 环形图鼠标悬停
- Meanshift均值漂移聚类算法
- Unity小地图跟随人物移动
- python代码范文_如何给你的Python代码“减负”,这里有一份指南请查收
- 图文模态交互 | CLIP + GAN = ?
- 【web前端教程笔记】
- 亚信卸载-无需密码卸载
- java面试题120题
- 计算机主机故障检测原则,1.计算机故障处理应遵循的基本原则有哪些? 爱问知识人...
- 网络请求(四)Retrofit实战——金山词霸查词API遇到的问题
热门文章
- Windows进程与线程学习笔记(一)—— 进程结构体
- 23、HTML图像按钮
- 二叉树的先序线索化、中序线索化、后序线索化的对比
- 【PAT乙级】 1015 德才论 (25 分)
- Spring RabbitMQ使用
- php学历低,学历低学起php来难不难
- 什么意思呢_technician是什么意思
- python polar contour_Python将2darray的最后一行和第二列添加到最后位置 - Polar Contour图...
- 海量数据下如何使用多线程的导出 Excel
- 字节跳动P0级事故:实习生删除GB以下所有模型,直接上了今日头条......