I am trying to execute a script (.sql file) on a database from a C# Windows application. The SQL file contains 'GO' statements; this means I am using the object SMO.
I am trying to continue on error and also log any error which might occur during the execution of the script on the database. Is there any way to do this?
This is the code I'm using:
using (SqlConnection sqlConnection = new SqlConnection(connectionString))
{
ServerConnection svrConnection = new ServerConnection(sqlConnection);
Server server = new Server(svrConnection);
string script = File.ReadAllText("upgradeDatabase.sql");
try
{
server.ConnectionContext.ExecuteNonQuery(script, ExecutionTypes.ContinueOnError);
}
catch (Exception ex)
{
//handling and logging for the errors are done here
}
}
Any help is appreciated!