SQL Server

PASS Summit 2014 – What to expect

When thinking about attending PASS Summit each year I don’t spend much time deciding. I have not missed a Summit yet and hope I won’t miss one in the future. This post is meant to help those that may be deciding whether or not to go or for those that have decided to go but really don’t know what to expect.

At PASS Summit there are many things to do. The list below resonates in my mind every year:

  • Networking
  • Learning from others
  • Finding those you have not seen and catch up with them
  • Meet new people, your favorite MVP or MCM or just a great figure to finally put a face to the name
  • Learn new things

Some of my favorite Summit experiences include meeting people like (not a definitive list) Kalen Delaney, Paul Randall, Kimberly Tripp, Brent Ozar, and the list could go on. Meeting these people for me was a treat and has made my PASS trips great to reconnect and chat with them and so many others to name off. The PASS Attendee parties are also one of the highlights because it was a chance to talk with peers and some of the famous ones in a setting that was not about database. You learn things like Kalen loves air hockey and some DBAs are really funny, but more than that, you can chat with the leaders of the PASS organization and board members.  These are times I will remember for a very long time.

First Timers

For you first timers, you are in for a treat. This is the first Summit for you and hopefully won’t be the last. For you there is finding and meeting people and speakers that you have seen for many years, maybe, and now they are there to shake hands with and chat with you. They are not untouchable, they are real. Friendly SQL Server Professionals that will actually be willing to chat with you.  There is the Expo where you can see products you have heard about for a while and actually see how they work.  It is NOT all sales and hype, there are actually some very good demos there.  You will always get some sales but this is your chance to get to know the vendors better.  Here are a list of things I would do as a first timer having been through many Summits and I could actually be a great first timer now. 🙂

  • Find out who is presenting and mark the ones that you MUST see and then those that you would like to if the opportunity presents itself
  • BUY THE RECORDINGS, no matter how good of a time manager you are, you will inevitably get overwhelmed with the amount of stuff that is out there and the people who are there, this will give you the opportunity to watch the recorded sessions you missed because you are networking.
  • Did I already mention buying the recordings before the show?
  • Make time for the Community Lounges, SQLCAT Support Center and anything that you cannot get online or in a presentation. Get in front of people and BRING BUSINESS CARDS to give out so that people get to know who you are and they may give you their contact information. BUILD A NETWORK.
  • Go to the MUST see presentations since education is still a huge part of the Summit
  • Attend the Keynotes or watch them, sometimes they surprise you with announcements you won’t get anywhere else.
  • Get to know the Board of Directors of PASS. Hold them accountable as they lead the organization that you are a member of.
  • Investigate opportunities to volunteer for PASS or one day run for the Board.  Passionate people is what makes PASS great, remembering that passion begins with PASS. 🙂
  • Attend the online First Timers presentations that are out there.  I believe there are many but these are great events. I believe that there is even one now onsite at the PASS conference. Get to know what is there for that year.
  • Find the SQL MVPs, they are out there.  These volunteers in the SQL Community have passion towards SQL Server and are always willing to share.
  • Find out who the Microsoft Players are and their role and network with them.
  • Many more things that you can do to enjoy and always want to come back for another Summit.

Preparing for your next experience today

If you begin with the next year in mind, set up the relationships that you will renew each year at the Summit and you will find yourself refreshed and renewed each Summit you attend. Do things to keep in touch with people you meet, like getting their contact information, giving yours out to set up collaboration during the year you are away. I keep all the cards I receive in a place in my backpack and it is amazing how many I have at the end of Summit. Obviously this is not an opportunity for free consulting, but to get a quick opinion or a quick answer to a question, your network is your best friend. The next thing you should do to complete your experience is when you leave Summit, look for the email where registration opens for the next Summit and most often it is a very significant discount to register before the year ends than to wait until the next year. Save some money.  Finally, get to know the players and you will be playing for the rest of your career.

Valuable Lessons Learned

The most valuable lessons I have learned at my PASS Summits I have attended is that people at PASS Summits are real people. They have lives outside of their career and they have failings just like me. I don’t know everything and they don’t know everything, that is why we get together and chat with each other because they share what they have learned and experienced and I do the same, and we come away better for it. The people you meet at PASS and the leaders that lead PASS are just like you and me, they are not better than you or me and we are not better than them, we have just had different experiences and that is what makes a PASS Summit FUN. Swapping stories, learning new things and renewing the PASSion that you have gained for SQL Server and the technologies that surround it.  Chatting with the Microsoft folks and the MCM and MVP crowd can enlighten you in an environment that cannot be replicated at work, take advantage of this opportunity, you won’t regret the time you spend.  But most of all Unwind, HAVE FUN and take it all in, you will be exhausted when you get done, but it will be an experience second to none.

I hope to see you there and hope your experience will be well worth the time. Here’s to all the SQL Community or #SQLFamily out there that will be attending, can’t wait to see you there.

Read More

MCM SQL Server 2008 Achieved

Another step in my career as I have passed the Lab Exam and have become an MCM in SQL Server 2008.  I believed I could achieve it after passing my knowledge exam the first time.

The first attempt at the lab was back in October and it was disappointing to find out that I did not pass the first time. I thought about what I could have done better and determined that I let time get away from me.  I had the experience I thought I needed to do well on the lab exam, but could not get to the point of finishing all the objectives and then there were those that I had not had experience with.  I found myself rehashing my experience to find that important part of getting prepared.  I did not think that study would help enough, so I started with my own lab environment (VM with SQL Server on it) and I ensured that I knew how to work with most of the engine features in BOL and thought of my strategy for the second attempt.

As I reflect on my attempt and prior to that day, I am grateful for the time I took to teach the concepts I was learning in my lab environment, to others. I also love the User Groups in Utah for allowing me to solidify some concepts I felt were important to know and be very familiar with by presenting at the Group meetings.  I may have taken it sooner had I had a study buddy to bounce things off of, but I found that the post from Rob Farley I got a new lease on life for the test.  I was confident in what I knew, but I am not as great in managing my time in scenarios of stress.  It helped to have the test administered via Lync at my house, which was much better than where I took it last time.

The day of the test, the proctors were awesome and took good care of me and explained the process.  They were very understanding and that set my day off to a good start. During the test, I employed some techniques that I learned in preparing, that were all about time management to allow me to get through the Lab and demonstrate what I knew how to do. I think that my time management really helped me the most as I already had the experience I believed I needed to pass the test.

Thanks to all the other MCMs that shared their expertise in presentations, emails and all those that were totally encouraging me to attempt my MCM experience.  But most of all to a supportive manager and employer (www.healthequity.com) that stood by me in the expense and time to take this exam. I am honored to be among the MCMs in SQL Server and looking forward to the road ahead.

Read More

T-SQL Tuesday #39: More Efficient SMO with Server.SetDefaultInitFields

TSQL2sDay150x150 This T-SQL Tuesday is about PowerShell and how I use it with SQL Server. There are many more posts to come about PowerShell and SQL Server but I thought I would cut my teeth on this T-SQL Tuesday since it was on PowerShell.

If you read Rob Farley’s (b | t) post on the SMO topic, I am going to extend it a little and illustrate how you can get a little better TSQL out of SMO by using some things built into the SMO Server object.

The Server object contains a lot of properties and methods, but this post will focus on one called SetDefaultInitFields. This method takes an object and a list of properties that should be retrieved initially when the object properties are accessed. This allows much more efficiency when dealing with collections of items, such as Databases, Tables and Columns.

The code will retrieve me a list of databases with their PageVerify setting and the screenshots will show you what the Profiler output looks like with and without using the Server.SetDefaultInitFields method. Nothing rocket-science, but it will help illustrate that you can help SMO out in the efficiency department.

# This will get the Server object from the SQL Provider
# either by using Import-Module SQLPS with SQL 2012 installed
# or by using Add-PSSnapin SqlServerProviderSnapin100 with 2008/R2 installed
# or by using SQLPS.exe with 2008/R2 installed
# If you load the Module SQLPS with 2012, you don't have to load the 
# SMO Assembly for Microsoft.SqlServer.Smo
# Execute each set in a new PowerShell window to see the same information

# This set will get the list of databases, but will execute the query
# to get the PageVerify for each database (plus much more information)

$server= Get-Item SQLSERVER:\SQL\localhost\default
$server.Databases | Select Name, PageVerify

# This set will get the list of databases and when it does, it will get them with 1 query
# along with the PageVerify at the same time

$server= Get-Item SQLSERVER:SQLlocalhostdefault
$server.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Database], "PageVerify")
$server.Databases | Select Name, PageVerify

Here are the screenshots that show the output in Profiler for each query. Notice that you will see the first set of PowerShell actually gets the data for each database one at a time.  With the second set, you see one query.  The reason is because of SetDefaultInitFields on the Server Object.

First screenshot, shows the retrieval of the Name of the database for one database and you get the CompatibilityLevel for free as SMO will interrogate that automatically for it’s own internal purposes. But you will see that the second screenshot will have a lot more information that it retrieves, just because you asked for one of the properties in a group that SMO has defined. It retrieves it all. Notice on each of these, that it is specifically for the database named ‘Bob1’ and not for any other. Each database will have these 2 queries run for it, and without any help it could be a long process to get 1000 database attributes.

Profiler_1_NoHelp

Profiler_2_NoHelp

Now in the third screenshot you will see that using the second piece of PowerShell in the code, that it issues 1 query and gets all the information in one round trip to the server. Look Mom, no WHERE clause.  Pretty efficient.

Profiler_4_WithHelp

Hopefully this gave you a taste of what you can do to help SMO be a little more efficient and return with less round trips to the server. Do not underestimate the power of SetDefaultInitiFields.

Have a great T-SQL Tuesday.

Ben Miller

Read More

Log Shipping encounters corrupt log backup

I ran into an issue the other day and wanted to ensure that I shared it out there.  In a Log Shipping scenario, you can occasionally run into a corrupt transaction log backup. This causes the database to stay in restoring mode (as mine was previously in a standby/read-only state for reporting), but requires the next LSN to be restored, which you don’t have.

In this case, it went overnight and was out of sync a ways, but at night I do a differential backup of the database.  By restoring the differential backup with norecovery to the log shipped database, it allowed me to continue restoring with log backups from that time on.

Hope that helps anyone in the www realm, it is a nice save since databases can be large and the initialization could be very impactful.

Read More

Get SQL Server Service Accounts with WMI

Today I was tasked with retrieving the SQL Server Service accounts to validate them in Active Directory.  I wanted a simple way to get them and show the account names for each SQL Server service.  I knew that you could get the service in PowerShell with Get-Service.  I also new that PowerShell could get the service with Get-WmiObject –class Win32_Service. But neither one had the ServiceAccount property.

So I turned to WMI under SMO with PowerShell.  The script below has the details of a script I named GetSqlServices_WMI with a parameter of $sqlserver.

param (
	[string]$sqlserver
)

# Call this with .filename.ps1 "servername"

[void][reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement")
$wmi = New-Object ("Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer") $sqlserver
$wmi.Services | Select DisplayName, Type, StartMode, ServiceState, ServiceAccount | ft -auto

The call is in the code.  The results will have DisplayName, Type, StartMode, ServiceState and ServiceAccount listed in a table with column headers.

Great way to interrogate the Services from SQL Server.

Available Properties to you are as follows:

  • Parent
  • AcceptsPause
  • AcceptsStop
  • Description
  • DisplayName
  • ErrorControl
  • ExitCode
  • PathName
  • ProcessId
  • ServiceAccount
  • StartMode
  • Type
  • IsHadrEnabled (because I am using 11.0 SMO)
  • StartupParameters
  • Dependencies
  • AdvancedProperties
  • Urn
  • Name
  • Properties
  • UserData
  • State

With Methods

  • Alter
  • ChangeHadrServiceSetting (because I am using 11.0 SMO)
  • ChangePassword
  • Equals
  • GetHashCode
  • GetType
  • Initialize
  • Pause
  • Refresh
  • REsume
  • SetServiceAccount (handy little guy)
  • Start
  • STop
  • ToString
  • Validate

The link to the documentation for this object is here (Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer).

Enjoy and happy scripting.

@DBAduck

Read More

Powershell, SMO and Database Files

Powershell, SMO, SQL Server

In response to some questions about renaming a physical file for a database, I have 2 versions of Powershell scripts that do this for you, including taking the database offline and then online to make the physical change match the meta-data.

First, there is an article about this at http://msdn.microsoft.com/en-us/library/ms345483.aspx.  This explains that you start by setting the database offline, then alter the database and modify the filename then set it back online.  This particular article does not show the physical renaming of the file, but it is necessary since the ALTER DATABASE MODIFY FILE statement only changes the metadata of the database in master.

There is a procedure to do this with SQL CLR and TSQL, but I chose to illustrate it in Powershell and SMO (using SQL Provider as well as straight SMO).  The SQLCLR version is by a SQL Server MVP, Ted Krueger (Blog | Twitter) and can be found at this link.

My version will be based on Powershell and SMO with a smattering of SQL Provider provided in SQL 2008+.

Code Snippet
  1. Add-PSSnapin SqlServerCmdletSnapin100
  2. Add-PSSnapin SqlServerProviderSnapin100
  3.  
  4. $servername = "localhost"
  5. $instance = "default"
  6. $dbname = "N2CMS"
  7. $logicalName = "N2CMS"
  8. $NewPath = "c:\program files\microsoft sql server\mssql10_50.mssqlserver\mssql\data"
  9. $NewFilename = "N2CMS_4.mdf"
  10.  
  11. if(Test-Path "sqlserver:\sql\$servername\$instance\databases\$dbname")
  12. {
  13.         $database = Get-Item("sqlserver:\sql\$servername\$instance\databases\$dbname");
  14.  
  15.         $fileToRename = $database.FileGroups["PRIMARY"].Files[$logicalName]
  16.         $InitialFilePath = $fileToRename.FileName
  17.  
  18.         $fileToRename.FileName = "$NewPath\$NewFilename"
  19.  
  20.         $database.Alter();
  21.         $database.SetOffline()
  22.         Rename-Item -Path $InitialFilePath -NewName "$NewFilename"
  23.         $database.SetOnline()
  24.         Write-Host "File Renamed"
  25. }
  26. else
  27. {
  28.         Write-Host "Database does not exist";
  29. }

If you notice, I first add the Snapin that is the SQL Provider.  If you already have it loaded in your Powershell Profile, then you can just omit those lines.  If you do not have SQL 2008 objects installed on this machine, then you will notice that the Snapins don’t load either.  In that case you would just use the version below.

In the SQL Provider version you will see a Powershellism with Test-Path and you are using a path, it just is a SQL provider path that points to the Database and makes sure that it exists.  Compare it to the other version where you are looking at the Server.Databases[$dbname] and then you get the filegroups and then the files.

This version of the script is purely SMO and PowerShell.  First you load the objects from SQL Server 2005/2008 SMO.

Code Snippet
  1. # Always
  2. [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | outnull
  3.  
  4. # Only if you don't have SQL 2008 SMO Objects installed
  5. [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum") | outnull
  6.  
  7. # Only if you have SQL 2008 SMO objects installed
  8. [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlEnum") | outnull
  9.  
  10. $servername = "localhost"
  11. $instance = "default"
  12. $dbname = "N2CMS"
  13. $logicalName = "N2CMS"
  14. $NewPath = "c:\program files\microsoft sql server\mssql10_50.mssqlserver\mssql\data"
  15. $NewFilename = "N2CMS_4.mdf"
  16.  
  17. $server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $servername
  18. if($server.Databases[$dbname] != $null)
  19. {
  20.         $database = $server.Databases[$dbname];
  21.         $fileToRename = $database.FileGroups["PRIMARY"].Files[$logicalName]
  22.         $InitialFilePath = $fileToRename.FileName
  23.         $fileToRename.FileName = "$NewPath\$NewFilename"
  24.         $database.Alter();
  25.         $database.SetOffline()
  26.         Rename-Item -Path $InitialFilePath -NewName "$NewFilename"
  27.         $database.SetOnline()
  28.         Write-Host "File Renamed"
  29. }
  30. else
  31. {
  32.         Write-Host "Database does not exist";
  33. }

This version will use the Server object to get the database that you are looking for so that you can get at the files.  The file you are looking for is the $logicalName so that you can get the PhysicalName of the file.  Then using the builtin CmdLets to handle Files operations, a Rename-Item is issued to rename the initial path to the new one.

Operation order:

  • ALTER DATABASE dbname SET OFFLINE
  • ALTER DATABASE dbname MODIFY FILE
  • Rename-Item from old to new
  • ALTER DATABASE dbname SET ONLINE

I did not put these in a function, but they could easily (or not too hard that is) put together using Parameters and make it versatile for other situations, but that is for you to do so that it works for your scenario.

Love PowerShell!

Read More

The Best Thing I Learned at PASS

SQL Server

Being that I have never missed a PASS Summit yet (in the US), I thought I would share my experience about last PASS and previous PASS conferences.

I attended a Pre-Con with Kalen Delaney on Query Tuning and Plan Guides. I also remember sessions last PASS that were very relevant to my job. Each year that I attend PASS, I find that there is more to know and there is more to learn from many that are there to present.

I was pleased that when I got home each time, I applied my learning directly to my job. I remembered the Plan Guides day, and ironically while troubleshooting some performance issues with a database, found that I could leverage plan guides for a specific query, and it worked as Kalen illustrated. It actually saved many queries from bloating the plan cache, and was pretty helpful. But I had not done anything at that time with Plan Guides, so the topic and the time spent was very timely.

The other topics included Powershell and Wait Stats and Wait Types. The more practical sessions are very helpful and very applicable to my job as a DBA and manager mentoring DBAs. I can only say that I still plan attending all the SQL PASS Summits in the US. One day I hope to attend one outside of the US, but for now, the value of these Summits in networking, vendor introductions and all out knowledge transfer is worth every minute spent for me.

Read More

SQL PASS 2007 has concluded

SQL Server

I went to the SQL PASS 2007 Summit this past week, and I have to say that this was one of the best ones I have been to. I went to a pre-conference session with Kalen Delaney on Managing and the Reuse of Query Plans. Everything that I learned, I could use in my current work. That was very important for me as a new DBA in a project that needed this information.

Thanks to all speakers who took the time to put together presentations for us to learn from.

Read More

Error in SQL (Error: 17806, Error: 18452) SSPI Problem

I recently came across this while managing a clustered SQL Server. There were various messages listed out on forums, etc., but for me we found that the error was originating because we have DNS issues and Domain Controllers (DC) was unreachable due to a network switch configuration problem.

So if you see these errors, you may see in the EventLog a NetLogon error relating to not being able to reach a domain controller to login, and you will get the error below because the DC is the one that hands the Kerberos token to the process for use in SSPI related activities.

Logon,Unknown,Error: 17806 Severity: 20 State: 2.
Logon,Unknown,Login failed for user ”. The user is not associated with a trusted SQL Server connection. [CLIENT: IPAddress] Logon,Unknown,Error: 18452 Severity: 14 State: 1.
Logon,Unknown,SSPI handshake failed with error code 0x80090311 while establishing a connection with integrated security; the connection has been closed.

Good luck and have a great SQL day.

Read More
Menu