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 was running some dynamic programming code (trying to brute-force disprove the Collatz conjecture
I'm trying svn add *.py --force As the documentation suggests , but I know
I have been trying to force images to download using PHP Headers but there
I'm trying to force Safari or IE7 to open a new page using a
I'm trying to force an inherited class to use a custom attribute. I'm creating
I am playing with Microsoft's TreeView control and I am trying to force a
I'm trying to find a way to force Windows to reboot, and I am
I'm trying to use the MSBuild NUnit community task to force tests to run
I am trying to figure out a way to force all of my Interfaces
I'm trying to develop a module for Joomla 1.5 that identifies brute force login

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.