SQL Server Default Backup(s) Location- Using DENALI SSMS/2008R2

Have you ever been in a situation thinking, why MSFT did not included an option to change default backups location in SSMS? Well, I was in few cases!! The good news is they’ve given that Option in DENALI SSMS….Yes Guys you heard it right!! So no more digging into Scary Registry values to change those settings 🙂 In this post let’s see how this can be achieved now running on 2008R2(This applies to SQL 2005/2008 and 2008R2) and also..let’s see how to tweak this option even on earlier Versions of your SQL Server using DENALI SSMS without getting our hands dirty touching Registry values 😉

If you recall correctly, while installing SQL Server It’ll ask for all the Data, Log, TempDB and Backup locations. Changing the TempDB files location is pretty simple, can be done just by Alter Database/Modify File and restarting your SQL Instance. Changing Default Database Files(mdf and ldf) files location is also pretty much simple, Just Right click on your Instance in SSMS and select Properties and navigate to Database Settings as shown below…

But……….where can i look and change the default Default Backup Location???  By navigating to the below registry entry

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.PROD\MSSQLServer

In this case I’m looking at my “PROD” Instance. Similarly  If i want to verify/change my “DR” Instance backup location, I can simply go to MSSQL10_50.DR and do the same. This might change accordingly for your SQL Instance.

That was little bit annoying right??? Well, it really depends on how comfortable are you with dealing with registries!! Okay! Now let’s see how this can be achieved using DENALI SSMS without pain.

Verifying/Changing Default Backup Location in DENALI:

Open your DENALI SSMS and connect to your DENALI Instance and RC and Properties at Instance level and navigate to Database Options, Interestingly You can see an added option below your Database Files location(s) as shown below

Let’s change the Backup location from SSMS and let’s also see how the registries are being changed behind the scenes.

Registry before Changing Backup Location:

Changed Backup Location from DENALI SSMS:

Registry After changing Backup(s) Location:

Awesome!!!!!!!!!!!!! Interestingly, you can also just connect to your SQL Server 2008R2 Instance from DENALI SSMS and change your default backup Location for your SQL Server 2008R2. Huhuuuuuuuuuu.

Let’s see how it works. I’ve connected to my PROD Instance which is SQL Server 2008R2 version from DENALI SSMS as you can see below and i changed the default location to D:\Backs.

Nowww……Let’s see how our Registry Value looks like for our 2008R2 PROD Instance.

Tadaaaaaaaaaaaaaaaaaaaa!!!!!! 🙂 🙂 🙂
For me this is one of the Most Interesting enhancements with DENALI SSMS. Can’t express how impressed am i with this little thing:)

Bottom Line : Using DENALI SSMS you can change the Default Backup Location for your SQL Server DENALI Instance as well as SQL Server 2008R2 Instance without digging into Registry Values.

Setting up Email Alerts for PBM(Policy-Based Management) Policies

PBM(Policy-Based Management) – One of the most fancy terms which we(the fantastic SQL Server DBA’s) are listening starting SQL Server 2008. In this Blog post I’m not going to explain in detail what PBM is how exactly it works, instead I’m going to show how to create a Policy for checking Auto-Close, Auto-Shrink,Compatibility Level and Recovery Model of all the databases on a regular basis and how to setup email alerts if any of our databases are violating our policy.

For detailed explanation on PBM PS http://msdn.microsoft.com/en-us/library/bb510667.aspx

As i mentioned in my previous post, setting up DB Mail profile is mandatory for sending email alerts from SQL Server. Okay, enough blabbering..let’s get started!

As the first step, under “Management” Node in your OE(Obj Explorer) expand “Policy Management” and RC on “Policies” and choose create “new policy” as shown below.

Note: You can create conditions first and choose them accordingly for any future policies as well. In this post, I’m going to create everything from Create new policy Option it self, which avoids confusion for people who are new to PBM.

Name your Policy and select “create new condition” to create one as shown below.(you can pick from here if you’ve already created one in the past as mentioned in the above note)

Once, you click on “create new condition”, you’ll be welcomed with a new screen as shown below. Give any appropriate name for your condition and choose one facet from the drop down as shown below. I this case I’ve to choose Database Options Facet, because i’m creating a policy to evaluate DB Options.

select all your required options and create an expression using And/OR, Drop down Menus as shown below and Click OK. You can add your own description if you need any under “Description” tab.

Once done, now you have choose your targets(I selected against every Database) and evaluation mode(I’ve selected on schedule and created one to run/evaluate on daily basis) as shown below.

Once done..you can add your own description(optional) and click Ok. At this point we are all set with setting up a policy which runs on a daily basis to evaluate all our conditions.  Let’s try to evaluate manually and see how it looks.

Go to your policy node and RC and select Evaluate(Enable the policy if it’s disabled). You’ll be welcomed with the below screen which is very much self explanatory…

You can click on View to see more details on the violation and also you can click on Apply to fix them all from right here with a single button click.

Configuring Email Alert:

Soo…we haven’t configured email alerts yet upto this point. To achieve this , the simple trick is to know the exact Error Number(s) which PBM generates in our Error logs and to setup alerts/actions for those Error Numbers in our SQL Server Agent. As per BOL the below are the error numbers which we’ve to look for when setting up alerts for PBM

Execution mode Message number
On change: prevent

(if automatic)

34050
On change: prevent

(if On demand)

34051
On schedule 34052
On change 34053

To double check, Let’s see our SQL Error Log and Event Viewer what has been logged…

Okay…..a message has been logged with eventID 34052. So…now let’s configure Alert to notify operator from SQL Agent for this Error Number.

FYI..I already created an Operator as you can see below

Okayyy…it’s time to create Alert. Follow the below Screen shots in the same order

Choose Error Number as shown below

DO NOT JUST CLICK OK now….Instead go to RESPONSE tab and choose an operator whom you want to notify for this Alert based on this Error Number as shown below.

 

Again, don’t just hit OKinstead go to Options and enter a customized message which you feel appropriate for you as shown below

Now click OK:) and let’s try to evaluate our policy manually as we did earlier(Go to your policy node under Management in your Object Explorer and RC and select Evaluate) for testing our policy initially and let us see what we’ve in our Inbox.

Perfectttttttttttt………!!! See how simple it is…to make yourself a hero with all these cool automation stuff 🙂

Hope this Helps!!

 

 

 

 

 

Configuring SQL Server DB Mail to send emails to your Gmail/Yahoo Mail.

Though this is a very old topic; DB Mail being introduced in SQL Server 2005 replacing annoying SQL Mail, i would like to brief about this topic because………………….

Well, i was configuring alerts using PBM(Policy Based Management) on one of our brand new SQL Server 2008R2 Instances today in such a way that if any policy has been violated, SQL Will send an email to our DBAops Group. I will cover this topic in upcoming posts! Prior to this, for SQL to be able to send email notifications, we’ve to configure DB Mail.  In this demo let’s see how to send emails from SQL Server to Gmail. you can test alerts, operators, notifications, log shipping/Mirroring notifications, Job failure notifications and what not……(Basically you can simulate a real environment at home to learn things) on your own Personal laptop where you are trying to learn and explore new things within SQL Sever.  why to wait?? Let’s proceed…then

First of all of course you need to have a GMAIL account 🙂 . If you don’t want your personal email account for SQL Server sending alerts, create a test account for this purpose. I did the same under the name sqlssms1@gmail.com

Note – Gmail smtp sever: smtp.gmail.com

Go to your Account Settings and make sure that POP is enabled for your account as shown below.

Save your settings and you can sign off from your GMail. Now, let’s go to your SQL Server and very first thing which you’ve to make sure is your DB Mail XP’s are enabled. Just Query sp_configure ‘database mail’ and make sure that the running value returned  is ‘1’ as shown below. Also, Service Broker should be enabled on MSDB Database. You can execute select name,is_broker_enabled from sys.databases where name = ‘msdb’ and make sure that “1” is returned.

Go to your Object Explorer – expand Management Node and select Configure Database mail as shown below.

Follow the below in Sequence as shown below.

Next – > and Click on Add to add new SMTP account to the profile as shown below.

Once you select Add, you’ll be welcomed with the below Screen, where we’ve to configure our account details and provide the smtp details for gmail.

Things to note in the above screenshot: Gmail Requires SSL to be checked and Port 587. Now Select Next and I’ve chosen this as my Default Public Profile as you can see below.

Select next->Next-> and Finish and you’ll be seeing a success message as shown below.

That’s all we need to do for configuring your DB Mail on SQL Server. Now, let’s see by sending a test email from SQL Server. Please see the below screenshots…

I’ve entered the same gmail account for testing purposes, and you can see the email being delivered to my Inbox as shown below…

Tadaaaaaaaaaa!!! That’t it Guys…..All I can say is, now you are all set to play with all your Automated(SQL Agent Jobs) stuff , create Operators, configure in such a way that SQL will send you notifications to the operator. Now it’s all yours!! In the upcoming Post, Let’s see how can we configure PBM to send email alerts, if any of the  policies has been violated.

Hope this info is useful..Cheers!!

SQL Server Configuration Manager/Startup Parameters 2008R2 vs DENALI

Things we should be Aware of in SQL Server DENALI Configuration Manager, A Small simple change which might make a huge difference!

Before proceeding any further, let me make it very clear….for any changes to me made on any of the SQL Server Services you’ve to make use of SQL Server Configuration Managernot our typical windows services from administrative tools. 

I’ve seen in the past(still seeing few folks doing the same even now!!) where people going to “RUN” and entering “services.msc” for changing SQL Server Service accounts, Start Up type etc….Hope you are not doing the same!

Config Manager in SQL Server 2008R2:

Okay, Let’s jump into Config Manager in SQL Server 2008R2, when you choose properties of SQL Server Engine we’ll be getting what is shown in the screenshot below.

This is the place where we’ve to change the Service accounts and pwd’s. You can change the Start Mode(Automatic/Manual/Disabled) in the Service Tab. For adding any start up parameter, you’ve to go to your advanced Tab as shown below.

Configuration Manager in DENALI:

See the screenshot below and if you see carefully, you’ll notice a new tab for startup parameters!

Basically, DENALI has 2 new tabs, one for Brand new fabulous feature “AlwaysOn HA” and the other for “Starup Parameters”.  Let’s see what’s present in my AlwaysON tab…

Well, I’ve Installed this Instance of DENALI on my WINDOWS 7 x64 Client OS which is a stand alone, hence unfortunately, I can’t show you much about this setting here 😦  (I’m planning to Install DENALI on my LAB Cluster pretty soon to explore and learn this brand new HADR feature of DENALI…yayyyyyy)

Let’s move on to Starup Parameters Tab, You can see the brand new interface as shown below.

IMHO, this makes all of our(DBA’s) lives much easy dealing with those annoying semi-colons “;” and Spaces where we should be very very cautious upto SQL Server 2008R2. A single space will change the entire behavior of your startup parameter(s).

Let me show you how we can add a trace flag as a starup parameter in DENALI. Let’s try to enable Trace Flag 3226  as a start up parameter to disable all the successful backup events being logged in our error logs.( See here if you want to know how you can enable a trace flag globally instead of making it a startup parameter). All you need to do is Just typing “-T 3226” and click Add ->Apply->Ok (Service restart is required to reflect the changes) as shown in the below screenshot.

If you want to Update any parameter, all you need to do is Just click on the parameter which you want to change and make changes and click on Update Button. ( The Add button will change to Update button once you select any parameter as shown below).

In the same manner you can remove any Startup parameters which you’ve added.

This greatly reduces pain in our Butt dealing with Spaces and Semicolons( I’m sure that almost everybody agree with me in this matter, especially who’ve already faced an issue and wasted time(like me when i was a Novice in SQL)  figuring out what’s wrong with the parameter provided and banging head to your desk, OMG! why this SQL Server is not starting up as expected 😦 )

Hope this post helps!

SQL Server Default Ports

Most of the times…We, the DBA’s are concerned about the TCP port which SQL Sever is running under and UDP Port under which Browser service is running under. So…what about the rest of the SQL Services? What is the Def port for SSIS? How about SSAS?

Thought of keeping all together in a single place which might be helpful. (I can use my own post as a single point of reference myself ;p)

Default Ports for SQL Server Services:
SQL Server Default Instance – TCP 1433
SQL Server Browser Service – UDP 1434
SQL Server DAC (Dedicated Admin Connection) – TCP 1434
–You can look into SQL Server Error logs at Start up for this. Eg: sqlcmd –Stcp:<server>,<port> or sqlcmd –S127.0.0.1,1434(if your SQL Server is configured to use only Local DAC Connections).
SSIS/MSDTC/T-SQL Debugger/RPC – TCP 135
SQL Server Service Broker – TCP 4022
SSAS – TCP 2383
SSAS Browser Service – TCP 2382

References:
http://support.microsoft.com/kb/968872#LetMeFixItMyselfAlways

Note: These are the default Ports which comes with the default Installation of your SQL Server. They can be always reconfigured as required. In fact, Default Port 1433 should be changed and should be included in your SQL build process, Since it is highly vulnerable to attacks.

Let’s see how can we verify our SQL Server Port…..
Verifying Port from T-SQL:
By using the DMV ‘sys.dm_exec_connections’.  This will return the current connection details. I mean, If you are connecting to SQL Server remotely via TCP, it will return the TCP port, If you are connecting locally It won’t return anything since you might be most probably connecting using Shared Memory.(If you explicitly connect to your SQL Server using TCP/IP as your Network Protocol even locally, it will return the TCP port details.)

Please see the below Screen shots which i hope are pretty much self explanatory.

Using Configuration Manager: To avoid the confusion of what network protocol currently you are are on, You can always make use of our SQL Server Configuration manager to verify the port details as shown below.

 

Hope this Post is Useful!