在.NET执行SQL脚本的简单实现

SQL小工具 批量执行SQL脚本文件(WinForm开发 .Net 2.0) 该工具主要支持两大功能: 1、批量执行SQL脚本文件; 2、文件拷贝操作。 其中,App.config为工具配置文件, 上述 中,value的值为数据库连接字符串。 Server=实例名;DataBase=数据库名;User ID=数据库用户名;password=数据库连接密码。 工具默认为Sql2000服务器,数据库用户名为sa,密码为空。 经验不足,望您能够指出改进的地方。 立即下载

使用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]

c# 代码生成器源码(C#语句,SQL脚本) 利用C#语言实现代码自动生成,且可以生成数据脚本语句。 立即下载

相关推荐

在.net执行sql脚本的简单实现

本文介绍了使用C#调用cmd来执行osql实现脚本的执行。

.NET 10 重磅特性:无需项目的C#脚本执行方案

.NET 10新特性:dotnetrunapp.cs简化C#开发 .NET 10 Preview 4推出dotnetrunapp.cs功能,允许开发者直接运行单个C#文件,无需创建项目文件或复杂目录结构。通过文件级指令(如#:package引用NuGet包、#:sdk指定SDK),可快速构建脚本或小型应用,并支持shebang行跨平台执行。当代码复杂度增加时,使用dotnetprojectconvert无缝转换为完整项目。此功能降低C#入门门槛,保留与标准项目的一致性,为学习、实验和脚本开发提供高效方案。安

weixin_41541184的博客 2195

HDMI接口协议

接口HDMI(High-Definition Multimedia Interface),新一代多媒体接口标准。即高清多媒体接口。它能够同时传输视频和音频,简化了设备的接口和连线;同时提供了更高的数据传输带宽,可以传输无压缩的数字音频及高分辨率视频信号。HDMI 1.0 版本于 2002 年发布,最高数据传输速度为 5Gbps;而2017 年发布的 HDMI 2.1 标准的理论带宽可达 48Gbps。1、能够同时传输视频和音频,简化了设备接口与连线。2、提供了更高的数据传输带宽,

weixin_42581439的博客 2606

.Net C#执行JavaScript脚本

ClearScript 是一个 .NET 平台下的开源库,用于在 C# 和其他 .NET 语言中执行脚本代码。它提供了一种方便和安全的方法来将脚本与应用程序集成,并允许将应用程序暴露给脚本以进行更高级别的自定义和交互。本文介绍了 ClearScript 的使用方法和特点,包括如何在 C# 中执行 JavaScript 脚本、如何与脚本交互、如何调用 C# 方法、多线程使用等方面的内容。

拥有必珍惜 1298

MuMu模拟器过检测实战:从硬件伪装到API欺骗的完整避坑指南

本文详细介绍了MuMu模拟器过检测的实战技术,从硬件伪装到API欺骗的全方位解决方案。通过修改CPU/GPU信息、内存分布、系统属性和行为模拟等关键技术,帮助用户有效绕过现代应用的模拟器检测机制,提升模拟器的隐蔽性和稳定性。

xxx12的博客 1452

RAG开源框架深度评测:从RAGFlow到Dify的实战选型指南

本文深度评测了主流RAG开源框架(RAGFlow、Dify、WeKnora)的核心能力与实战表现,提供企业级选型指南。重点对比了文档解析、检索性能和生产部署等关键指标,揭示RAGFlow在复杂文档处理、Dify在低代码开发、WeKnora在腾讯生态集成的差异化优势,并给出技术选型决策树与成本优化方案。

weixin_29294597的博客 842

.NET中执行sql文件

//执行脚本                 string infile = System.Web.HttpContext.Current.Server.MapPath("/Plguin/target/SQLQuery4.sql");                 Process sqlprocess = new Process();                 sqlprocess.

wangxinghui8的专栏 673

光谱特征选择之模拟退火算法SA

光谱特征选择之模拟退火算法SA。

weixin_42621095的博客 903

.net执行sql脚本

下面是使用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{[STAT

1283

llama.cpp量化模型在MTT显卡上的性能对比:S80/S3000/S4000实测数据

本文基于摩尔线程MTT S80、S3000和S4000三款显卡,对llama.cpp量化模型进行了深度性能实测。报告详细对比了不同量化精度(如Q4_K_M、Q6_K)在Llama 3.2 1B和Qwen 2.5 7B模型上的推理速度、显存占用、功耗及温度表现,为开发者根据硬件选择最优模型配置与参数调优提供了关键数据参考和实战指南。

week9的博客 362

Transformer实战(2)——循环神经网络详解

循环神经网络 (Recurrent neural networks, RNN) ,RNN 是在文本输入中广泛使用的神经网络。RNN 非常灵活,已被用于解决诸如语音识别、语言建模、机器翻译、情感分析和图像字幕等问题。RNN 利用输入的序列特性,序列输入可以是文本、语音、时间序列以及任何其他元素的出现取决于其前面元素的序列。在本节中,我们介绍了 RNN 及其变体,并学习如何使用 TensorFlow 进行实现。

盼小辉丶的博客 1万+

使用ADO.NET执行SQL脚本

public void ExecuteSql(SqlConnection connection, string sqlFile) { string sql = ""; using (FileStream strm = File.OpenRead(sqlFile)) { StreamReader reader = new Strea...

alili1991的博客 423

红队内网攻防渗透:内网渗透之内网对抗:实战项目&VPC1打靶&PHP-RCE&三层代理路由&防火墙上线&密码喷射&域控提权

上面已经抓取到了密码,但是我们通过拓扑分析看,要想上线win10只能通过正向shell,因为win7的防火墙是开的,win10反向主动连接肯定入站规则拦截,而win10自己没有开防火墙,所以win7主动正向连接就可以上线。win7开启了防火墙,入站规则肯定是会拦截我们的请求的,所以我们需要反向上线,让win7主动来连接我们。这里扫描发现是存在ms17010漏洞的,但是想上线192.168.2.142的话,我们没有路由是上线不了的,这里有两种办法:一种msf直接生成后门,另一种cs移植后门到msf。

HACKONE的博客 916

ASP.NET(C#)执行.SQL脚本实现数据库建表

Date:September 29, 2007  |  Author:Mz  |  From:FuCity.Net一,首先我们在SQL2000中导出SQL脚本1,企业管理器中控制台根目录选中你要导出的数据库,右击选择所有任务中的生成SQL脚本.2,在弹出的对话框中进行设置单击全部显示选中编写全部对象脚本复选框(当然你也可以跟据情分别选择)设置格式选项卡中前两项要选中其它的跟据你的需要.选项的选项卡

Inception@Blog 3451

HFSS实战项目——高带外抑制特性SIW带通滤波器

本文对单级滤波器和双级滤波器的设计、工作原理及仿真结果进行了详细分析,并验证了双级SIW带通滤波器在性能方面的优越性,为微波通信系统中滤波器的设计和应用提供了重要参考。

2401_87464239的博客 1822

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

.net中sql脚本的执行

    如下:    using System;using System.Xml;using System.Data;using System.IO;using System.Collections;using System.Data.SqlClient;namespace ExecuteSqlFile{ ///  /// DBAccess 的摘要说明。 ///  public class D

Augmentum-Casper的专栏 1038

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

在.net中执行SQL脚本

本文章主要是摘自网上发表的文章,加以整理而成。 一,osql.exe osql.exe 可以执行基于ODBC驱动的数据库脚本。假设使用sqlserver2000 具体方法如下(以sql server200 数据库为例): try { System.Diagnostics.Process pr =...

RONG8903的博客 429

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

.net执行SQL脚本文件

//执行脚本文件 protected string proceedSQLScripts(string connectionString, string pathToScriptFile)     {         List statements = new List();         using (Stream stream = File.OpenRead(pathToScri

cyb331的专栏 787
上一篇: 在.net应用程序中使用用户控件
下一篇: 通过vs.net数据窗体向导看Ado.net
marvelstack
博客等级 码龄23年 515粉丝 75原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值