Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Location
    Argentina
    Posts
    58

    Question Unanswered: run script files from c# and listen for output

    Hello, is it possible to run sql script files from c# and listen to messages?
    Code:
                       foreach (string aScript in scripts)
                        {
                            if (File.Exists(aScript))
                            {
                                txtProgress.Text += Environment.NewLine + " Run script: " + aScript + " - Start time: " + DateTime.Now.ToString() + Environment.NewLine;
    
                                __streamReader = new StreamReader(aScript);
                                __myQuery = __streamReader.ReadToEnd();
                                __cmd.CommandType = CommandType.Text;
                                __cmd.CommandText = __myQuery;
                                __cmd.CommandTimeout = 5000000;                           
                                __rc = __cmd.ExecuteNonQuery();
                                txtProgreso.Text += Enviroment.NewLine; // MESSAGE HERE
                                __streamReader.Close();
                            }
                        }
    I tried with
    Code:
                 // Create a SqlNotificationRequest object.
                    SqlNotificationRequest notficationRequest = new SqlNotificationRequest();
                   
                    // Associate the notification request with the command.
                    __cmd.Notification = notficationRequest;
    But I get an error saying I need SQL 9 or later, aldo SQL 2005 Express says it΄s version 9

    Is there another way?
    Thanks!

  2. #2
    Join Date
    Mar 2008
    Location
    Tacoma, WA
    Posts
    11
    Personally, I would rewrite the C# code to parse each line of each script and execute a SqlCommand object for each line that starts with insert, update, delete and maybe select. If they are transactional statements, in each script then this will be a little bit harder but should be do-able.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •