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 1029619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:34:22+00:00 2026-05-16T12:34:22+00:00

My first post here, please be gentle. =) I work for a company that

  • 0

My first post here, please be gentle. =)

I work for a company that inherited the maintenance of a bespoke system used by one of our customers. The previous developer (no longer with us) encrypted all the database objects (WITH ENCRYPTION).

The system has been plagued with various timeout issues well before we took ownership of it, and we want to get to the bottom of these.

The database is on SQL Express 2005 in production. We want to run the profiler on it but because the various objects are encrypted, most stored procedure calls etc.. show up as ‘– Encrypted Text’.

Not very useful. I’ve written a little console app in C# to decrypt all the database objects, which works perfectly as far as I can tell

It finds all encrypted objects in the database and for each one, decrypts it, removes the with encryption clause, drops the original and recreates it using the new ‘without encryption’ text.

There are some computed columns that get dropped before trying to decrypt the functions that are used in their definitions, then get recreated.

What I’m finding is that once everything is decrypted, I can’t get into the system because the stored procedures etc.. take far too long to run on their first call. Execution plans are being compiled for the first time, so some delay is understandable, but we’re talking 1 minute plus.. after 30 seconds the command timeout is hit, so the plans never get compiled.

I also have the same issue if I drop and recreate the database objects using their original scripts (keeping the WITH ENCRYPTION clause in).

So there’s some consistency there. However, what absolutely mystifies me is that if I drop the execution plans from the original copy of the database (which was created from a backup of the production database), the same stored procedures are much faster. 10 seconds for first call. As far as I can tell, the stored procedures, functions etc.. are the same.

From my testing, I don’t think it’s a particular procedure or function that is causing the problem. It seems like the delay is cumulative, the more objects I drop & recreate the slower things are.

I’ve taken a few random stabs in the dark, rebuilding indexes and updating stats – this has had no effect at all.

We could write something to execute all 540 functions, triggers, sprocs etc.. to pre-empt the first real call from a user, however once SQL server is restarted (and our client does restart their server from time to time) the execution plans will be dropped and we’d need to run the same tool again. To me it doesn’t seem a viable option (neither is increasing the CommandTimeout property), I want to know why I’m seeing this behaviour.

I’ve been using sys.dm_exec_query_plan and sys.dm_exec_sql_text to look at the execution plans, and using DBCC DROPCLEANBUFFERS and DBCC FREEPROCCACHE as part of my testing.

I’m totally stumped, please help me before I jump out the office window.

Thanks in advance,

Andy.

–EDIT–

I don’t quite know how I missed it, but the Activity Monitor is showing a session being blocked by a recompile of a table valued function. It takes far too long to compile and the blocked query hits the timeout.

I don’t understand why in original version of the database (restored from backup taken from the customer site), the compilation takes around 10 seconds, but after dropping and recreating these objects in the same database, the table valued function takes almost a minute to compile.

I’ve tried truncating the log, which didn’t have any effect. I still need to have a look at the file sizes.

— Another edit —

The TVF returns a temporary table, and has 12 outer joins in the query, all on either sys.server_principals or sys.database_role_members.

I seem to remember reading something about recompiles and temporary tables, which I’ll have to check again..

  • 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-16T12:34:22+00:00Added an answer on May 16, 2026 at 12:34 pm

    Turns out that if I pass the parameter of the TVF to a variable, then replace where the original parameter was used, normal service is resumed (query takes less than a second, instead of a minute!)

    Some kind of parameter sniffing shenanigans going on, I don’t really understand why though – at the point I’m trying to call the function, no query plans exist, good or bad.

    I’m in contact with Microsoft on this one (first time I’ve ever used my MSDN support entitlement) so hopefully we’ll find out more and I’ll post what I’ve discovered.

    Thanks all for your help, we’re getting there!

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

Sidebar

Related Questions

First post, so here goes. I'm writing a script that does intelligent search and
This is my first post, so please be gentle. I've been playing around with
This is my first post on StackOverflow, so please be gentle... I have some
This is my first post here and I wanted to get some input from
Well, this is my first post here and really enjoying the site. I have
first post here, I come in peace :) I've searched but can't quite find
This is my first post here and since I've seen many great answers I
first post don't hurt me :) I am using a BorderLayout with the usual
This is my first post and I'm quite a novice on C++ and compiling
First, let's get the security considerations out of the way. I'm using simple authentication

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.