Incorrect Syntax – What?

Categories: News, Professional, Scripts, SSC
Comments: No Comments
Published on: November 17, 2017

Intuitive errors are very helpful when trying to troubleshoot a problem. On the other hand, when we receive an error that is vague, we sometimes find ourselves wanting to throw the laptop out the window. What do we do though when the error message really does look to be pretty intuitive but we can’t figure out where the problem is?

Today, I am going to cover one of these falsely intuitive errors. As it turns out, this is a problem that I had actually forgotten about since I had not seen it in many years. The error is shown here.

This error looks pretty straight forward, right? It tells me there is an incorrect syntax somewhere in my query. Running into a syntax error somewhere along the line does happen to all of us at one time or another. Because of that, I would not be terribly alarmed by the error and just proceed to fixing the syntax problem. Here is the query that is throwing that error.

Now is the time to start pulling out your hair. There is no syntax error in the query. Go ahead and look it over 10-15 times. I know I did.

Ok, if there is no syntax error, then what could possibly be the real problem? Is the database corrupt? Maybe a system table is corrupt? Grasping at straws here, but could it possibly even be some sort of royally screwed up permissions.

Everything seems to be checking out properly. There is no corruption whatsoever. Laptop is soon to be launched at this point right? Ok, maybe not launched because this is a simple query. But, had this been a production related query that was rather intense and complicated, there really may be something getting launched as the frustration mounts.

Simple Solution

Well, since the error does not fit the crime, maybe this is one of those really odd errors that truly means something else. In this case, if we dissect the query we will probably notice that there is a DMO being called here. If I query sys.stats directly there is no problem but joining to sys.dm_db_stats_properties I get the error. If I run the query from the master database, the query runs without error. In fact, running the query from within a connection to most databases succeeds.

Now we have two clues to the problem. It only fails in some databases and only fails when the DMO is used in the query. Let’s take a look at database properties and see what we can find. In this scenario I am finding this little nugget in the affected databases.

This database happens to be in SQL Server 2000 compatibility mode. I wonder why that may be and proceed to investigating as well as fixing it. Let’s see what happens after changing the compatibility mode to something more recent (and yes this is an OLD version of SQL Server and the whole thing should be updated anyway but that is a discussion for another time).

If we step through this whole script, we will see that this is a script that will reproduce the entire scenario from break to fix. First thing is to set the compatibility mode to 80 (SQL Server 2000), then run the query (results in the error). Next I change the compatibility mode to 100 (SQL Server 2008) and rerun the query (no error this time) and I get all of the stats with properties that I was hoping to get. Then I conclude with confirming that I am in the correct compatibility mode.

Conclusion

Errors will happen as we work with TSQL – that can be expected. Sometimes we type too fast or just miss something here or there. When we get a syntax error, it really sets our mind to focusing on it being a mistake that we made. In this case however, the error is thrown for a syntax problem because the DMO is not accessible in compatibility mode 80.

Due to the straight forward error – we may spend a little to much time looking at the wrong thing. Keep your mind open to the error being elsewhere than your code should you see a syntax error near “.” in your endeavors.

T-SQL Tuesday #096: Inspiration Abounds

Comments: 2 Comments
Published on: November 14, 2017

Who Inspires You?

Today is a bit of a divergence from the usual geekery that may abound on my blog. As prompted by Ewald Cress (blog | twitter), it is time to take a step back and put forth a bit of reflection. Ewald has requested we do this as a part of the TSQLTuesday monthly event. If interested, here is the invitation to participate along with all the nitty gritty details and those things we love to ignore (rules).

While looking at the invitation, it dawned on me how long this monthly event has been running. This is the 96th installment which also means it is the 8th birthday of this event. Birthdays are a good time to do a bit of self reflection. And right now with Thanksgiving around the corner, the invite to reflect upon those people that may have served up some sort of inspiration to us is a really cool idea.

For me, this is about much more than just a story or two about people that have impacted me in my career choices. This topic is also about much more than just a handful of years of inspiration. Inspiration comes in many different flavors and should help to build you into who you are over time.

With that, I give you my 96 for 96.There is no way that just one or two people could have inspired me to this point in my life. So, I set to see if I could think of 96 people that have had some impact in shaping and inspiring me. One person for each edition of TSQLTuesday on this the 8th Anniversary of a really cool thing started by Adam Machanic (twitter).

96 for 96

My apologies up front for what may be a really long article

Personal

  • My Wife (1) – How can I have a list of those who have inspired me in my life and not include the rock and stability of my life for most of my adult life? She has been there to push me along since the beginning and working me into something more refined.
  • Hursts (5) – My adopted family that taught me a lot about compassion and hard work. They have been very instrumental in helping me to learn more about giving to others.
  • Grandparents (2) – I wrote about my grandfather when he passed. My grandmother is tough and inspiring for somebody so petite. The two of them helped to inspire me to have a good time but also how to be resolute.
  • Children (4) – Wow, my kids are crazy balls of energy all the time. The learn and grow and absorb and try and fail and try again. They have so many talents that I would have never imagined. They embrace the challenges (mostly) and inspire me to develop new talents and continue to learn.
  • Ella (1) – My wife’s grandmother was stern and rigid. She was very precise in how things needed to be done. Oh and boy was she strong willed. She influenced me with how to be stern and accepting and how to balance that nicely.
  • Football team (22) – A football team? Why would that be? This is the team that I coached most recently. These guys had it tough. Due to various things outside of my control or their control they had a mid-season coaching change. I became a part of the new coaching staff. We pushed them hard and saw them grow. They did not quit and would be a huge inspiration to many on how to persevere.
  • Pierre & Veronique (2) – Good friends from France. Pierre died many years ago but he was able to instill in me a “fire in the belly” type of mantra. Hunger for more and hunger to be better. Veronique is another very strong woman and very quiet. Between them they have helped to inspire me in how to be strong yet quiet.
  • language teachers (2) – This one is for my foreign language teachers from elementary school through high school. Between French and German, they were able to inspire a desire to learn language and culture.
  • Conway (1) – My High school Calculus teacher. He was the toughest teacher I ever had. There were no shortcuts with him. I learned how to think logically from him. I may not have liked it back then when I could just see the solutions (without having to do every stinking step) but had to do it his way. Turns out it was worth it because it helps to avoid the shortcuts and I can think through problems to hopefully reach a better solution now.
  • Mimi (1) – Mimi was my collegiate counselor. She helped me to understand the need to speak up but how to do it politically when the time warranted it.
  • Mandy Harvey (1) – What more can be said about this girl? If you haven’t seen it, you need to watch it now.
  • Kelvin Spendlove (1) – Kelvin was a family friend from Vegas. He came down with cancer and passed away earlier this year. Kelvin was an example of fighting and persevering. Despite all of his pain, he kept a pleasant demeanor and showed as much charity to others as he could. No matter how bad you have it, you can take a moment to uplift somebody else.
  • Jon Huntsman Sr (1) – Mr. Huntsman is more of somebody that is well known that does and says many things that are inspirational to me. His philanthropy is of great interest. Huntsman teaches that the more you give with the right intent, the more you will receive and thus be able to continue the cycle

Hey Sport!

  • Coaches (3) – Different coaches for different sports that I had growing up inspired many things. One of those things is the ability to work through the fatigue and to be able to be comfortable in that painful/difficult moment of any given competition. Are you able to pick up the pace in that last mile?
  • Thao Tran (1) – Thao was a great friend that got me back into endurance sports. I had found myself out of the routine and out of time. With Thao, I was able to find that time and get back to running for very long amounts of time.
  • Dan & Dave (2) – Remember these guys? The decathletes that were in all the ads all the time? These guys made Track and Field super sexy. Seeing these guys and how cool it was to do Track helped encourage me to try other events.
  • Khalid Khannouchi (1) – Elite level marathoner. Khalid and Bernard are both elite level and record holding marathoners. This was something that I aspired to accomplish. That dream may be changed now but the ability they showed to push harder and harder through the fatigue is something that I have found very helpful in my career.
  • Bernard Lagat (1) – same as Khalid.
  • Steve Prefontaine (1) – Runners everywhere know about “Pre”, right? His running and style were inspirational and he was one of the runners I looked to when I was running through High School.
  • Greg Lemond (1) – Despite the animosity between Greg and Lance I am grouping them together. Lemond was a legend in my youth. He was winning the Tour de France and looking good doing it. Lance contracted and beat cancer and then went on to smash the Tour de France several times. No matter the allegations – the feats of these two were beyond comparison and well beyond awesome. I am a better runner than biker, but the two are similar in that they encourage you to go beyond and dig deeper in order to be successful.
  • Lance Armstrong (1) – same as Greg
  • Jerry Sloan (1) – Talk about a tough nosed get it done and gritty kind of professional. We could all learn a little about this type of workmanship.
  • Stockton (1) – Part of the trinity in Utah Jazz history. The humility and workman-like attitude he brought to the sport he loved is admirable. His attitude inspires me how I can work hard, be humble and be extremely talented and capable in my profession.
  • Malone (1) – Nobody outworked the Mailman. It is a tough act to follow but something to strive to accomplish.
  • Steve Young (1) – I had the opportunity of meeting Steve Young at the Olympics where I served as a translator one year. I met Dale Murphy there as well. I was amazed out how approachable these men were. I grew up watching both of them play (football and baseball respectively) and becoming a fan of the style in which they played and the success they were able to achieve in life and on the field. This helps me to try and become more approachable with clients or at various SQLFamily community events. It is not easy! 😉
  • Dale Murphy (1) – same as Steve Young
  • Ozzie Smith (1) – Ozzie was a wizard at shortstop. I remember watching some of the things he did defensively and being floored. Doing the job, doing it well, and doing it with a little flare. Sometimes a little flare is needed in the job – just as long as the job is getting done well!
  • Walter Payton, Jim McMahon, Mike Singleterry, William Perry, Mike Ditka (5) – Da Bears. These are the guys that got me to be a Bears fan for life – bad or good or well … Teamwork and doing whatever other thing was necessary to help the team succeed is what stuck with me from these guys. Need a lineman to play halfback a few plays? Call on the Fridge. In the workspace, sometimes we will just need to do something else in favor of the success of the group as a whole.

The Geeky!

  • Bill Gates / Steve Jobs (2) – from Garage to tech Giant these guys inspire with the dreams of success.
  • Steve Jones (1) – Steve was instrumental in getting me to write. He was helpful while also being honest. I have been able to develop into a better writer thanks to his help.
  • Gail Shaw (1) – Gail is a good friend. Another strong woman I have had the pleasure of getting to know. She is a great person to have a low key conversation with about SQL or about life. Gail knows her stuff and we can all learn something from her.
  • Paul Randal (1) – I have had the opportunity to chat with Paul on a few occasions. The most memorable comment from him was that we can all learn from each other. He learns from us and we can learn from him. Paul knows a lot about SQL Server and is still able to learn more. We can all continue to learn about SQL Server.
  • Kimberly Tripp (1) – Kimberly is a genius with stats and indexes. I have learned plenty from her from her presentations and articles.
  • Kalen Delaney (1) – One of my favorite things about Kalen is her ability to tease and know when it would be effective. Kalen is a person with whom I have enjoyed some great conversations. Are you looking for somebody that know a boatload about SQL Server – Kalen should be at the top of that list.
  • Kevin Kline (1) – Kevin has unwittingly bestowed some great lessons on me. He has some great internals information on SQL Server. He also has some awesome personal development stuff that people could learn from him.
  • Brent Ozar (1) – Brent is very smart with SQL Server. Probably the greater inspiration to me is his energy. He is great with marketing and branding. He does a great job at appearing to be outgoing. That is a difficult thing for many in the IT field that would self-classify as an introvert.
  • Joe Sack (1) – Joe and Jonathan are going to be grouped together. I had the opportunity to work with both of them when working on my first book. I learned a lot about the writing process and some tips for just plane old making it better. I hope I can retain what I learned.
  • Jonathan Gennick (1) – same as Joe
  • Bob Ward (1) – between Bob, Paul and Ewald I learn so much about the internals of SQL Server. These guys are smart and love to play with the debugger. It makes me a bit jealous. I would love to have adequate time to just dive in with the debugger on a regular basis – maybe daily. There is a lot that can be learned from these three. Find their stuff and start learning. They push me to keep pushing harder to learn more about the internals.
  • Paul White (1) – only addition here is that I appreciated the late night conversations with Paul. He had the added advantage over Ewald and Bob in having a more direct impact in inspiring some of my internals dives.
  • Ewald Cress (1) – same as Bob.
  • Pat Wright (1) – Pat is a monster in the community. Pat runs user groups, organizes events and works to bring so many people together or greater learning opportunities. He does not limit his efforts to just the SQL Server community. Rather he is looking at all data related communities.
  • Ben Miller (1) – I met Ben many years ago. He introduced me to a few little tidbits for SQL Server and it sparked a greater interest in me to diver deeper and just get better at what I do.
  • Wayne Sheffield (1) – well this big teddy bear helped Steve Jones with getting me down the path to writing. Wayne did it in a little bit of a different way but was somebody that helped inspire me that writing technical papers is something that I could do.
  • Kendra Little (1) – the technical insight and ability of Kendra is top shelf. What I like about Kendra’s community presence and work is the character she brings to it. Learning can be fun and witty and personal. It doesn’t have to be technical and dry all the time like so much of the content out there.
  • Jes Borland (1) – Talk about an amazing ball of energy! Oh and Jes is an awesome talent in the SQL community too. If you want to learn, take a minute or three with Jes.
  • Jennifer Moser (1) – Jennifer is simply amazing if you ask me. She can herd cats err data professionals like it is nothing. She does so much for the community and I would dare say that much of what she does goes completely unnoticed. If you come across her, tell her thanks. We can all learn a bit about working tirelessly for the betterment of a community from Jennifer.
  • Dwaine Camps (1) – Dwaine was a SQL Super Stud in my opinion. He was a great help in solving many technical puzzles and he loved to apply himself to those types of problems. For him, those puzzles were like deep dives for me. I learned a lot from Dwaine. Rest in Peace.
  • Jeff Moden (1) – Jeff is rbar none a top shelf MVP in my opinion. He is the juggernaut of high performing tsql solutions.
  • Andy Leonard (1) – Friend, mentor, wize man with a goatee. Nuf said! Andy is an easy going person that taught me an important lesson about community. Sometimes taking a step back is a far better contribution to the community than to hold on to everything with white knuckles.
  • Andy Warren (1) – Andy has been very influential for me. Reading his articles and talking to him, I have had the opportunity to understand a little better the managerial presence. I don’t really know how to explain that very well, but there is a calming presence and an understanding of staying even keel with whatever issue pops up. He has a way of looking at various issues, thinking about them, presenting them in a seemingly un-biased fashion and just being factual. Sometimes we can benefit from the approach of studying it out and not acting too rashly.
  • Robert Davis (1) – Robert is another one of those internals studs. Robert has been influential to me with some of his articles about how different features work. Again, this is an inspiration to dive into SQL Server to better understand how things are working.
  • Aaron Bertrand (1) – When I first met Aaron, I have to admit I was surprised that he knew who I was. This impressed me quite a bit. It tells me that this well known community giant takes the time to get to know the little guy and that everybody in SQLFamily is important. Maybe I can learn from that and work that much harder at remembering who people are (I am very weak at remembering people and faces).
  • Thomas LaRock (1) – Thomas is an interesting character on my list. This is not a bad thing at all. He is an interesting person. The most influential thing I have picked up from Thomas is his ability to weave a story while presenting. He is an amazing presenter in my opinion. He has an ability to teach through story telling that is difficult for me. It is certainly something I am striving to become better at doing.
  • Midnight DBAs (2) – Jen and Sean are the Midnight DBAs. I would call them friends as well. When I think about their influence, “Don’t sweat the small stuff” comes to mind. That doesn’t mean we need not take care of the small stuff, but rather sometimes we can have zero impact on certain things. All we can do is try to make our case and hope that people will accept our input as the SME.
  • Grant Fritchey (1) – To be honest, I don’t know why I put Grant on this list. Just kidding. I enjoy chatting with Grant. The nice thing here is that we can chat about things that are not always about SQL Server. If you have a recommendation, Grant is all over listening to you and determining if he can test it out. I don’t think I have ever seen him be dismissive to anybody except that one time to me. Yes, he will probably think about that one for a bit. It is a story that could be told some day.

TSQL2sDay150x150The Wrap

Wow, what a list? That is a list of 96 influencers in my life. True some names have been partly or entirely obscured, but the people are real. You will probably notice that I did not include any links to twitter profiles or blog sites. I am leaving it to you to google the person.

I have just shared roughly 96 points of data with you about my development into a data professional. I still have a long way to go as well. Oh and because it is 96 points of data, it meets the requirement to be at least loosely tied to the requirement of being about data.

Don’t see your name on this list? I really had far too many names for the 96 and I do realize that some people that have been really influential in my life did not make it to this list. I am sure all of us could find far more than just one or two people that have influenced us in life. If you are reading this post, I challenge you to come up with your list of at least 20 people that have influenced you. I bet you will be pleased with the self reflection.

SQL Server Haunt 2017

Comments: No Comments
Published on: November 1, 2017

Halloween is a great time of year. It is unfortunate that it is just one day of the year. That said, I do like to think of the phantasmripmonth of October as Halloween Month. I have several posts over the years that geek out over the cross-over between Halloween and SQL Server.

The undead of Halloween are now upon us. Among the hordes of data zombies roaming the streets in lab-coats and fishnet stockings, few of us are still scrambling to remove the hexes we have looming over our data.

As chance would have it, these hexidecimals, err hexes, have a more profound effect on us than we first thought. Many may have yet to even recognize the impact of the hexes placed along with the monsters that now lurk in the data after having been summoned via those hexes.

DB and Fun Related

Seeing as I am a really big fan of this holiday I have a few Halloween posts over the years. If you are interested in the previous Halloween posts, here is a list of a few of them:

All Halloween posts

That list is my Halloween treat this year. Now for a bit of a trick with a very strong warning. Because of this warning, I am not posting any code showing how to perform the trick.

Warning

The contents of this post are for the intent of HUMOR!

Freddy Kreuger

mangled

I can hear you clamoring from half a world away right now – “There is nothing called ‘Freddy Kreuger’ in SQL Server. What in the world are you talking about?”

You would be very accurate in your exclamation there. But this is not necessarily a strict exercise in feature names within SQL Server. I want you to think a little further outside the norms for a while.

Do you currently or have you ever needed to shred XML? XML shredding via TSQL can be a monstrously bloody killer to your database performance. As it turns out, Mr. Kreuger was also a monstrously bloody shredder.

Jason Voorheese

Yet another beast that is not truly in SQL Server, or is it? A not so new but new feature in SQL Server is called JSON. This feature does actually perform better than XML in some regards. That said, we do have a very common problem between the two of these features – blobs.

If you are not familiar with what that means -here you go. A blob is an overly large item being stored in the database. If you wish, you could correlate that to the other well known Halloween beast – “The Blob”.

Over time, this blob acts like sludge and just slows down your database queries. In addition, like the creature, the blob in your database tends to continue to grow in size and is seemingly never able to be put in check.

Skeletons

When I find skeletons, I have to be honest, I don’t find them terribly frightening. When talking about skeletons in your database, I am even less frightened.

Then again, when I run into the situation as described recently, in this post, I may get a bit of a startle and get just a wee bit concerned.

Overall though, I am rarely startled or frightened by any skeletons in the database. These are really just the supporting structures of a nice secure database and are called “schemas”. See, not really all that frightening here if we think about it just a bit.

This next one however, might be a little harder and should be nearly enough to cause some heart pain.

Warlocks

Surely there are no wizarding type of people in the database, right? Warlocks? I know for absolute certainty that there is no such feature or anything remotely close to a warlock, witch or wizard within the database. That is unless my database is about mystical creatures and people.

Alas, I urge you again to expand the box of perception a little bit and become just a tiny bit imaginative. This one, truth be told, does require a fair amount of explanation and imagination though.

The problem comes in part from some magical data issues that can occur due to this particular feature. In addition, this also comes from the wonderful grammatical errors from various blog posts and forums out there mis-spelling “which” as “witch”. Since “manwich” is really close to “man-witch”, I am calling it a warlock.

Now, since I am calling it a warlock, that leads us to the next strong hint about the feature. “Lock” in this case is the key. Now which magical, imaginative feature might there be that is related to “lock”? That would be the “nolock” directive and all of the data quality issues that it presents. Here is a really really good recap (by Aaron Bertrand) on this feature along with reference to it being “magic” – at this site.

Pirates

This is probably the easiest of the day by far. For all the data loving geeks out there, SQL Server has this pirate flavored way for you to get your drool on. This feature is called “R”. Yup – just like what a pirate says matey.

R is a tool to be used by data scientists or data geeks in general to try and throw together many different flavors of statistical analysis about your data.

Split Brain

Finally, (at least for this Halloween) we have this condition that is real within SQL Server. While treatable with long hours and heavy medication, it is something to be feared.

This condition is something rare but it is very real. The split brain syndrome is pretty much a multiple identity personality disorder in your database. If you have multiple nodes in a cluster, mirror or availability group, it is possible for more than one of those nodes to believe it is the master node and then for different transactions to become hardened in each of those nodes.

When this happens, you will not be able to use bleach to clean up the mess. Instead, you will be required to spend a grundle of time with your database cuddling it and nursing it back to data consistency and good mental health.

Last but not least, HAPPY HALLOWEEN!

What’s that SSIS Password

Categories: News, Professional, Scripts, SSC
Comments: No Comments
Published on: October 30, 2017

A recurring theme over the past several weeks (there are always recurring themes it seems) has been an issue that relates to SSIS. Clients will call for help with an SSIS package that has started failing and they are stuck trying to figure it out. They are all stuck at the same spot in the process – trying to get the package open. As it turns out somebody has decided to password protect the package in each case and the client is unable to open the package because they don’t know the password.

Inevitably they are all stuck at the following screen:

Granted this screenshot is for the password prompt for a project password – it really is the same issue if it is a package password. This seems like pretty good security right? If nobody knows the password then nobody can alter the package, right? At least that seems to be the prevailing course of thought.

Of course this introduces various other issues, one of which I alluded to already – a failing package. What if the requirements change? What if the package needs to be migrated? What if the package needs to be documented from stem to stern? Even better -what if this type of security is not all it is purported to be?

SSIS Security

Microsoft has provided various different “protection” levels for affecting sensitive information within a package. These levels can be set from within the GUI or from the dtutil utility. Here are some of those settings.

Setting Description Value
ServerStorage Rely on SQL Server database roles for protection. Only valid if saved to msdb and not to the file system.
DontSaveSensitive Suppresses the values of sensitive properties in the package when the package is saved. 0
EncryptSensitiveWithUserKey Uses a key that is based on the current user profile to encrypt only the values of sensitive properties in the package. 1
EncryptSensitiveWithPassword Uses DPAPI to to encrypt sensitive values in the package based on a user generated password. 2
EncryptAllWithPassword Encrypt the entire password based on a user generated password. 3
EncryptAllWithUserKey Uses a key based on current user profile to encrypt the package. Only the user that encrypted the package can open or run the package. 4

Based on these descriptions, a look at the package contents (via notepad) would look something like this:

The package will have that ProtectionLevel value added to the xml of the package with the selected value based on the descriptions from the previous table. In the case of this image, it appears that the package in question has been set to “EncryptSensitiveWithPassword” which correlates to a value of 2. This is also what is causing that password prompt to be displayed when opening the package.

So What’s that SSIS Password?

First, a bit of a birdwalk. Some will say you don’t need that password. They say you can go ahead and just change the “ProtectionLevel” value in the project/package xml and all will be rosy good. That may or may not work. Try it at your own risk. That said, if your ProtectionLevel is at a value of 2, there is an alternative method you could retrieve that password. I am going to show you just how to do that.

This method is going to need to assume that the package is being executed via a SQL Agent job and that you also have access to view job properties on the server in question.

Let’s just jump straight to a script to help us with that.

Take note here that I am only querying the msdb database. There is nothing exceedingly top secret here – yet. Most DBAs should be extremely familiar with these tables and functions that I am using here.

What does this show me though? If I have a package that is being run via Agent Job in msdb, then the sensitive information needs to be decrypted somehow. So, in order to do that decryption the password needs to be passed to the package. As it turns out, the password will be stored in the msdb database following the “DECRYPT” switch for the dtutil utility. Since I happen to have a few of these packages already available, when I run this particular query, I will see something like the following in my results.

Now, let’s go ahead and take one of those packages and test this out. I will just take the password that was listed for one of the packages, find the path of that package and then try to open the package using the password I just uncovered. Let’s keep it simple and say I am trying to open the first package called “Sports Adobe Ticket Sales Data Upload”.

After finding the package in question, I enter the password – shown here.

After I click the “OK” button, I am greeted with the following.

Tada! I now have full access to the package fully decrypted. If I need to change the ProtectionLevel, I can easily do that now as well. From here, I am set to proceed with troubleshooting the failure or any of the other reasons I noted for needing to gain access to the package.

 

Conclusion

Occasionally it becomes necessary to access an SSIS package that may be encrypted with a password. This is easily accomplished (unfortunately) if the package happens to be run via a job in SQL Server. While it is possible to gain access to the package, it would be far better to not need to circumvent the security to gain access. Instead, it would seem a much better idea to properly document the necessary passwords etc in a common vault so the appropriate people could access the package in the event of an emergency.

Drop That Schema

Categories: News, Professional, Scripts, SSC
Comments: No Comments
Published on: October 27, 2017

An often under utilized or maybe even mis-utilized feature of SQL Server is a database object schema. In the event of the latter, there is an occasional requirement for change. When this need arises, it can turn into a bit of a problem. That is of course if we are not well prepared. In this article, I am going to explore one possible change – the dropping of a schema.

What is a Schema?

A schema is a distinct namespace to facilitate the separation, management, and ownership of database objects. It removes the tight coupling of database objects and owners to improve the security administration of database objects (Source: Technet).

Much like a skeleton is a distinct system that helps support the structural integrity of certain biological entities, a schema helps to support a distinct functioning and structure within a database. This is, of course, a very simplistic description and analogy, but it works.

Another way to look at a schema is almost like a blueprint of what has been or will be created within the database. Like many blueprints, a database schema can map out all sorts of “sub-systems” at our disposal within the database. Some of these may include functions, procedures, tables, views and so forth.

What happens when you try to take out the entire blueprint without understanding the relationship to all of the subsystems? In the case of the schema it just so happens that you will be presented with an error message informing you that you are trying to do something that is either ill-advised or not supported or both.

Here is an example of such an error.

Msg 3729, Level 16, State 1, Line 2
Cannot drop schema ‘Maintenance’ because it is being referenced by object ‘AutoStatsHistory’.

This error message proves to be helpful. I obviously have some objects bound to the schema that need to be blown away before I can drop the schema. If I only have a few objects, this may not be too terribly annoying to do one by one. But what if I have 100 or more objects? Now that becomes an entirely different story.

Drop that Schema!

I have run into this very issue where there are far too many objects in the schema to be able to drop one by one. Add to the problem that I am looking to do this via script. Due to the need to drop the schema and the (albeit self imposed) requirement of doing it via script, I came up with the following that will cover most cases that I have encountered.

And a sample of the output:

As you can see here in the output, I have set the script to generate a series of drop statements for each of the dependent objects within the schema. In addition, the drop statements are ordered to remove objects that may have dependencies on other objects first. A big key here is that this script does not drop the objects for you. Rather it just creates the scripts to do the work. You must review the output and then execute the scripts separately. That means you will be entirely responsible for the results.

Once all of the objects are out of the way, the last statement in the sequence is to finally drop the schema.

You may notice that there are a few things not included in this script. The most notable may be that the Service Broker related objects are not accounted for in this script. I leave that for a later revision.

Conclusion

Occasionally it becomes necessary to remove a schema from the database for one reason or another (e.g. somebody decided to do both Dev and Prod in the same database separated only by schemas). Dropping a schema can become a little bit of a pain without the right tools. This script will help get you on your way to a scriptable solution (to help with documentation of what was changed) and a little less pain while doing it.

Seattle SQL Pro Workshop 2017 Schedule

Categories: News, Professional, SSC
Comments: No Comments
Published on: October 26, 2017

db_resuscitateSeattle SQL Pro Workshop 2017

You may be aware of an event that some friends and I are putting together during the week of PASS Summit 2017. I have created an Eventbrite page with all the gory details here.

With everybody being in a mad scramble to get things done to pull this together, the one task we left for last was to publish a schedule. While this is coming up very late in the game, rest assured we are not foregoing some semblance of order for the day. 😉 That said, there will still be plenty of disorder / fun to be had during the day.

So the entire point of this post is to publish the schedule and have a landing page for it during the event. *

Session Start Duration Presenter Topic
Registration 8:30 AM All
Intro/Welcome 9:00 AM 10 Jason Brimhall  
1 9:10 AM 60 Jason Brimhall Dolly, Footprints and a Dash of EXtra TimE
Break 10:10 AM 5    
2 10:15 AM 60 Jimmy May Intro to Monitoring I/O: The Counters That Count
Break 11:15 AM 5    
3 11:20 AM 60 Gail Shaw Parameter sniffing and other cases of the confused optimiser
Lunch 12:20 PM 60   Networking /  RG
4 1:20 PM 60 Louis Davidson Implementing a Hierarchy in SQL Server
Break 2:20 PM 5    
5 2:25 PM 60 Andy Leonard Designing an SSIS Framework
Break 3:25 PM 5    
6 3:30 PM 60 Wayne Sheffield What is this “SQL Inj/stuff/ection”, and how does it affect me?
Wrap 4:30 PM 30   Swag and Thank You
END 5:00 PM Cleanup

*This schedule is subject to change without notice.

Seattle SQL Pro Workshop 2017

Categories: News, Professional, SSC
Comments: No Comments
Published on: October 19, 2017

Seattle SQL Pro Workshop 2017

October is a great time of year for the SQL Server and Data professional. There are several conferences but the biggest happens to be in the Emerald City – Seattledb_resuscitate

Some friends and I have come together the past few years to put on an extra day of learning leading up to this massive conference. We call it the Seattle SQL Pro Workshop. I have created an Eventbrite page with all the gory details here.

That massive conference I have mentioned – you might have heard of it as well. It is called PASS Summit and you can find out a wealth of info from the website. Granted there are plenty of paid precon events sanctioned by PASS, we by no means are competing against them. We are trying to supplement the training and offer an extra avenue to any who could not attend the paid precons or who may be in town for only part of the day on Tuesday.

This year, we have a collision of sorts with this event. We are holding the event on Halloween – Oct 31, 2017. With it being Halloween, we welcome any who wish to attend the workshop in FULL costume.

So, what kinds of things will we cover at the event? I am glad you asked. Jimmy May will be there to talk about IO. Gail Shaw will be talking about the Query Optimizer (QO). Louis (Dr. SQL) will be taking us deep into Hierarchies. Andy Leonard will be exploring BIML and Wayne Sheffield will be showing us some SQL Injection attacks.

That is the 35,000 foot view of the sessions. You can read more about them from the EventBrite listing – HERE. What I do not yet have up on the is what I will be discussing.

My topic for the workshop will be hopefully something as useful and informative as the cool stuff everybody else is putting together. I will be sharing some insights about a tool from our friends over at Red-Gate that can help to change the face of the landscape in your development environments. This tool as illustrated so nicely by my Trojan Sheep, is called SQL Clone.

I will demonstrate the use of this tool to reduce the storage footprint required in Dev, Test, Stage, QA, UAT, etc etc etc. Based on client case study involving a 2TB database, we will see how this tool can help shrink that footprint to just under 2% – give or take. I will share some discoveries I met along the way and I even hope to show some internals from the SQL Server perspective when using this technology (can somebody say Extended Events to the Rescue?).

Why Attend?

Beyond getting some first rate training from some really awesome community driven types of data professionals, this is a prime opportunity to network with the same top notch individuals. These people are more than MVPs. They are truly technical giants in the data community.

This event gives you an opportunity to learn great stuff while at the same time you will have the chance to network on a more personal level with many peers and professionals. You will also have the opportunity to possibly solve some of your toughest work or career related problems. Believe me, the day spent with this group will be well worth your time and money!

Did I mention that the event is Free (with an optional paid lunch)?

Linked Servers and Stats

Linked Servers

A linked server is a fabulous feature in SQL Server to help accomplish various data tasks between local and remote servers. There is a time and a place for the use of linked servers. Unfortunately, some are of the belief that a linked server is the solution to all problems including the way to end world hunger.

You may recall that I have written about linked servers on a few occasions. Usually that is due to the relationship of a poorly performing process and the linked server. Here is a prime example here or here. On the other hand, here are some examples of using a linked server in a much better light here and here.

Using a linked server is entirely up to you. If you choose to use a linked server, you will need to understand there are risks involved – beyond just the documentation and performance nightmares it can cause. Today, I will share one of those fabulous gotchas – mostly because it has cropped up more than once with my clients.

Remote Stats

On more than one occasion I have had an emergency request because everything was broken. The everything in almost every incident is an SSIS package that is failing with error messages. The error message will typically have text similar to the following:

Could not locate statistics ‘_WA_Sys_00000015_346C780E’ in the system catalogs.

Due to the error, the package fails processing and grinds to a halt. When diving into the package it is discovered that the missing stats happen to be coming from a linked server query. This raises a big bright blaring alarm for me. Why is the SSIS package accessing the data via a linked server? This is rather counter-productive and definitely contrary to what is desired from a performance perspective.

You can certainly see why this is a sudden emergency right? Absolutely nothing is working anymore, right? Well, at least that is the way it seems for the person reporting the issue. Understanding that their realm of work has come to a halt is important in order to get to a resolution more quickly. Knowing that the point of failure is not as grande scale as claimed is critical because it can help you keep your cool while assessing the real problem.

Since the problem presents itself when accessing a specific object or even set of objects across a linked server, we have our scope of the issue scaled down quite a bit already. Now, what do we do from here? Obviously the statistic with that name is missing, right? Don’t be so hasty to assume it is actually missing. Let’s verify that the stat is indeed missing first. Even better – let’s just eliminate as many variables as possible. We can do this by querying the affected objects directly from SSMS.

Easy Troubleshooting for the DBA

 

For me, it is essential to eliminate variables when we run into a failure. In this case, I have just a few major variables that can potentially be causing this problem. Those variables are:

  1. SSIS
  2. Linked Server
  3. The query itself
  4. Security
  5. Bad Plan
  6. The stat is legitimately missing

I can easily assess the legitimacy of each variable through various quick tests. To eliminate or validate the “query” variable, I can issue a very simple query to retrieve data from the affected object. So let’s eliminate variables 1 and 3 in one fell swoop.

This query, in this scenario, results in the following:

This, while disappointing, is actually quite productive. This has eliminated two variables for me. I now know that SSIS is not related to the problem. I also know that query complexity is not related to the problem. There are still a few variables left to either validate or eliminate. Since I know the problem occurs when querying via linked server, let’s try querying the remote server direct (not via the linked server).

Well, while that does not entirely eliminate or validate any variables, it does tell me that the problem is still specifically related to the linked server. What if I try to use OPENQUERY instead of the traditional linked server query?

Wow, look at that? Ok, so this is a bit of trickery because I have told SQL Server to execute that query on the linked server as if it were a “local” query on that server. This does work without error and is definitely pushing the findings to be more conclusive that it is a linked server problem.

While the openquery version works, I do still need to eliminate some variables from the problem. One of the variables is security. Since the error mentions sp_table_statistics2_rowset, I googled about for that proc and found some mentions that maybe there are some column denies related to the stats in question that is giving the linked server some major fits. Or it could also be insufficient permissions to execute DBCC SHOW_Statistics. I highly doubt this to be an issue since the openquery version works while using the same pass through authentication of the linked server that the traditional linked server query would use.

In order to eliminate security as a potential cause, the test is simple (while it could be more complex, I went for the jugular to just eliminate the theory as quickly as possible) – I will add my account as the pass through account (which is a sysadmin on the remote server) and then query the linked server all over again. Suffice it to say, there was no change in the result – the error persisted.

This does not just yet eliminate the security variable because there could be a cached plan somewhere. So, just to be sure, I chose to flush the cache on both the linked server and the local server. Running the simple “Select *” query all over again yielded no difference in the query results. I can now safely saw that the problem is not related to a cached plan nor is it related to the security. At this point, I set the linked server security back to the way it was. I have effectively eliminated all variables but 2 and 6 (linked server and the stat is missing).

Let’s eliminate the missing stat variable right now.

Undoubtedly you have noticed that I built a drop statement into the result set from this particular query. That aside, the green highlighted row is the very stat that was producing the error. This stat is most certainly available on the source server (linked server). This entirely eliminates the sixth variable because the stat is not missing.

This brings us to the final step – see what happens when we drop the stat and try the query again. I have the drop statement ready to roll, so let’s just run that and see what happens. My risk here is very small. This is an auto-generated stat and will be recreated if needed. After dropping the stat, I run the simple “Select *” query across the linked server again and guess what? It works perfectly fine.

In my opinion, we can just skip a few of these steps if the problem is on a system generated stat and just go straight to dropping the stat and trying again.

That said, the better solution in this case would be to do one of two things.

  1. Modify the Package to not use the linked servers in this way and create a data source connection for each of the different server connections.
  2. Modify the Package to use OPENQUERY style queries.

My preference between those two options would be to create specific data sources. It seems very silly to pull data across the linked server to then be consumed via SSIS package.

I have just illustrated what I would classify as a nuisance problem related to linked servers. Simplifying the approach as I described with the two potential solutions would alleviate this nuisance while also giving an inevitable performance boost.

Your Name is Your Brand

Categories: Blogging, Professional, SSC
Comments: 3 Comments
Published on: October 13, 2017

This topic is one that has been stewing for a while and finally this week it decided to boil over.

My first thought with this post was to write a rant. Instead, I want to try and turn it on its end and try to put a different spin on the problem. Yes – I said problem.

Know your Audience

This started when I was setting up a piece of software (to demo to a client) for a vendor that I respect – A LOT. I noticed something peculiar about the software that was different than the documentation (and therefore expected result). I reached out to my contact at this company and he escalated a ticket to their support staff. After a few back and forth threads, my contact noticed something troubling – as had I. While I was going to set it aside but my contact was bothered by it too. The support personal started calling me by the wrong name.

Addressing somebody by the appropriate name or title is a pretty important topic. In this case, not only did they start addressing me by some other name, they had also lost sight of the existing relationship I had with this company as well as any previous information provided to them demonstrating level of expertise in the area of SQL Server or with the specific observation being reported. This is demonstrative of a lack of attention to detail – both in regards to the audience and the technical problem.

Your Name is Your Brand

If I throw a few names out there like Paul Randal, Steve Jones, Grant Fritchey or Brent Ozar, chances are you will know who those people are (given you are reading this blog post). These are people (like many other giants in SQL Server) that have built a brand based off their name. This is a good thing. You recognize the name and you recognize that they are very good at what they do.

Building your brand is not an overnight sensation. It does take a while and possibly a bit of luck here or there along the way. The one thing it always starts with is your name. This leads me to my next story.

This week I have been at Summit. This is not the traditional DBA Summit hosted by PASS, rather this is related to Dynamics (AX, NAV, GP, CRM, 365). Just like most conferences, we all get a nice easy to read name badge.

Hopefully you can easily read that mine clearly says my name is “Jason”. Besides the name, there is a QR code on the badge. Otherwise, the name is large enough you can generally read it from afar.

While meandering through the Exhibitor Hall, I stopped at one particular booth that was raffling off an R2D2 that particular day (they also raffled off a C3P0 and a Yoda on other days). And yes it is very rare for me to stop at one of these raffles – but it was R2D2.

As I was stopped to fill out the form for the raffle, I was approached by an eager booth dude. “Hey Larry, how’s it going?” he said. He was obviously talking to me, so I turned to him and said “Jason” while showing him the name on my badge. Not even 30 seconds later he did it again “So, Larry…”. At the sound of that, I had to cut him off and correct him again and reminded him I had just told him my correct name and even showed it to him via the badge. At this point I abandoned the R2 raffle and told him I was no longer interested.

This was coming from a vendor that was more than likely hoping to try and pitch their software. A lack of attention to the audience at hand just cost him a lead (albeit small compared to the number they gained). Now, that vendor has to worry about the word of mouth that may come from their lack of attention and focus.

Now, my name is pretty important to me. It may not be as important to you – but it is to me. Similarly, your name should be extremely important to you. You and I are all working at a similar task – building our own brand based on our names.

I am sure both of these vendors I have illustrated are also keen on building the brand around the corporate name they have established. Brand and name are recognizable. Now, put yourself in either of these two scenarios I have just described. Have you ever made a mistake with somebody else’s brand? Or, have you ever been on the receiving end of this kind of mistake? Suddenly the world is spinning a slightly different direction, right?

I won’t divulge the names of either vendor in this case (partly because I still have a good relationship with the one and I have already forgotten the name of the second), but think about this: What do you do for your brand when somebody steps on it? How we react (and granted I probably could have taken a higher road in the second case by gently reminding the vendor yet again what my name was) can do quite a bit for building a brand. It’s not always about what you know, but also about how you conduct yourself towards and around others.

Seed Post for SSG Syndication

Categories: SSG Syndication
Tags: No Tags
Comments: No Comments
Published on: September 27, 2017

Some Text here to seed the syndication.

«page 1 of 61








Calendar
December 2017
M T W T F S S
« Nov    
 123
45678910
11121314151617
18192021222324
25262728293031
Content
SQLHelp

SQLHelp


Welcome , today is Tuesday, December 12, 2017