I don't like to use osql.exe, isql.exe, although N earlier, use Osql.exe to query the SQL Server server in the LAN. ADO.NET is enough. As long as "Go" is filtered. As follows: use system; using system.data; using system.collections; using system.data.sqlclient;
Namespace ExecuteSqlfile {///
#region attribute
Private static string constr = ""
private static string ConString {get {if (ConStr == "") {try {XmlDocument doc = new XmlDocument (); doc.Load ( "ServerConfig.xml"); string userid = doc.SelectSingleNode ( "ServerConfig / UserId") .InnerText; string password = doc.SelectSingleNode ( "ServerConfig / passWord") InnerText;. string servername = doc.SelectSingleNode ( "ServerConfig / ServerName") InnerText;. string database = doc.SelectSingleNode ( "ServerConfig / DataBase") InnerText. Constr = "Server =" servername "; uid =" userid "; pwd =" password "; database =" Database;} catch (exception ex) {throw ex;}}
Return constr;}}
Private static sqlConnection con;
Public static sqlconnection myconnection {get {if (con == null) {con = new sqlConnection (constring);} Return Con;}} #ENDREGION
///
String commandText = ""
String varline = ""
While (sr.peek ()> -1) {varline = sr.readline (); if (varline == ") {Continue;} if (varline! =" go ") {CommandText = varline; commandText = "/ r / n";} else {alsql.add (commandtext); commandtext = "";}}
Try {EXECUTECOMMAND (ALSQL);} catCh {return false;}
Return True;}
Private static void executeCommand (arraylist varsqllist) {myconnection.open (); sqltransaction varratrans = myconnection.begintransaction ();
Sqlcommand command = new sqlcommand (); command.connection = myconnection; command.transaction = vartrion;