Tuesday, April 27, 2010

Policy-Based Management in SQL Server 2008

Some time ago I promissed publishing a post on Policy-Based Management feature in SQL Server 2008. Well, it's time to fulfil my promise! :) This is a rather large post, I hope you find the information it contains useful!

Policy-Based Management is indeed one of the greatest administration features in SQL Server 2008. With this feature you can easily manage one or more instances of SQL Server!

The main concept in Policy-Based Management, is that Policy Administrators can set up policies that are evaluated upon certain events within the scope of the monitored SQL Server instance(s). After setting up the policies, based on certain scenarios, the policies are evaluated and specific actions are automatically performed as set up in the active Policies.

To this end, there are four evaluation modes:
  • On demand - This mode evaluates the policies when explicitly requested by the user.
  • On change: prevent - This mode uses DDL triggers in order to prevent Policy violations.
  • On change: log only - This mode allows Policy violations but it logs each violation using event notification. It logs the violations to the SQL Server logs and Windows Application logs.
  • On schedule - This mode allows the user to schedule (using a SQL Agent job) when the policies will be evaluated.

Let’s get a first look and feel at the Policy-Based Management set up dialogs in SSMS. In the following screenshot you can see the Policy Management module in the Object Explorer in SSMS:
 

  • When right-clicking on Policies you can create a new Policy.
  • When right-clicking on Conditions you can create a new condition and then assign it to an existing or a new Policy.
  • The Facets is a collection of SQL Server objects that allow you to set up conditions and policies against their properties. By right-clicking on a Facet you can create a condition or a Policy.
Note that the Policy Management module falls under Management as its scope is for the entire SQL Server instance. Of course, via the Policies you create, you can evaluate multiple SQL Server instances, certain databases, even certain database objects!

OK! Now let's proceed with an example, showing how we can set up policies based on the abovementioned evaluation modes. For this post, I will be using the "AdventureWorks2008" sample database.

On demand
We right-click on Policies and we select New Policy. We are presented with the following dialog where we provide a name for the Policy and then we either select the check condition or we create a new one. In this case we will be creating a new condition:
 


The next screenshot shows the newly created condition:

For creating a new condition, you must provide a name, select the Facet (in this example) the Stored Procedure, and set the expressions for evaluating the properties you like. In this case we want the condition to track all the stored procedures that their names start with 'sp_'.

We click on the OK button and we are returned to the Policy:

You can see that the Policy now contains the "SPNames" condition we created in the previous step. Also, I set up the Evaluation Mode to "On Demand". Though, this type of condition allows you to select any Evaluation Mode.

The available Evaluation Modes are dependent on the type of the condition. For example there are conditions for which a DDL trigger cannot be executed so the “On change: prevent” mode cannot be selected in such case, etc.

Also, in the “Against targets” list you can target specific databases against which the condition will be evaluated. Additionally, in the “Server restriction” you can select against which SQL Server instances the condition will be executed. Remember: Policy-Based Management allows managing multiple instances of SQL Server!

Now, let’s set the Policy to only evaluate the “AdventureWorks2008” database by clicking on the “In Every - Database” list item. Here’s the new condition for restricting the Policy’s evaluation on the specific database:


We click on OK and we are returned back to the Policy properties dialog:

I will not add a condition for the Server restriction as I am only using a single SQL Server instance for this post.

That’s it! We click on OK and the Policy is ready! As this Policy’s Evaluation Mode has been set to “On demand” we cannot enable it. It wouldn’t make any sense after all. We can only use it by right-clicking on it and selecting “Evaluate”. This is the purpose of the On Demand evaluation mode after all! :)

After running the Policy we get its evaluation results:


From the above screenshot we can conclude that at the time being all stored procedures within the “AdventureWorks2008” database comply with the condition set up in the Policy.

Now, what about adding a new procedure on the “AdventureWorks2008” database having the name “sp_SampleSP”? Let’s do so, re-run the Policy and check the evaluation results!

Here are the results:

Oops, we got an error message by the Policy. Let’s click on [Details] View… to see what’s wrong:


We can see that the Policy reported that the stored procedure “sp_SampleSP” does not comply with its condition of not having stored procedures with names starting with 'sp_'.
The above is a very simple example of what a Policy can do. Imagine what else you can do with Policy-Based Management thus making your life easier! :)

Let’s delete now the sample stored procedure we earlier created. We need to comply after all! :)

On change: prevent
If we want to change the Evaluation Mode of the above Policy to “On change: prevent”, we can double-click on the Policy, change it and then enable the Policy:


Now let’s try to create again the same stored procedure:



As you can see from the above screenshot, the Policy prevented the Database Engine from creating the stored procedure as it does not comply with the naming condition specified by the Policy!

On change: log only
Similarly, we can change the Evaluation Mode of the Policy to “On change: log only”. This will allow the stored procedure to be created but it will also add a log entry in SQL Server Logs and Windows Application Log reporting the violation of the Policy:



On schedule
Last but not least, you can set up a schedule for when the Policy should be executed. This will create a SQL Server Agent job that will execute the Policy at the selected time.

Summary
This post was a very basic example on how you can use Policy-Based Management in SQL Server 2008. You can build really advanced Policy scenarios where you can have multiple Policies and conditions, evaluating a large set of actions in more than one SQL Server instances.

The Policy-Based Management feature in SQL Server 2008 is extremely powerful and allows setting up strict Compliance scenarios ensuring the health and desired structure of the monitored SQL Server instances and the databases that exist within them.

The best way to learn more about Policy-Based Management in SQL Server is to get experimented with it in order to fully realize its potentials.

You can also check out this link for more information on Policy-Based Management in SQL Server.

Until next time!
Read more on this article...

Wednesday, April 21, 2010

The Significance of Technical Communities

So here I am thinking of the next event. Should it be a topic on a new .NET Technology? A topic on a SQL Server 2008 R2 feature maybe? When should I deliver my next webcast? Which is the next local or regional event am I going to attend?

As I am thinking the above, I am also feeling the need to say a few words on Technical Communities. I guess that all people sometimes feel the need to philosophize things a bit.

A few days ago I had the pleasure to attend the Microsoft Regional CEE MVP Summit in Athens, Greece. I had the chance to meet in person with many people whom I only knew through emails and several social media on which we exchanged knowledge, ideas, and generally interacted on technical topics of common interest.

I must say, attending the Summit in Athens, was one of the best experiences of my life. When attending such events, you fully realize what the Technical Community is all about. You interact with great people sharing the passion for technology. You discuss with people sharing common interests on certain areas of technology. You share knowledge and you are glad that you are able to help a person learning a bit more on a specific topic.  You are also glad that this person helps you learning something more on the technology topic of his/her expertise.

So what a Technical Community really is? Is it a mailing list on which you post questions on various technical issues you might be dealing with and wait for answers? Is it a platform on which you collaborate by answering various technical questions? Is it a forum, a blog maybe?

Well, a Technical Community is all the above plus much more. First of all, I believe that it is not just the platform that makes a Technical Community. The platforms and related tools make it easier to exchange knowledge and they have a significant role within a Community. Though, what really makes a Technical Community is the people. It is the people who share a passion for technology and have the willingness to exchange knowledge without requesting anything in return. It is the people who spend hours from their free time for helping others and feels really good for doing so. It is the people who constantly get more educated on their area of expertise and present in events, trying to help other people who are interested on those topics for learning even more, answering their questions and discuss with them. 

A Community is actually an “environment” that helps its members to develop their skills through knowledge exchange via presentations, hands-on labs, online and offline discussions and many other activities. It helps its members to catch up with the latest technologies of common interest easier and more efficiently. It is a “place” where each individual puts effort and time for helping others because he believes in people. A Community is all about people and their need for belonging to a broader group of people within which they can share knowledge, exchange ideas, and share the passion and excitement on technology.

I feel that this is what a Technical Community is all about.
Read more on this article...

Thursday, April 8, 2010

Microsoft DevDays 2010 in Cyprus!

A few weeks ago I got asked to present on Microsoft DevDays 2010 in Cyprus. DevDays is the biggest event in Cyprus for Software Architects and Developers.

This year, the event features many hot topics such as:
  • Visual Studio 2010
  •  Windows Azure and Windows Identity Framework
  •  Interoperability and how to run PHP Applications on Microsoft Platform
  •  ...and much more!
I will be presenting the session with topic: "An Introduction to the ADO.NET Entity Framework and Data Services".  This session is all about data! It discusses how data can be easily accessed and manipulated using the ADO .NET Entity Framework and then how this data can be exposed to the Web using the powerful WCF Data Services.

So if it happens and you are in Cyprus on April 15, make sure you register for the event here and stop by for learning more on state of the art Microsoft technologies! The weather in cyprus is quite good as well! :)

Of course, if you are in another country in Central or Eastern Europe, a DevDays event might be taking place near you! Check out this link for more information!

See you at the event!
Read more on this article...

Thursday, April 1, 2010

Congratulations 2010 Microsoft MVP!‏

Today is a very special day! I am proud to announce that I received the MVP award for the second time in a row!

-------------------------------------------------------------------







Dear Artemakis Artemiou,

Congratulations! We are pleased to present you with the 2010 Microsoft® MVP Award! This award is given to exceptional technical community leaders who actively share their high quality, real world expertise with others. We appreciate your outstanding contributions in SQL Server technical communities during the past year.

-------------------------------------------------------------------

Once again, I would like to thank all the SQL Server community members for making this community a great place for exchanging knowledge and exploring the real potentials of SQL Server and its related technologies! It is awesome being part of this community!

Also, many thanks to Microsoft for strongly supporting the technical communities around the globe!

I would also like to thank the SQL Server Product Group for developing such great technologies and everyone involved in the MVP Award Program.

On my end, as I did last year, I promise that I will keep on doing my best regarding my involvement in the SQL Server community and keep on sharing knowledge!!!
Read more on this article...