Execute the batch processing file (. bat) in C # And perform database operations,

Source: Internet
Author: User

Execute the batch processing file (. bat) in C # And perform database operations,

Using System; using System. collections. generic; using System. linq; using System. text; using System. threading. tasks; using System. configuration; using System. data. sqlClient; using System. data; using System. diagnostics; namespace Sample2 {class Program {static void Main (string [] args) {Process proc = null; try {/** autorun. bat file content osql-S 127.0.0.1-d DataSample-U sa-P 1234567890-I C: \ test. SQL */string targetDir = string. format (@ "C: \"); proc = new Process (); proc. startInfo. workingDirectory = targetDir; proc. startInfo. fileName = "autorun. bat "; proc. startInfo. arguments = string. format (""); // this is argument proc. startInfo. createNoWindow = true; proc. startInfo. windowStyle = ProcessWindowStyle. hidden; // The DOS window is not displayed here. It is feasible to use proc. start (); proc. waitForExit (); Console. readKey ();} catch (Exception ex) {Console. writeLine ("Exception Occurred: {0}, {1}", ex. message, ex. stackTrace. toString ();}/* test. SQL content USE [DataSample] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo]. [Area] ([AreaId] [int] IDENTITY (1, 1) not null, [AreaName] [nvarchar] (50) NULL, [CityId] [int] NULL, CONSTRAINT [PK_Area] primary key clustered ([AreaId] ASC) WITH (PAD_INDEX = OFF, expiration = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY] GO */}}}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.