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

  • SEARCH
  • Home
  • 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 6911365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:56:40+00:00 2026-05-27T08:56:40+00:00

I am trying to force SMO to schema qualify object names for stored procedures,

  • 0

I am trying to force SMO to schema qualify object names for stored procedures, UDFs and views, but for some reason it doesn’t work. I have got a stored procedure without a schema and need to have the default schema pre-pended to it:

I have this code:

var procs = from sp in _smoDB.StoredProcedures.OfType<StoredProcedure>()
              where !sp.IsSystemObject && !sp.IsEncrypted
              select sp;

foreach ( StoredProcedure sproc in procs ) {

    var script = sproc.Script( ScriptOption.SchemaQualify );
    var scriptText = script[3];

}

When I access the script text it isn’t putting the schema name (dbo) in front of the stored prcocedure. Can anyone explain this?

  • 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-05-27T08:56:41+00:00Added an answer on May 27, 2026 at 8:56 am

    I haven’t worked with SMO in 2008/R2 (only 2005), so I may be missing something, but here’s what’s I’d try:

    var procs = from sp in _smoDB.StoredProcedures.OfType<StoredProcedure>()
                where !sp.IsSystemObject && !sp.IsEncrypted               
                select sp; 
    
    var options = new ScriptOptions();         // reusable ScriptOptions object
    options.SchemaQualify = true;
    options.EnforceScriptingOptions = true;    // surprise!
    foreach ( StoredProcedure sproc in procs ) 
    {
        var script = sproc.Script( options );     
        var scriptText = script[3];  
    }
    

    (I haven’t tested this)

    I’m guessing the stored procedure was originally created without specifying the schema, and that is what is being scripted. To get a schema-qualified script, you’ll need to enforce the scripting options and will lose any comments and formatting (here’s the article from MSDN).

    I believe this will apply to Views and Functions as well.

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

Sidebar

Related Questions

I'm trying to force ssl on certain pages, but also on a directory. But
I'm trying svn add *.py --force As the documentation suggests , but I know
I'm trying to force Django to always store numbers with 2 decimal places but
I have been trying to force images to download using PHP Headers but there
I am trying to force one animation waiting for the other, but without luck.
Possible Duplicate: (static initialization/template instantiation) problems with factory pattern trying to force static object
It's probably something obvious, but when I'm trying to force the user to keep
I am trying to force HTTPS on a domain. It must be done using
I'm trying to force an inherited class to use a custom attribute. I'm creating
I am trying to force an iframe to the exact same height as the

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.