Category: Blog

  • When will we look back at this?

    It’s amazing how software has advanced. I look at the software I use, and I’m amazed. I still remember texting to 40404 for basic twitter usage on my Windows 6.5 Mobile. That seems miles away from the apps I know use on my current iPhone 4S. I almost can’t comprehend what my life would be like if I didn’t have a smartphone now.

    I saw this video of a HoloDesk from Microsoft Research. It’s neat, and I can imagine the possibilities of what might come, but for not it’s very basic.

    It makes me wonder when we’ll have something more like this interface:

  • Starting with Azure

    I’ve been meaning to do this, and I finally had the chance recently to start working with Azure. Red Gate is investing in cloud tools, and more development tools, so it’s something I need to work on.

    I went to the Azure page, and noticed a “Member Offers” link.

    azure_a

    When I clicked through, I could see the benefits. Below this screen shot is the list of stuff you get, depending on your MSDN subscription. You can see the exact benefits on the MSDN benefits page.

    azure_b

    I clicked the activate link and was taken to the Windows Live login page. After signing in, I got a page that asked me to create an account. It listed my specific benefits and the requirements for an Azure account.

    azure_c

    Since I have a mobile phone and a credit card, I clicked the arrow to proceed. The first thing is to verify your account with a mobile phone. I assume this gives me some sort of two factor authentication as well as a way for them to reach me for billing issues.

    azure_d

    After receiving a text and entering it, I was taken to the billing area. I know this freaks many people out, however I’ve had a number of friends use the MSDN subscription trial and not been billed after 5 or 6 months. I’ve had a few that have been billed, but it’s been low amounts, in the $5-10 range. Grant Fritchey (b | t) is one of them, and with all the writing he’s done on Azure, some presentations, and research for Red Gate, he hasn’t had issues.

    It’s your career, it’s worth $5 a month. If you find you’re spending more, shut stuff down. I’d give it a try, however, if there is any chance your career will include work in the cloud.

    azure_e

    Once you enter a credit card, they’ll get to work.

    azure_f

    The welcome screen gives you lots of options. I’m sure I’ll end up here quite often across the next few months as I try to be sure that I’m not running up my cost. I can expense it back to Red Gate, but I do try to spend wisely.

    azure_g

    What now? There’s lots of options.

    azure_h

    I have a few things in mind, but I’ll probably start with a few light experiments based on some presentations I’ve seen. Buck Woody has a nice set of resources to get me started, and I’ll likely give one of these a try.

  • The Bicentennial SQLSaturday–#200 Philadelphia

    When Andy Warren (b | t | Li)started SQL Saturday with #1 in Orlando, we weren’t sure it would succeed. After a few events, we dreamed and wondered if we’d ever get to 50 events. Despite our success in the past, we weren’t sure if a free event, supported by advertising (essentially) would survive over time. We also weren’t sure if we could replicate and grow this event in other locations.

    It grew, and prospered, and then exploded, thanks to Karla Landrum (b | t). Under Karla’s guidance and nurturing, we’ve seen a tremendous number of events taking place all over the world. Not only did we get to 50 events, the SQL community blew past 100 a few years ago and earlier this year event #200 was posted.

    It’s somewhat fitting that in one of the cities that helped birth my country, and houses the Liberty Bell, will host SQL Saturday #200 in a little over a week. I’ll be traveling next week, along with Andy for the event. There’s an exciting lineup of speakers, bringing you a wide variety of SQL Server learning sessions.

    I’m looking forward to seeing friends and meeting new people, as we celebrate the bicentennial SQL Saturday. If you can’t attend this event, there are lots of SQL Saturday’s scheduled for the rest of the year. They’re free (other than lunch at a few events) and it’s worth your time to learn something new about SQL Server and network with some of the people in your local area.

    If you’re attending an event, you might even think about bringing kids and perhaps organizing a session for them.

  • Getting Information from a Database using Dynamic SQL

    I ran across someone that was building a restore script to automated their restores. This person wanted their script to work with any instance, and that means they’d need to find the path for the database files, if the database already existed.

    It was interesting to me, and I decided to give a solution a try, and I ended up using dynamic SQL, which I don’t love, but it worked. As I was digging through, I realized that all the database data is in sys.master_files. However I’d started this and it was an intriguing problem. I don’t love this solution, and I wouldn’t use it here, but there might be a place where you can use it.

    To find out if a database exists, you can easily use the sys.databases view to find it.

    USE master
    GO
    DECLARE @path VARCHAR(500)
       , @db VARCHAR(200)
    ;
    
    SELECT @db = 'AdventureWorks2008'
    
    IF EXISTS (SELECT name
             FROM sys.databases
     WHERE name = @db
     )

    This is a snippet, and you need more code for this to work, but it does work if you include the “then” and “else” blocks. If the database doesn’t exist, you can grab the default file paths from the registry if you want to build the restore script, but if it does, then what.

    You want to find the database files, but these aren’t stored in master. If you query sys.database_files, you’ll get this:

    dbfilepath

    I have 8 or 10 databases on this instance, but none appear. However if I query a specific database, I get the files.

    dbfilepath2

    How do I get this data, in a script, given that I can’t execute a “use” statement easily at runtime.

    There are probably a few ways, but for me, I decided dynamic SQL might make sense her. This is an administrative task, so it’s not likely to allow for SQL Injection as I wouldn’t expose this for users to run.

    The first step is to build my query. In this case, I want to execute this query:

     select physical_name
      from AdventureWorks2008.sys.database_files
       where file_id = 1

    This isn’t ideal, in that I could have many files for this database, but for now I’m concerned with just getting the primary data file.

    I can build this string dynamically like this. Note that I’ve assigned the result to a variable for now.

    DECLARE @sqlCommand nvarchar(1000)
    DECLARE @db varchar(75)
    DECLARE @file VARCHAR(500)
    SET @db = 'AdventureWorks2008'
    SET @sqlCommand = 'select @f = physical_name from ' + @db + '.sys.database_files where file_id = 1'
    
    SElect @sqlCommand

    However now I need to run this command and return a value. sp_executesql is a function that allows you to execute a string, pass in parameters, and assign them back. I can do this with this script.

    DECLARE @sqlCommand nvarchar(1000)
    DECLARE @db varchar(75)
    DECLARE @file VARCHAR(500)
    
    SET @db = 'AdventureWorks2008'
    SET @sqlCommand = 'select @f = physical_name from ' + @db + '.sys.database_files where file_id = 1'
    
    EXECUTE sp_executesql @sqlCommand, N'@f varchar(500) OUTPUT', @f=@file OUTPUT
    
    select @file

    If I run this, I’ll get the file path from the AdventureWorks2008 primary data file.

    That’s the first step in this process. If I wanted to complete it, I’d have to make sure I did this for each data file, probably using some temporary table instead of a variable, and storing all the physical paths and logical names, and using those to build a dynamic restore script.

    Or I could download this script: SQL 2005 Restore Script Generator