The Generate Scripts task in SSMS is insanely handy. A few quick clicks and you can have tables, stored procedures, users, etc. scripted out. I’ve used it quite a bit, but I ran into an unusual situation yesterday.
I needed to create a database schema and thought I’d use the handy dandy Generate Scripts task. Popped through the wizard, clicked finish and it errored! Here was the error message:
I was thoroughly confused – I was running SSMS 2008 against a SQL Server 2008 server. I wasn’t sure where SQL Server 2005 even came into play.
I went through the process again, this time paying closer attention and noticed this:
Apparently the Script Wizard defaults to SQL Server 2005. I changed it to SQL Server 2008 and everything ran as expected. While I had run this task against other SQL Server 2008 instances, apparently none of them made use of the new data types in 2008 and, as a result, didn’t generate errors. Now why it would default to SQL Server 2008 is an entirely different question….
Okay, maybe I’m being a little sarcastic. I don’t troubleshoot dynamic SQL very often, so I don’t always see potential issues right away. For those dear readers who work with it regularly, you should stop reading now – this is all pretty basic – but it took a few minutes out of my day.
This is the only dyna- that I like
My troubleshooting methods consist of displaying the command created by the dynamic SQL and seeing if it runs correctly or if I’m missing a quotation mark or something along the way. There is probably a better way to troubleshoot, but again, I play with it so rarely that I’m stuck in a rut.
Evaluating Dynamic SQL commands
Late last week, a developer sent the following block of dynamic SQL code because he was having issues getting it to work:
ALTER DATABASE [random_dbname] SET ONLINE;
WAITFOR DELAY ''00:01'';
I followed my normal troubleshooting methods and everything worked fine. Trying to execute it as above, I received the following error message:
Msg 942, Level 14, State 4, Line 7
Database 'random_dbname' cannot be opened because it is offline.
On first glance, I was confused, because it was obvious that I brought the database online. I soon realized, though, that everything within the parentheses was being evaluated prior to being executed. Apparently SQL Server has a shorter memory than I do.
Breaking it into two separate statements like below accomplishes what needed to happen
– Bring the database online
ALTER DATABASE [random_db] SET ONLINE;
WAITFOR DELAY ”00:01”;
(‘ USE [random_db];
/*blah blah blah*/
Thinking that this ‘emergency’ had been handled, I went back to my other tasks.
Database Context and Dynamic SQL
As these thing happen, though, received another call because after he ran all of this, the database context remained Master. Fortunately, this was easy to explain. The database context switching exists only during the execution of the EXEC statement and does not persist after its completion.
None of this is rocket science or even deep SQL knowledge, but maybe it’ll save a minute or two for some other DBA out there.
Posted by tledwards
| Tagged: DBAs
Last year my better half, Tim, suggested that we start a blog. It made sense for any number of reasons, but it scared the heck out of me. I couldn’t imagine that there was anything that I could ever blog about that hadn’t already been posted and probably by someone with much more experience than I have. I have a tendency (as I did today) to go out and search for other blog posts that cover the material that I’m about to write about to ensure that I’m at least adding something new with my post.
In school, if you’re assigned a paper on the pastoral imagery used in “The Adventures of Huckleberry Finn”, the instructor knows that there have been several works on that particular subject and assumes that you will be using (and referencing) information from those works. Blogging, for most people though, is not an assignment – it’s something that you make the choice to do. The people that read your blog assume that the ideas, tips and facts that you blog about are yours, unless you attribute them.
Over the past few months, there have been numerous tweets and blog posts about bloggers that have been plagiarizing other people’s works. In some cases the posts are lifted word-for-word and other cases they have selectively reworded the blog posts, but they were still identifiable. I have no idea whether it was intentional or that they were uninformed about how to use information from other posts. K. Brian Kelley [Blog/Twitter] wrote a post ‘Avoiding Plagiarism’ a couple of weeks ago. I thought I’d take this opportunity to add a little more information. As a note, I’m not an expert in plagiarism, so if any of you reading this post find errors, please comment and I’ll update this post.
On dictionary.com, the Random House Dictionary definition of plagiarism is:
“1. the unauthorized use or close imitation of the language and thoughts of another author and the representation of them as one’s own original work.
2. something used and represented in this manner.”
Reading this definition clarifies the reasons for my fear of blogging. I would never lift language from another blog post, but there have been blog posts that have inspired me (like K. Brian Kelley’s) to write a post. Here are some ways that I handle referencing other works.
I think you should read this
Example: Kevin Kline wrote an excellent post about the pains of not being included in a meme. You should read it here: http://kevinekline.com/2010/01/14/goals-and-theme-word-for-2010/
In this case, I have nothing to add, but I want to give my audience the opportunity to read great posts that I’ve come across.
You can say it better than I can
Example: PowerShell is fabulous. It’s so awesome that it’s caused some otherwise contentious DBA’s to wander astray. Colin Stasiuk [Blog/Twitter] admitted as much in a recent blog post : “…it’s no secret that I’ve been having an affair on TSQL. I’ve been seeing PowerShell behind her back and I gotta tell ya even after the initial excitement of a new language I’m still loving it. “
I know that I couldn’t have said it better than Colin, so in addition to linking to his post, I quoted his remark. Quotes should be used sparingly – if you find yourself quoting more than a sentence or two, you should probably use the example above.
Note: Blogs, whitepapers or other articles that are copyrighted require permission prior to their use. In addition, some online works have posted requirements on how they can be used. Brent Ozar (Blog/Twitter) has a good example of that here.
This is what I researched
Example: While the sp_change_users_login has the option to auto_fix logins, that action assumes that the username and login name match. If they don’t, it will fail. Using the Update_One option is a safer and the preferable way to handle it. For SQL Server 2005/2008, the ALTER USER statement is the preferred method for mapping users to logins. Greg Low’s (Blog/Twitter) article ‘Much ado about logins and SIDs’ provides a good explanation for these methods.
This is probably where unintentional plagiarism occurs most often. If, during your research, you read blog posts, articles, whitepapers, etc. and find useful information, your best bet is to attribute them. If you recall the definition of plagiarism above, it applies to both language and ideas, so if you learned something that you’re passing on a blog post or if you’re using that information to validate your ideas, they need to be cited. Again, keep in mind any copyright laws that might apply.
What doesn’t need to be cited
Common knowledge/generally accepted facts
Items that are common knowledge or generally accepted facts do not need to be cited. Examples of common knowledge are:
- A table can only have one clustered index
- SQL Server is an RDBMS
- Most SQL Server based questions can be answered with “It Depends”
There is a decent article on common knowledge here.
Results of personal research
If you’re blogging about an incident that occurred or the results of test that you ran, they don’t require a citation. That is, unless, you did research to solve the incident or used other information to validate your test results.
The term ‘Fair Use’ had been bandied about in the recent plagiarism incident. The idea of fair use has no exact definition, but is determined by a set of guidelines. There is a good definition at Plagiarism.org and a good article titled “The Basics of Fair Use” by Jonathan Bailey. According to Plagiarism.org the guidelines look at:
- The nature of your use
- The amount used
- The affect of your use on the original
The ability to define fair use is pretty obscure and personally, I wouldn’t want to try and stand behind that argument. The incident mentioned above definitely fell outside of those guidelines, in my opinion.
At some works fall out of their copyright term and become part of the public domain. The Wikipedia article regarding public domain can be found here. While the copyright laws no longer apply, they still require citations. This point is moot for any SQL Server blogs, since, at this time, there aren’t any works old enough to have fallen out of their copyright term.
There is a huge amount of helpful information in blogs. Blogging also provides an opportunity for us to share information and experiences. I think that it’s understood that we learn from other people – just ensure that you credit those people for their hard work.
As DBAs, we are increasingly being asked to manage more and more technology. Some of that is the result of internal pressures (i.e. taking on additional roles) and some of that is the result of Microsoft bundling an ever increasing array of different technologies within SQL Server. Dealing with these various technologies has become a weekly issue for me, but it really came to light today when I had a SQL Server Reporting Services 2008 server that was consuming 100% of the CPU. Doing some poking around, I realized not only did I not really know anything about this beast called “SQL Server Reporting Services”, the tools to manage it are extremely lacking (now, that is my opinion coming from a position of complete ignorance about this technology). I connected to the SSRS 2008 service with SSMS and, from there, I could only view three things: SSRS jobs, security, and shared schedules. I determined that none of the shared schedules were responsible for the utilization since nothing was scheduled to run anywhere near the time that the problem started, so that was a dead end.
Next, I connected to the Report Service by hitting http://[servername]/reports. From here, I could look at all of the various reports that had been deployed to the instance, general site settings, security, both instance-wide and at a report level, and I could look at my own subscriptions. The one thing that seemed to elude me was visibility into what, if anything, users were running on the SSRS server.
Frustrated, I connected to database instance through SSMS that hosts the ReportServer database. I figured there had to be something in the database I could query to give me some visibility into what my SSRS instance does all day. Thinking like a DBA, the first thing I did was look under “System Views” in the ReportServer database. I saw two views, ExecutionLog and ExecutionLog2, so I decided to do a simple SELECT TOP 100* from each to see what they would give me. This is where I stumbled upon my gold nugget for the day. Right there in the ExecutionLog2 system view was all of the information that I had been looking for. Running the following query, you can get a wealth of valuable information on what reports users are running, when they are running them, what parameters they used, and how long the report took to generate (broken down into data retrieval time, processing time, and rendering time) – all key information for trending the load that your server is under and <gasp> justifying new hardware, if needed.
WHERE CONVERT(VARCHAR(10),timeend,101) >= -- Some start date that you supply
AND CONVERT(VARCHAR(10),timeend,101) <= -- Some end date that you supply
To many of you who regularly use SSRS this may be very remedial, but I figured I would throw this out there for those DBAs who like me, have to learn this stuff on the fly in a crisis.
By the way, as a side note, for those who are curious about why the ExecutionLog2 system view was used instead of the ExecutionLog system view, it appears that the ExecutionLog system view exists for backward compatibility for SQL Server 2005 Reporting Services upgrades. The ExecutionLog2 system view provides much more information than the ExecutionLog system view.
It would be so nice if something made sense for a change.
A couple of weeks ago, we had a database that had become corrupted due to a disk failure. After running a DBCC CHECKDB, it appeared that there was one table with a corrupted cluster index. Paul Randal (Twitter/Blog) verified that this was the case and that it was, unfortunately, non-recoverable without data loss. Fortunately, we had backups and this database was a replication subscription, so between the backup and publication, we were able to rebuild the database without losing any data. We then had to rebuild a kind of goofy replication set up, but that’s another story.
As I was doing some validation about the data that was contained in the backups and what needed to be pulled down from the publication, I realized that there was at least one other table that was corrupted. This is where it became confusing. I went back through the output from the CHECKDB and noticed that the table in question was not mentioned. At this point, I went through and matched up all of the tables that were listed in the CHECKDB output against the actual tables in the database and found that there were three tables in the database that were not listed on the DBCC output. I ran DBCC CHECKTABLE against the missing tables and while two of them came back with no error, one was definitely corrupted. The CHECKTABLE command actually “terminated abnormally” on the corrupted table. I went back through the the error logs and dump files that had been generated at that time. Aside from the references to the CHECKTABLE that was run, the only object referenced was the table that had shown up in the CHECKDB output.
As a note, this is a 2008 SP1 database. I know that, when running CHECKDB from SSMS, it will only display the first 1000 errors, but there were only 274 errors mentioned in the output, so I didn’t think that was the issue. I asked Paul Randal (mentioned above) and his thought was that perhaps the metadata had also been corrupted and because of that CHECKDB may not have seen those tables as existing.
We’ve recovered from the incident, but it was a curious experience. Up until now, I’ve gone off of the CHECKDB output, but this gives me reason to think that there might be tables that aren’t included. I am interested to know whether anyone else has ever run into a similar incident. Hopefully it was just an (odd) learning experience.
I was tagged by TJay Belt (Twitter/Blog) in this latest series of blog stories. I believe that it was started by Paul Randal (Twitter/Blog), carried on by Tom LaRock (Twitter/Blog) and then went viral. Since ‘New Year’ seems to be synonymous with ‘everything going to heck in a handbasket’, it’s taken me awhile to respond, but here goes.
I’ll start by saying that if anyone would have told me that I’d be a DBA (or anything computer related for that matter)
You may ask yourself, well, how did I get here?
when I was in college, I would have fallen down laughing. My step-father was a biomechanical engineer and one of my main goals in life was not to be a geek like I thought he was. I majored in Communications with a minor in English. At the time of my
graduation I had never touched a computer or even wanted to. So, how did I get to be a DBA? Sheer coincidence.
Back in my kid-free days, I worked for IBM. I actually had to use a computer (odd for me), but my responsibilities were working with IBM’s resellers and the maintenance plans they resold. It was all about soft skills and I spent a ton of time on the phone with resellers. All of the information that we gathered was stored in a(wait for it…) DB2 database. After awhile, I took on the responsibility for putting together reports. While there was definitely no administration going on, it was kind of fascinating to play with all of that data. That all stopped, though, for my next life changing event.
And they looked so sweet...
I left my job at IBM just before I gave birth to my first child and became a stay-at-home mom. Around the time my
second child was born, I started to feel the desire to go back to school. The odd thing is that the field that I was drawn to was computer science. I’m not sure if it was due to some strange chemical imbalance or the need to spend time with something that actually had logic behind it, but I began my computer science degree shortly after my youngest son turned one.
Going back to school with two little ones running around was definitely a challenge. Getting to the end of an 800 line assembly language project and have my son smack his hand on the keyboard deleting it, helped me learn the value of saving and saving often. I’m sure that trying to learn recursion while dealing with a cranky toddler helped my ability to persevere. Eventually, though. I completed the program and became a computer science instructor. Teaching was and is still the field that provides me with the greatest amount of satisfaction. I enjoyed it immensely and felt that I was good at it. Unfortunately, though, by that time I was a single mother of two boys and job satisfaction doesn’t exactly pay the bills.
My first *real* job
After leaving my teaching position at the college, I was able to get a job teaching the medical staff at our local hospital the new order entry/documentation application. I knew that this had to be temporary and that I needed to become a part of a more technical division. During the process of keeping our training environment up to date, I ended up interfacing with our DBA group on a regular basis. One of the DBAs left and that provided me the opportunity to join the team. Our lead DBA was pure awesomeness and provided me with a good solid platform of knowledge. That was back in 2003, completed my MCDBA in 2005 and the rest is, well, the rest is now. Still working, still learning.
It was a crazy, twisted road to get here and I’m looking forward to the road ahead. I’m not tagging anyone with this, but I’m thankful to TJay for giving me the chance to share my story.
This post is a response to Tim Ford’s Whose Blog Is It Anyway challenge. The opportunity to use the words: pony, nude and bong in a blog post about an actual experience was too much to pass up.
I’m a DBA and I’m logical – coldy logical, if you listen to K. Brian Kelley - but I’m here to tell you that sometimes you just have to go with your gut. Most of us have an inner voice that clues us in on the things that you know but can’t rationalize or aren’t ready to deal with yet. That’s the voice that lets you know that the URL in your son’s internet history with the word ‘PussyCat’, probably isn’t a site featuring live, nude cats. Not everyone trusts that voice – just ask George “Let’s Have Padme Die Of A Broken Heart Instead Of Anakin Crushing Her To Death” Lucas – that would have been a far more awesome scene.
I’m here to talk about such a time, early in my career. I had a great DBA to learn from, but he had moved on to another position. I felt pretty firm in my knowledge and knew that, whatever came up I could fix or handle by simply using some magical tool, library or bong.
That’s when I ran into it – the problem that I couldn’t fix, but was going to cause me pain. On a Friday evening I started seeing error messages in the SQL Server error logs that indicated that we were having disk issues. Of course the error message didn’t read ‘Your disks are failing’, but everything that I was reading seemed to indicate that. One thing that bears noting – this was the central order entry/documentation application for the hospital that I worked at – there was no acceptable downtime. I contacted our system administrator who did some research and let me know that all of the disks looked fine. Now, this was an SA whose knowledge I respected – he’d been in the field forever (not like ENIAC forever, but pretty close). He alluded to the fact that I was still a newbie and probably didn’t diagnose the problem correctly. At this point it was around noon on Saturday and even though I was getting tired of looking around, I figured that I’ve started, so I’ll finish. I wasn’t able to find any information that was clearer than I had provided before, but I knew, in my gut, that we were about to have problems – big problems. I called the SA again and tried to encourage him to look a little more closely. I asked him to pretend that the RAID array was a horse stable. From the outside, it might sound pretty happy. On the inside it might look good initially, but as soon as he looks down he’s going to be very sad about the pony. For some reason, that analogy didn’t work…
As the afternoon progressed, I kept with my gut feeling and bugged the heck out of that SA. The disks actually gave up the ghost and 40 hours later (non-stop), with our application vendor and Microsoft on the line, we finally got the disks replaced and the application back online. At the post-mortum, once everyone had gotten a few hours sleep, that same SA wanted to know how I knew what the problem was since none of the errors were absolutely clear about the cause. I just told him that I knew in my gut that something bad was about to happen. He said, “Well, if you’d told me that in the beginning, I would have done more research!”.
While the story above is true, some of the particulars have been changed to protect the innocent.
I was tagged by Jorge Segarra (Blog – Twitter) who had been tagged by Thomas LaRock (Blog – Twitter) in his post about his goals and themeword for 2010. I was going to try to remain blissfully ignorant about being tagged, but then Tim went and posted his goals. So I guess I’m on the line now. My theme word for this year is:
While there are many things that I want to accomplish this year, I don’t know that (m)any of them will occur until I can figure out a way to recharge. I’m typically a self motivated type of person, but it seems like, during the previous year, I’ve hit the wall.
I’m not entirely sure what has caused this, but I’m guessing that it is some combination of the cyclical nature of job satisfaction, having a boatload of things going on at home and the disconnect between the amount of things that I would like to learn and the amount of free time that I have.
Is there a human connector on that thing?
I realize that there is no magic button that will instantly recreate the hunger for knowledge that I had when I began learning to be a DBA. What I can do, though, is set some goals, work hard to follow through on them and be patient. My hope is that in the process of achieving these goals, I’ll rejuvenate my love of this career path.
Pick one or two topics to focus on
I have at least three SQL Server books sitting on my desk and more at home that I haven’t done much more than flip through. Rather than setting a goal to read all 3000 pages (doable, but daunting), I’m going to pick a couple of subjects to focus on and learn them as thoroughly as possible. This is ongoing – if it’s March and I know everything there is to know about database corruption (or whatever it is I end up focusing on), I’ll move on to the next subjects.
My first love is teaching. It invigorates me and gives me purpose. Blogging provides me an arena to hopefully teach people that are learning to be DBAs and the chance to share what I’ve learned.
Become more involved with PASS
As I’ve mentioned in previous posts and as Tim mentioned in his goals for 2010, we’ve talked often about starting a PASS chapter in Tucson. This ties into my love of teaching and will help us to connect with folks locally who have similar interests. I would also like to take part in other committees within PASS as needed. This will definitely require a balancing act with work and family, so I’ll be taking baby steps to ensure that I don’t shortchange other areas in my life.
What does this all mean?
None of these individual goals are earth-shattering and that’s intentional. I have a tendency to swing for the bleachers, but end up hitting to the pitcher and it makes me grumpy. My hope here is that I make some good, solid line drives and then I’ll be set up to hit it out of the park.
I’m tagging a couple of people that have unknowingly helped me to recharge (some thank you, eh?)
TJay Belt (Blog – Twitter)
Wendy Pastrick (Blog – Twitter)
Kendal Van Dyke (Blog – Twitter)
Posted by tledwards
| Tagged: Administration
, Discussion items
A few days ago, in his blog Goals and Themeword for 2010, Jorge Segarra (Blog - Twitter) tagged Lori and me to write a blog about our goals and theme word for 2010. While the title of my blog is somewhat sarcastic, it really reflects facing a year that will be full of immense opportunity and challenges as the result of a successful 2009.
In 2010, I face opportunities on all fronts in my life, professional and personal, so here I outline some of those and end with what I feel will have to be my theme word for the year.
On the professional front, 2010 is going to be a year full of many opportunities. The biggest challenge will be to take full advantage of these opportunities without letting everything else slip. Here are the major opportunities, as I see them:
- It is starting off with me shifting my focus in my position with my employer from more of a support role (production DBA) to more of a strategic role by leading a team of DBAs and System Architects and striving to make them stronger as a team as they take on what seems to be an impossible list of projects. As anyone who has made this shift knows, the key to doing it is learning to delegate effectively, however, as most that have made this transition also know, you never get completely out of the support role. As part of this, I have the unique opportunity to get to mentor someone who has recently shown a great deal of aptitude on our help desk and help mold him into a junior DBA, something I know will be extremely exciting and rewarding to participate in.
- As I move out of my DBA comfort zone, I will be required to learn a ton of technologies that my team will be responsible for that I haven’t really had to worry about up to this point. Some of these technologies (SharePoint, SCOM, PowerShell, SSRS) I find to be extremely exciting opportunities and will be a great chance for me to learn and grow. Some of the technologies I will be required to learn (i.e., SSIS) are technologies that I have tried to avoid and would rather not deal with, but circumstances dictate that I must and I know they will end up being growth opportunities for me, nonetheless.
- Getting to attend the 2010 SQL PASS Summit. Unfortunately, I missed the 2009 PASS Summit and, consequently, missed many great opportunities to learn and network. I have promised myself that this year I am going if I have to beg, borrow or steal (okay, that might be a bit of an overstatement, but you get my point ).
- Starting a PASS chapter in Tucson, AZ. This is something that Lori and I talked about for a while and that we are going to be very passionate about in 2010.
Of course, this new focus and need to learn these new technologies means a huge investment of time which leads me to my next challenge/opportunity – work/life balance.
Throughout 2009, one of the biggest things that I never thought I could get right was balancing the needs of my job with the needs of my family. In 2010, this challenge will become exponentially more difficult. If 2009 taught me anything it is that I need to go into 2010 with some sort of system or plan to try to make sure that I give my family the time that they deserve while still living up to my work commitments. This is a challenge that I am still working on cracking. Some of the personal opportunities and challenges I face in 2010, other than spending more time with my family include:
- Dealing with some personal issues of one of our kids as he strives to find out who he is on the way to adulthood. We have had some challenges with this over the last year and are seeking some supplemental help, but the challenge will be to define and stick to a plan that will help our son become a happy, productive, well-adjusted adult.
- Getting more involved in our church. This has actually been on the list for a while now, but it needs to become a priority. This is where we lead by example, not only for our church, but for our family as well, and is something that I see as essential for us to get to where we need to be spiritually. I know that we have been blessed with many great gifts and talents in our family and it is time that we use those to give back.
- Continuing to grow the relationships that we have cultivated with our many friends in the SQL Server community. I have to say that getting to network with the SQL Server community around the world in 2009 via virtual conferences and social media was one of the most unexpected and rewarding professional experiences of 2009 and, probably, my career. Most people would put this as a professional goal, but as I have interacted with many of you, I see the friendships that are cultivating as much more than professional connections and feel blessed to have been able to have these friendships.
- Blogging more. Again, this could be go either way, professional or personal, but I consider it a personal goal as it isn’t something that is really required by my employer (or something that probably a lot of my coworkers even know I do) and our blogs aren’t always technical in nature. If you told Lori and me at this point last year that we would we start a blog in 2009 and be syndicated by SQLServerPedia, we would have laughed and said that would be ridiculous because we couldn’t come up with enough to write about that anyone would want to read. Fortunately, we did get the blog off the ground in the last few months of 2009 and wrote some articles that people had some interest in, so the next challenge for us is to keep putting out content from our professional and personal experiences that, hopefully, people will want to continue to read. In this way, we can feel like we are contributing something back to the great SQL Server community that has helped us out so much.
So, all of this leads to my theme word for 2010, management! In order to have a shot at accomplishing all of these goals, it is going to require management; management of time, priorities, expectations, and resources. This is going to be probably the biggest challenge that I have faced so far, but if I am successful, the rewards will be great and have an impact on my life and my family that will pay dividends for many years to come.
Here is hoping that all of you have a successful and happy 2010!
Posted by tledwards
| Tagged: Administration
, Discussion items
, PASS Summit
I went to install SQL Server 2008 on a Windows Server 2008 R2 box today for the first time and was greeted with the error “You must use the Role Management Tool to install or configure Microsoft .NET Framework 3.5.” The text of this error was basically about as decipherable as the voice of the adults in the old Peanuts cartoons, so I fired up my old friend Google to find out what to really do. It seems that Windows Server 2008 R2 ships with .NET Framework 3.5.1 and in order to proceed, you need to go to Server Manager (that window that pops up when you login and stays unless you close it) and enable (really, install) the .NET Framework 3.5.1 and any prerequisites.