I have two scripts that are called in one program, the first script creates a database, and the other is a script to fill the database.
How to know if the first script is finished before launching the second one?
How to wait for second script that the first notice that the process is over? How can server inform the creation of the database program and then proceed with further work?
Code
string createDatabasePath = args[0];
sqlConnectionStr = Properties.Settings.Default.conString;
SqlConnection conn = new SqlConnection(sqlConnectionStr);
conn.Open();
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
FileInfo file = new FileInfo(createDatabasePath);
string script = file.OpenText().ReadToEnd();
script = script.Replace("GO", "");
comm.CommandText = script;
comm.ExecuteNonQuery();
My problem is when executenonquery finiched?how I know ?
We need to know what “in one program” means – is that a set of T-SQL commands or a C# application, etc.? However, the easiest way to make sure one is done before the other is just to combine them into a single procedure, or have the first one call the second one:
A more complicated option is to alter the second process to check that the new database exists and WAITFOR some time until it’s complete: