Author: way0utwest

  • Downloading SQL Saturday data

    I wanted to find out how many SQL Saturday’s I’d spoken at and how I ranked with others. I got a spreadsheet from Kendal Van Dyke at one point, but it was quickly out of date. However Kendal mentioned that there was an XML document on the site, and I looked. Sure enough, there is, but it’s separate for each event.

    That makes sense, and it’s fine. I can get the data and put it together. That’s a nice project and I decided to tackle it with Powershell. Certainly SSIS would work, and I may do that as well, or leave it to you to do. There are others that have done this and Kendal has an XLS he’s updated with this data, but this is something I wanted to just try.

    In any case, here was my plan:

    • Download the XML file for each event.
    • Save the XML locally.
    • Parse out the event node, capturing the title and speaker.
    • Load data into a SQL Server database on Azure.
    • Report on speakers and events.

    That’s it, and it’s not a big project, but it does take a little work to get the pieces to work well. I have potential load issues, duplicate data, etc.

    This post will look at just the first and second items, downloading the XML data for each event and saving it.

    Downloading XML – Technique #1

    This is the first way I found to do this, which was interesting. I hadn’t expected this, thinking I’d need to load the XML document and then save it. However the Invoke-WebRequest doesn’t need that. It has this format:

    Invoke-WebRequest $sourceURL -OutFile $DestinationFile

    I can give a source file location (URL) and a destination, and it works. I used this code, and it downloaded an XML file to my local machine.

    # get SQL Saturday data from the site

    $debug = 1;
    # counter for events
    $i = 1
    $baseURL = “
    http://www.sqlsaturday.com/eventxml.aspx?sat=”

    $DestinationFile = “E:\SQLSatData\SQLSat” + $i + “.xml”
    $sourceURL = $baseURL + $i

    # debug information
    if ($debug -eq 1) {
    write-host $DestinationFile
    }

    if ($debug -eq 2) {
    Write-Host $sourceURL
    }

    # Get file from web server
    Invoke-WebRequest $sourceURL -OutFile $DestinationFile

    Now if I add a counter to increment the $i variable, I’ll get all the files.

    Downloading – Technique #2

    The other way of doing this is to load an XML document from a path. In this case, instead of the Invoke-WebRequest, I’ll use this code:

    $doc = New-Object System.Xml.XmlDocument
    $doc.Load($sourceURL)
    $doc.Save($DestinationFile)

    I create an XML document, load it, and then save it to the path.

    Looping

    In both of these cases, I add a looping item, looking for an error. For me, I decided to use 9999 as the loop terminator. That’s an easy one, since I’m not sure we’ll get to 9999 events any time soon.

    I added this code to the top:

    While ($i -lt 9999) {

    I then covered the load call with a TRY..CATCH.

    try {

      $doc.Load($sourceURL)

      # save file
    $doc.Save($DestinationFile)
    }
    Catch
    {
    # if we can’t load the file, assume we’re done for now.
    $i = 9999
    }

    $i = $i + 1
    # end loop
    }

    This worked OK, as you can see, but it failed early on.sqlsatloop_a

    Event 39 doesn’t have an XML file. In fact, the site for SQL Saturday #39 – New York City, fails with an ASP.NET error.

    This isn’t a good design, but it was a good start and allowed me to get moving on the data. From here, I can start working on the parsing and import procedures.

    A better development process might be to encapsulate the download into a separate process and pass in the path, as I can use this same technique to read my local XML files. I should also separate out the save, and the parsing.

    Of course, I need a better way to error handle and loop through files. I don’t want to download all the files every time, so I think I should have some parsing of my file system, finding which files I’m missing, and then ignoring those in my loop. I should also be limiting my downloads based on some number, which I’m not sure about how to calculate now, but I’ll think about it. I guess I could increment based on some list, but I’d have to get one from the SQL Saturday people. Or I could take a high guess, like 500, and just try to load all those files.

    References

  • Deploy the Database First

    One of the patterns I’ve seen in some environments is people are trying to deploy changes rapidly to their database backed applications. That’s not news, but what is interesting is some of them are staging the deployment of the database changes first. Not as in I deploy database changes at 8:00pm and then application changes at 8:30pm. These people try to deploy the database changes on Monday, and their application changes will follow on Tuesday, Wednesday, or even a month later.

    It’s an interesting concept, though I think it requires a lot of forethought in your designs, as well as very tight coding from your front ends that won’t be disturbed by extra columns in a result set.  That’s not easy to do, but it’s certainly possible, and it can even be useful if you deploy feature flags extensively in your application.

    As we become more dependent on databases for our applications, and our customers expect systems to be running constantly, I think it behooves us to find ways to make alter and enhance our applications without downtime. While there are patterns to keep applications running when the database goes down, I expect that the reality is that we need to find ways keep the database up as we alter it, which for me means making non-breaking changes.

    I think it’s possible in many cases to upgrade a database over time by carefully planning your schema changes and accounting for those changes in your front end architecture. However it’s not easy, as I mentioned, and you do need to commit to very stable and careful programming practices for your developers.

    Steve Jones

    The Voice of the DBA Podcast

    Listen to the MP3 Audio ( 1.9MB) podcast or subscribe to the feed at iTunes and LibSyn.

  • Which Problem Are You Solving?

    One of the problems I’ve seen for years in computing is people seeing the forest or the trees. Not that either is good or bad, but far too often I’ve run across people that only see one of these, meaning they examine problems from a high level perspective, or a very low level perspective. While either of those can help you solve your issues, there will be a problem or a time when you need to examine the situation from another perspective. Knowing when to look at a higher or lower level can be invaluable in troubleshooting.

    This past week I ran across a great post from Grant Fritchey called Understand the True Source of Problems. In this post, Grant talks about some strange DBA “best practices” that were implemented to solve problems, but aren’t necessarily the best of anything. It’s an interesting list, and you might read it for entertainment, though I hope none of you are following these ideals at your place of employment.

    However the thing I liked about this post is that in the beginning Grant begins with an old doctor joke, which is still funny to me, but it often is the approache taken by people trying to solve problems. They just avoid the issue, and never solve it. That can work in the short term, but I’ve seen this build up over time to the point where people are afraid to make any changes to a system or code because of the fear of causing some unknown issue.

    I don’t think that every issue needs to be solve to the root cause. There are plenty of times something goes sideways on one of my computers and a reboot fixes the issue. I’m fine with that, but if it occurs more than two or three times, I do need to solve the problem. I need to be able to dig deeper to diagnose what resources are failing, what performance issue exists, or maybe what line of code is broken. Perhaps I need to step back and examine if some other part of my system, like the disk or network, is causing an issue that appears to be isolated to code. In other words, I need to be able to look at the wider environment (the forest) or dive into the particulars of a process (the trees).

    Knowing how to strike this balance is a bit of an art, and it’s what really makes the best problem solvers experts. I can’t teach you that part of computing, but I can teach you this. When you don’t think you’ve completely solved the issue, stop for a minute and take a wider or narrower view. Or maybe both. Look for what you might not have thought of. If you’re like me, there are probably plenty of possibilities that come to mind when you stop and re-examine the issue. Then work your way through those items, discarding the ones that aren’t relevant. Sometimes opening your mind a bit is the best way to find the exact cause of an issue.

    Steve Jones

  • Saying No – Feb 28 and Mar 28

    I hate skipping events. If I could, I’d go to all SQL Saturdays each year, but I can’t make them all, and I can’t travel every weekend. I can’t really travel two weeks in a row as it puts stress on my and my family, and with our busy lives, it takes me away from the precious little time I have with them.

    This year I’ve already missed the annual trip to Albuquerque. It comes up on Feb 7, but I’ll be flying back from the UK that day, so I can’t make it. I’m disappointed as the drive down, a day of skiing at Taos, and seeing the wonderful hosts in New Mexico is something I look forward to. Hopefully I’ll go back in 2015.

    I’ve also got two other dates that are out. My apologies as I’ve told a few people I’d try to make their events, but I can’t travel on Feb 28 or Mar 28. That means I’m not going to make:

    I’d say I’m missing Vienna as well, and if I could, I’d go there and ski, but I was tempted by Pordeone and a weekend with my wife in Italy. However I have a few kid events, and my trip to SQL Bits involves a stay into the following week, so adding 3-4 more days isn’t something I can (or want to) do.

    In March, my kids are on vacation and with some family coming into town, I can’t travel then, either.

    This year seems to have a strange schedule to it. Not many events spread out, with most of them being bunched up into a few dates this spring. That limits my flexibility, but that’s a me problem, not anyone else’s issue. However it does mean that I don’t get to see as much of the amazing SQL Server community this spring. As of now, I don’t have any SQL Saturdays in the first quarter.

    I’m still planning April and May, and I’m hoping to get to a few other events. I’m also hoping we’ll see a few more SQL Saturdays pop up and I’ll still get to 10 this year.