Tag: syndicated

  • Return Values from XP_CMDSHELL

    Let’s be clear: I don’t recommend the use of xp_cmdshell as a general tool. It ought to be used when you have no alternatives, and you should carefully control access and what this can do. Opening a shell from SQL Server can be dangerous for your server.

    That being said, I do think there are places that xp_cmdshell works great and if you need to use it, how do you tell if the commands you executed were successful?

    For those of you that have worked in command lines, or remember DOS, there is a thing called an Errorlevel, that is returned by programs when they exit. For many of us that used to program in DOS, we always checked ERRORLEVEL when exiting a program, and we made sure that our program always returned a 0 if it exited without an error. That’s a standard that has been in place as long as I can remember working with computers.

    How can we use this? If I execute this in a command window:

    errorlevel

    I get an instance of Notepad on my screen. When the CD.exe application completes, it sets the errorlevel to 0. Technically it returns a 0 to cmd.exe, which sets the errorlevel to that value.

    What about this:

    errorlevel2

    In this case, nothing happens. However if I switch the command to:

    errorlevel3

    Then I get notepad again.

    How can we use this in SQL Server? When xp_cmdshell exits, it returns the errorlevel from it’s shell. Let’s test it. First, enable xp_cmdshell

    -- To allow advanced options to be changed.
    EXEC sp_configure 'show advanced options', 1
    GO
    -- To update the currently configured value for advanced options.
    RECONFIGURE
    GO
    -- To enable the feature.
    EXEC sp_configure 'xp_cmdshell', 1
    GO
    -- To update the currently configured value for this feature.
    RECONFIGURE
    GO

    Now execute

    DECLARE @i INT
    EXEC
    @i = xp_cmdshell 'dir'
    SELECT @i

    This returns the current directory (\Windows\System32 in this case) and a 0.

    errorlevel4

    Now if we change to our other example:

    DECLARE @i INT
    EXEC
    @i = xp_cmdshell 'cd tim'
    SELECT @i

    We get these results

    errorlevel5

    Since that’s not a valid path on my system, the DOS error is returned as a result, and the errorlevel is returned in the variable assignment.

    You can use this to test and see if your commands execute before you do something, like try to parse a directory listing that isn’t there.

  • Career Warfare – Book Review

    70618861[1] I picked up Career Warfare on the recommendation of a friend that had seen the Modern Resume presentation. I grabbed it as an e-book and have been reading it for the last few months, at a fairly slow pace (for me).

    I often read a book in a week, but in the case of this one, I would read part of a chapter, and spend a day or so thinking about it. Digesting the information, and seeing how it might be applicable to my career, and my brand.

    The author, David D’Alessandro rose to CEO of John Hancock Insurance, and you have to keep that in mind. The book is written as a tool for how you might advance your career in corporate America, and it includes lessons for upper management, many of which don’t apply to most of us. Items like dealing with the press aren’t something the average person needs to think about.

    However there is some great advice in there about how you should grow your career, and the impact that you have on your career based on your actions.

    I highly recommend it, and there are a couple of great pieces of advice in there. Most importantly, you are always building your brand. Slowly, surely, but every day you go to work, or interact with people professionally, you are building your brand. I like that he stresses honesty and integrity as well.

    There are some things I don’t necessarily agree with, like not bringing your spouse to social events, or not drinking at all, but if you are attempting to rise to the C-level ranks, perhaps that’s good advice.

  • SQLSaturday Advice – Scheduling

    One of the things that I’ve seen cause a few headaches at SQL Saturday events is the scheduling. First, before anyone gets upset, I think the organizers have done a good job, and I haven’t really seen anything wrong with what they’ve done. I just think here’s a little room for improvement.

    Easy to Hard

    One thing that I noticed at an event earlier this year was a number of sessions that covered the same technology, but at different levels of difficulty. For example, I saw a beginning Powershell and a more advanced Powershell session in the same schedule.

    However the advanced session was first, and the beginner one later. That’s fine in a vacuum, but if I’m getting into Powershell, or wondering what it’s about, I’d rather go to the beginner one and then if I want more, I can go to the advanced one later.

    So the first piece of advice is to schedule beginner content first, and then more advanced content. I might even try to schedule things back to back if I can, but definitely get beginner content out first.

    Big Names

    I don’t really consider myself a big name, but a lot of people know who I am, and I think there’s some attractiveness to having me at your event. The same thing goes for Andy Warren (LinkedIn | Blog | @sqlandy), Thomas LaRock(Blog | @sqlrockstar) and a few others.

    So,

    I would suggest that you look at your list of people, after you’ve scheduled content in order from easy to hard, and then make sure that your out of town people, or your big names, aren’t speaking at the same time. Attendees that are coming because of a few big names will want to see them, so spread them around. Make sure that you have your MVPs, your high profile people spread out so that your audience can go see them.

  • One Meel-ee-yon Posts

    We crossed the 1,000,000 post mark on SQLServerCentral today and that’s very cool to me. A few others as well since there’s been a “Race to post 1,000,000” thread going for a few weeks.

    It’s hard to believe that we’ve reached 1,000,000 posts. On one hand I would have thought we’d have gotten there sooner since we crossed the 1,000,000 visitors a month mark years ago, but most people read and don’t post. 

    I ran some averages earlier. When I sold the site, we were getting around 400-500 posts a day on most weekdays. Now we’re up over 700 a day and frequently crossing 1000 on busy days.

    Very exciting for me.