Fixing Slow SQL Server Management Objects (SMO) Performance

Just recently I’ve been converting a small utility that uses SQL-DMO to use SQL-SMO instead (SQL-DMO is deprecated in SQL Server 2008 R2; if you really need to use it, install the Backward Compatibility Components from the SQL Server 2008 Feature Pack from the Microsoft Download Centre). Remembering all those posts saying how slow SMO was compared to DMO, a colleague mentioned this:

 

SMO has the concept of Delayed Instantiation of Object Properties. The concept consists of not returning every property of a database object when the object is requested. Some properties, like the StoredProcedure’s IsSystemObject property, are not returned by default when you request a Stored Procedure or a collection of Stored Procedures from the Database. It is only when you explicitly access the IsSystemObject property that SMO goes back to the database to get its value.

[…]

 

If you find your SMO code is running slowly, use SQL Profiler to check whether you are accessing properties that are not returned by default and creating extra roundtrips to the database. Force SMO to load those properties by default by using the Server.SetDefaultInitFields method:

            Server server = new Server();

// Load all properties for columns
 server.SetDefaultInitFields(typeof (Column), true);

// ...or load all properties for all objects
 server.SetDefaultInitFields(true);

To build an SMO application, you need to reference the SMO assemblies. Click ‘Add Reference’ and navigate to the folder

C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies

Add references to:

  • Microsoft.SqlServer.ConnectionInfo.dll
  • Microsoft.SqlServer.Smo.dll
  • Microsoft.SqlServer.Management.Sdk.Sfc.dll
  • Microsoft.SqlServer.SqlEnum.dll

(These are the minimum files that are required to build an SMO application)

Ref.: How to: Create a Visual C# SMO Project in Visual Studio .NET

Improving SQL Server Management Studio’s Tabs

I saw this post by Brent Ozar, Fixing SQL Server Management Studio’s Tab Text, and immediately made the changes whilst face palming myself and going “D’oh!” at the same time. 

What are the improvements? First, the status bar is moved to the top of the tabbed window space, where your eyes are normally focused. Second it removes the server name, database name and login (which are all in the status bar anyway) from each tab title so that you can actually navigate around the tabs!

It’s been a constant source of frustration over many years of using SSMS, and I feel chastised for not investigating the options before. Nice one Brent!

MVC Mini Profiler

If you are working with ASP.NET MVC 3 you might be interested in this project: the mvc-mini-profiler. It includes standard profiler timing output but also comprehensive database profiling capabilities.

MVC Mini Profiler was designed by the team at Stack Overflow, and is actively being used there to monitor the Stack Exchange family of sites.

Visual Studio 2010 Web Standards Update

Visual Studio 2010 Web Standards Update is a free extension available for anyone who is using Visual Studio 2010 SP1 and it provides HTML5 & CSS3 support based on current W3C specifications.

It supports:

  • HTML5 – Video, Audio, Input Type, Drag & Drop, WAI-ARIA, Microdata, Schema.org
  • Browser API – GeoLocation & Local Storage
  • CSS3 – 2D Transforms, 3D Transforms, Animations, Background & Borders, Basic Box Model, Basic UI, Behaviour, Colour, Flexible Box Layout, Fonts, Paged Media, Hyperlink Presentation, Line, Lists, Marquee, Media Queries, Multi Column, Namespaces, Presentation Levels, Ruby, Selectors, Speech, Syntax, Template Layout, Text & Transitions. It also supports vendor specific prefixes like –ms, -webkit & -moz.

Note: This extension is created by a bunch of folks within Microsoft in their spare time. This is NOT an official Microsoft product

Scott Hanselman blogged about it here.

You can download here: Web Standards Update for Microsoft Visual Studio 2010 SP1

Who’s Your Product?

Love this quote, which sums up the model of companies like facebook, google etc.:

“If you are not paying for it, you’re not the customer; you’re the product being sold.”

Originally(?) appeared here and quoted many times since.

Perth .NET User Group, Thurs June 2nd: Good Things Come to Those Who ‘await’ with Joe Albahari

Join us at the Perth .NET user group, June 2nd 5:30pm, where Joe Albahari will showcase the magic of C# 5’s await and async keywords. You’ll see how easy asynchronous programming has become with Microsoft’s latest CTP, and how much you can achieve without being a guru in multithreading or monadic calculus.

We’ll start with very simple examples to introduce asynchronous programming in general: what exactly is it, how does it differ from multithreading, and why do we need it? Then we’ll examine the historical support for asynchronous programming in the .NET Framework and what people are doing right now. You’ll see why BackgroundWorker and the event-based pattern are clumsy and often inadequate – and how the APM strikes fear, pain (and ultimately asynchrophobia) into the hearts of the even most hard-core programmers. We’ll then demonstrate how the async CTP eliminates the problem almost entirely – allowing you to program as you always have.

  • TOPIC:  Introduction to C# 5 async with Joe Albahari
  • DATE:   Thursday, June 2nd, 5:30pm – 7:00pm
  • VENUE: Enex 100 Seminar Room, Level 3, 100 St Georges Terrace, Perth
  • COST:   Free. All welcome

There will be plenty of practical examples – from making a rich client app responsive to writing high-concurrency apps and games. We’ll also cover limitations and discuss when you would use this versus Reactive Extensions. The presentation will assume minimum background knowledge and yet will go fairly deep. We’ll also look at what the compiler actually does in translating asynchronous calls, and potential extensibility points. This is a great chance to get to grips with an otherwise difficult-to-research topic.

Joe Albahari is a C# MVP and author of C# 4.0 in a Nutshell and LINQPad. He has presented at TechEd and JAOO, and is a regular speaker in the Perth .NET UG. He has an extensive free online resource on .NET multithreading and parallel programming at www.albahari.com/threading/