August 17, 2017

Executing SQL queries in CRM database on behalf of another user

If you are using filtered views in SSMS it is not possible to see what data will be returned for other users. But there is a way!

The GUID of the user is stored in the SQL CONTEXT_INFO. All you have to do is to run this piece of code:

DECLARE @binUserGuid VARBINARY(128)
DECLARE @userGuid UNIQUEIDENTIFIER
SET @userGuid = 'GUID of the user you want to test'
SET @binUserGuid = CAST(@userGuid AS VARBINARY(128))

SET CONTEXT_INFO @binUserGuid

From now on you will be able to query the data as if you would be logged in as another user.

To clear the context info simply execute

SET CONTEXT_INFO 0x

I hope this helps those who are testing SQL queries for the CRM reports.

July 17, 2017

Have some respect!

Over the past five years I have been more and more involved as a speaker at the conferences. I had my first session at the meeting of Slovenian Developer Group (sloDUG), then soon my first session in English language happened at SQLSaturday Slovenia.

For those who don't know SQLSaturday events, these are FREE 1-day SQL training events made possible first by the organizers, who devote their free time to organize the whole event from scratch. Then there are sponsors who provide necessary funds for the event (renting the venue,  coffee and lunch for attendees, evening meal for speakers). And the last, but not least, there are the speakers who arrive from all over the globe, live on their own expenses and speak for free. Yes that's right! Free of charge. Even some sponsors are doing this just because they like the idea. All just for you knowledge thirsty enthusiasts. It's called giving back to the community. I too was once at the other end of the room listening to the speakers and admiring their enthusiasm.

Yes I do it for free, but I get paid with more than money, and I am sure that I am speaking on behalf of vast majority speakers at SQLSaturday. First there is this great feeling of spreading the knowledge when I deliver a good session and receive good feedback. Even better are the emails or tweets I receive after where people are commenting on the session or asking questions. But the best part of this whole thing are amazing friendships I have made with amazing people. We live in different countries and this is one of the ways we are using to meet again and hang together for a few days. Personally I always try to make this also into a short tourist trip, therefore I arrive at least a day early and leave at least a day later so I can explore the city and the country where I am speaking at.

Why am I writing this you ask? It all started with this tweet:


It happens and people tweet about it, no big deal. Some find it funny, some are feeling sorry for the speaker, and there are also some who take things like this personally.

Let's make it clear. Free event or not, speakers should prepare their sessions and themselves professionally. Go through the slides, the demos, see how much time you need and always think of what can you improve to make it better next time.

I'm not defending anyone here and I don't want to point any fingers, but then this tweet happened:

Wait what? Have some respect? How about you showing some respect? This "incompetent" speaker is one of the best professionals in his area of expertise and has taken his free time, paid for the trip and came to present to you for free so you could call him incompetent!

I just happened to be at this session. The speaker followed all the rules in the unwritten presenters rulebook. Two most important of them are: turn off all applications not needed for the session and prepare the scripts, do not type.

In the beginning everything went OK, but then scripts just failed to execute at one point. Then he started to type the commands 😐Of course this didn't work and at the end he decided to restart the computer. While restarting the computer he killed the time by explaining some things where demos were not need and had a short Q&A session. Basically he did everything he could do to make things better. Of course precious time was lost and he could not show everything he wanted to show in his session.

Boo-hoo, so what - it happens. Shit happens and it is called "The wrath of the demo gods". No matter how well you prepare yourself, there is always a chance that something will fail and eventually it will. The worst are online demos. The probability of connectivity problems in unimaginably high at the conferences. I myself have experienced "The wrath" twice. Both times there was something with SQL Management Studio. I restarted it and voila! Problem solved. In this case the restart of computer was needed, so it took a little longer to do so. Here the "incompetence" of the speaker is on display. Some would freeze and just wait in awkward silence for the computer to restart, some would try to kill the time with bad jokes 😬, but here the session actually continued.

I am sure that the author of the tweet above has seen better sessions but please don't judge people before you've walked a mile in their shoes.

So please have some respect for the speakers!