for(int i=0; i < fileDirectories.Count;i++){
string script = File.ReadAllText(@fileDirectories[i]);
string[] singleCommand = Regex.Split(script,"^GO", RegexOptions.Multiline);
StringCollection scl = new StringCollection();
foreach(string t in singleCommand){
if(t.Trim().Length > 0) scl.Add(t.Trim());
}
try
{
int[] result = Server
.ConnectionContext
.ExecuteNonQuery(scl, ExecutionTypes.ContinueOnError);
}catch(Exception e)
{
//whatever
}
}
The objective of this program is to run multiple scripts and if fail, capture the exceptions thrown by SQL SERVER and continue running the remaining scripts.
In order to try out, INSERT PERMISSION has been taken away from DB and hence first query (INSERT query) will fail when being executed on SQL SERVER manually because INSERT PERMISSION been taken away with below Error
The INSERT permission was denied on object 'xxx',database 'xxxxx', schema 'xx'
When running the program, variable result will have value 0 indicating the query failed but however it's not throwing error and being catch at catch? How should I pass the exception given by SQL Server to my console program?
eobject?catchsectionExecutionTypes.ContinueOnError?