Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8708683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:11:45+00:00 2026-06-13T04:11:45+00:00

I have a SQL Sever 2008 R2/64-bit database server for which I’m writing some

  • 0

I have a SQL Sever 2008 R2/64-bit database server for which I’m writing some fairly basic scripting utilities with the Sql Server Management Objects (SMO). My project is a 32-bit VS2010 executable written in C#.

Most of the effort has been fairly simple and successful. The only problem I’m having is in the firing of my custom event handler that should be called in response to a Scripting Error.

The Scripter object exposes a ScriptingError event, which I have attempted to leverage thusly:

//srv contains a valid server name
Scripter scrp = new Scripter(srv);

//scrp_ScriptingError is my handler
scrp.ScriptingError += new ScriptingErrorEventHandler(scrp_ScriptingError); 

My handler is declared thusly:

   static void scrp_ScriptingError(object sender, ScriptingErrorEventArgs e)
   {
       // my handler goes here, just printing e.Current.Urn to the console
       // This is merely representative, have had other things here, but
       // the handler never fires
       Console.WriteLine(e.Current.Value);
   }

All this compiles cleanly.

My code is invoked via simple scrp.Script(urns); where urns is just an array of the database objects being scripted out. Nothing fancy:

    try
    {
        sc = scripter.Script(urns);
    }
    catch (Exception e)
    {
        WriteLog(String.Format("Failure during scripting: {0}: Inner exception message (if any): {1}",e.Message,((e.InnerException==null)?"[None]":e.InnerException.Message)));
    }
    using (System.IO.StreamWriter file = new System.IO.StreamWriter(fileName,true))
    {
        foreach(String currentLine in sc)
        {
            file.WriteLine(currentLine);
            file.WriteLine("GO");
        }
    }

The problem is that, no matter what I’ve tried so far, when errors occur during scripting, my ScriptingError handler never fires.

Even in debug mode within VS2010, when I set a breakpoint within the handler, and fire my scripting code, and know an error will occur, only an exception will be thrown, but the breakpoint in my ScriptingError handler never trips.

I’m in trees-for-forest mode now, not sure what I’ve done wrong. Am I expecting the wrong things for the ScriptingError handler?

I have searched the MSDN docs on the SMO objects and found virtually nothing on ScriptingError handlers other than the basic API calls themselves, and precious few examples on the Internet. It seems incredibly simple and straightforward to me – just assigning an event handler to the event – but there’s some battery-not-included notice I’ve failed to note.

Pointers to my error are greatly appreciated, with a polite request for minimal brickbats if the error is exceptionally stupid on my part 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:11:47+00:00Added an answer on June 13, 2026 at 4:11 am

    I am not at a pc right know, but I think you should try to set the ContinueScriptingOnError option. Otherwise there would be no reason for SMO to invoke the event, but rather through an exception instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an EMPLOYEE table in a SQL Server 2008 database which stores information
I have a bit column in the SQL Server 2008 database and I am
I have a simple database table (SQL Server 2008 R2 Express), which has a
I have SQL Server 2008 Ent and OLTP database with two big tables. How
I have created SQL Server 2008 Database project using visual studio 2010. after build
I have an SQL Server 2008 database with a table that has a column
I have a SQL Server 2008 database. This database has a column that represents
Database: SQL Server 2008 I need to produce a sales report which groups sales
I'm experiencing something a bit strange. I have a table on SQL Server 2008,
I have a payment table in a SQL Server 2008 database, this holds both

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.