Author: way0utwest

  • Morphing Microsoft

     

    Microsoft has come a long way, and still has far to go. Which way will they go?
    Microsoft has come a long way, and still has far to go. Which way will they go?

    Microsoft is trying to change from a software vendor to a devices and services company? They are trying, according to this piece from Mary Jo Foley. With a Developer and Platform Evangelism group that is trying to bridge the gap between internal Microsoft developers and those external professionals in the real world, it appears this group will try to provide more code, samples, and frameworks that others can use. Perhaps they will even give us strong architectural examples that stand up to the real world.

    Personally I’d like to see them disclose code that works in real situations. Give us the code behind MSDN or the Microsoft Store. Prove to us you have code that not only works, but it written to meet your standards and needs. If you want to start with something that’s not open to the Internet because of security concerns, how about showing us how one of the internal MS systems really works? Maybe the annual employee review app?

    If the code isn’t enterprise ready, or of the quality that should be used as an example, why not? I know there are the same pressures building systems at Microsoft that many of us face, but if that’s the case, I’d hope Microsoft would tackle some of those issues in their tooling and platforms. They could then show us not only how to do things, but prove it can be done as well.

    I do think there is some truth to the fact that in many of the applications we build, the platform developers use is not just be the OS and local APIs. There is a richness gained by including data from services, data that exists outside of the organization. Whether that’s on the open web or from business partners, we need architectures that help us build applications that can survive some workload burst, tolerate individual machine failures, and do so at a reasonable cost. That doesn’t necessarily mean cloud services to me, but it does me better software patterns, practices, and models for developers.

    Steve Jones


    The Voice of the DBA Podcasts

    We publish three versions of the podcast each day for you to enjoy.

  • 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

  • Software Design and Schizophrenic Windows 8 Part 2

    I know it’s not schizophrenic, but that sounds better. It’s really a split personality.

    I wrote recently about Windows 8 and what I consider to be poor design in the update system. Today I want to look at another aspect that troubles me.

    Programs

    I’ve gotten used to the taskbar and finding the applications I need. I actually pin 12 applications to my bar because I use them on a daily basis and it’s much easier to start them from the task bar.

    I actually have gotten used to finding applications (other than Windows Update) on the Start Screen by typing the name. I know this worked in Windows 7, and I should always have been doing this, but the design of Win 8 actually forced me to get in the habit of hitting the Windows key and then typing the first 3-5 characters of the application name.

    In any case, here’s my taskbar.

    win8_schizo_3

    I’m running a number of apps, almost all of these are active. If I hover the mouse over any of them, I can find them. It’s no four-finger up swipe in OSX, but it works very well for finding stuff.

    Most stuff.

    I actually was running the Mail app in Windows a minute ago, however it’s not on my taskbar. I have to do one of a few things to find it. I can put my mouse in the upper left corner, and I’ll see it as thumbnail.

    win8_schizo_e

    I an alt+tab through my list of stuff and find it there, but that’s slow. I’d also say hovering I the upper left corner to be slow (to me).

    Schizophrenic.

    I also had the People app running. That’s in my alt+tab list, but quite by accident I realized that if I hover my mouse in the upper left and then move it slightly down, I get this:

    win8_schizo_f

    A list of the running metro-style applications.

    Now I have two task bars. One at the bottom of both my monitors (it’s duplicated) and a separate one on the left side of my screen (either one), if I correctly move my mouse along the left side of the screen. I don’t always do it correctly, and so switching to the metro apps becomes a little dicey at times, usually slow, and occasionally maddening.

    I thought we learned a long time ago that two separate menus was poor design.

    I don’t mind the idea of the left hand bar. It’s fine, and if it’s ergonomically better, great. Get people to move that way. However make sure you’ve integrated into the taskbar at the same time. Don’t give me two places that do the same thing for different items. Give me consistency.

  • The Control Poll

    Source Control provides lots of benefits.
    Source Control provides lots of benefits.

    I was reading about version control systems (VCS) recently, brushing up on some skills, and saw this quote in a thread:

    “There is no excuse for not using version control, even for a small project developed by single developer. Setting up local version control is beyond trivial, benefits huge. Any developer not knowing that cannot be considered good nor experienced.”

    That’s quite a pronouncement, and one that I believe is very true. No matter what type of development you engage in, I’d expect that you’d understand the benefits of using version control, and the dangers of not using it. It’s just like never backing up your system. I’d think that any developer that cares about their craft and is a professional has used version control. The really good ones will insist upon it.

    However I know that the decision to use a VCS is not always made by a developer. The company building the software might feel differently, and while I’ve always asked for a VCS, I have ended up with a series of folders on a share, named for dates, each containing a zip file of all our code at the end of that day. It was the bare minimum of version control I could live with, and fortunately we got by with just two people coordinating work. Any more than that and I’d insist on some type of VCS.

    This week, I wanted to ask how many of you voluntarily or involuntarily might be forced to do something similar.

    How many of you skip source control for certain apps?

    Even if you have source control for those large, multi-person teams, are there apps that you avoid putting into a VCS? What about your database code? I think it’s important that you keep all your code, whether for the front end application or database objects, in some type of Version Control system. If your boss won’t buy one, then check out Git or Subversion, both of which are open source and free.

    Let us know this week how you feel about source control and whether or not you decide the effort isn’t worthwhile for your projects.

    Steve Jones


    The Voice of the DBA Podcasts

    We publish three versions of the podcast each day for you to enjoy.