Sunday, March 15, 2009

Mid term blues

And the mid terms are here AGAIN... Exams never seem to end, do they?

And I still find myself wondering why I didn't study side by side.
If exams are not going on or about to start, studying doesn't seem an option at all. It's always I am tired right now. I do nothing fun the entire week so Saturday and Sundays are for that, having fun, chilling out, sleeping, watching tv and movies, NOT for studying.
But when the time's up I always always promise myself that this won't happen the next time. From now onwards I'll study hard, concentrate on my classes, read up on things on a weekly basis, search the topics we cover in class on the internet so that I get more knowledge, but even when I am thinking all of this I know they are nothing but empty promises.. and that's what they always turn out to be.

So right now... I am trying to study Design Patterns, am stuck with the Adapter patterns since about 8 in the morning. Trying to get the assignment done as well (yeah an assignment during mids, don't think we didn't try to stop him.. but there is never stopping teachers.)
I am still on the trying to study phase as I refuse to sign out of the two messengers installed on my machine, and so I continue chatting with my friends, who by the way don't have any exams so they can chat all they want.

My deciding to write a post for my mid terms is prove enough, I guess, that I am in no mood to study (am I ever?).

Anyways....... I think I should get back to the assignment. If anyone has ever done any assignment on "Parametrized Adapters" feel free to share... :P :P

Tuesday, March 3, 2009

SQL Server Triggers

Scenario:
  • Stop a query from execution
  • Know from the query was being executed.
Solution:
I was a bit skeptical about this. About the part where you execute a query from execution.
We knew we had to create a trigger for this, but how on earth would you stop a query from execution.
Turned out, SQL Server does provide a way to do that.

So let's take a look at the syntax of creating a trigger as put in on MSDN:

CREATE TRIGGER [ schema_name . ]trigger_name
ON { table | view }
[ WITH [ ,...n ] ]
{ FOR | AFTER | INSTEAD OF }
{ [ INSERT ] [ , ] [ UPDATE ] [ , ] [ DELETE ] }
[ WITH APPEND ]
[ NOT FOR REPLICATION ]
AS { sql_statement [ ; ] [ ,...n ] | EXTERNAL NAME }

::=
[ ENCRYPTION ]
[ EXECUTE AS Clause ]

::=
assembly_name.class_name.method_name

Trigger on a CREATE, ALTER, DROP, GRANT, DENY, REVOKE, or UPDATE STATISTICS statement (DDL Trigger)
CREATE TRIGGER trigger_name
ON { ALL SERVER | DATABASE }
[ WITH [ ,...n ] ]
{ FOR | AFTER } { event_type | event_group } [ ,...n ]
AS { sql_statement [ ; ] [ ,...n ] | EXTERNAL NAME <> [ ; ] }

::=
[ ENCRYPTION ]
[ EXECUTE AS Clause ]

::=
assembly_name.class_name.method_name

Trigger on a LOGON event (Logon Trigger)
CREATE TRIGGER trigger_name
ON ALL SERVER
[ WITH [ ,...n ] ]
{ FOR | AFTER } LOGON
AS { sql_statement [ ; ] [ ,...n ] | EXTERNAL NAME <> [ ; ] }
::=
[ ENCRYPTION ]
[ EXECUTE AS Clause ]

::=
assembly_name.class_name.method_name

The part in bold is what is responsible for getting the trick done.

You use INSTEAD OF when you don't want the query which fired the event to execute. And you mention the category the query falls under (the one that is to be stopped from execution) after INSTEAD OF.

So the Trigger become something like

CREATE TRIGGER trgr_Name
ON Tbl_Name
INSTEAD OF DELETE
AS
BEGIN
//Your code
END


Now, let's come to the second part. The part where you discover from which machine the query was fired.

And guess what? That has a simple enough syntax.

HOST_NAME() give you the name of the machine.
So all you have to do is declare a variable

DECLARE @Host_Name VARCHAR(20);
@Host_Name = HOST_NAME();



There was a whole piece of code for getting the IP from Host_Name, but I don't remember it exactly, so will put that when I find it. :)

The whole point of this post was so that I myself can find it when I need it again, as I don't really trust my memory for such important stuff. So no offense to all the people from whose websites I collected this material from.

Monday, March 2, 2009

And.... it's done!!!!

It's done.. I have finally given the presentation I was supposed to give for, I don't know, one month.. I have trying to avoid it, plus there were a lot of more pressing tasks to be completed. The task being the completion of a project and all.

Anyways, I should tell you what the presentation was about. It was about .NET Framework 3.0/3.5.

The story behind why I was given this particular topic to present was that since I joined I had been nagging everyone to migrate to 3.5 or at least make the new applications in 3.5. They finally got me to stay quiet by saying "Why don't you give a presentation on .NET Framework 3.5? Just highlight the new technologies introduced and convince us that we should migrate."
And since then I stopped mentioning 3.5.

Not that I didn't want to go through the hassle of making the presentation slides. It had more to do with gathering up the courage to speak in front of so many people (that means 10 people at the max) who you know have more knowledge than you about the topic you are speaking on.

Anyways, this time they scheduled it for Monday (that is, today 2nd March, 2009). I didn't get time in the office to work on the presentation, and I had a quiz this Saturday (which I am failing by the way) so I spent my entire Sunday on it. Full of tension, true, but learnt a lot things and that was fun.

I liked what WPF made possible, but I never really tried my hands on XAML, and I am glad I did for the presentation. Just a few lines of code were enough to get a button rotate on an angle of 45 and the window to appear in the form of Ellipse rather than the conventional rectangular shape one. :)

I might add a few references or a bit of the stuff I used in my presentation in near future (keep a note of 'might'). But none of the things I used were mine.... of course.. working on .NET 3.5 for a day doesn't make me any expert.

Anyways, almost the entire day, today (Monday) was spent on the presentation. I was supposed to cover all technologies (WPF, WCF, WF, WCS and LINQ) but was only able to touch WPF, WCF and LINQ. So in the morning it was decided that we'll go with this and for the rest of the things we'll schedule another presentation.
Showed the slides to my boss.
Then spent the rest of the time before presentation worrying about what I'll do when they start asking questions. And some of my team members encouraging me and telling me there is nothing to worry about. And also asking people not to ask questions.. the people I could ask to do so.
And installing Visual Studio 2008 on a laptop that will be used for the presentation, and not being able to.
Trying to find out why on earth does the VS 2008 on my Home PC doesn't color code XAML. Still don't have an answer for that though, can anyone answer that??

And finally the time for presentation came. Wasn't even able to connect the laptop with the projector. Two people were involved so that the slides could be projected for everyone to see.
During the presentation it seemed like I was giving it to my top-most boss only, with a few glances to the other people in the room. Couldn't help it. Even back in the days I used to debate, I concentrated mostly on one particular portion of the audience and had to make an effort to look at the others too.
A lot of questions were asked.
None of which I was able to answer :P
People got really excited about WPF though. :) And liked the two code examples I put in. :)

All in all the presentation went okay. With my supervisor supporting me by answering all the questions that were targeted towards me. And the rest of the team chipped in nice comments about the presentation and encouragement after the presentation ended. :D And it really felt good to hear those comments. :)

The remaining day was spent thinking 'shukar hai ho gaye presentation, tension to khatam huai'.

So an entire day was spent on a presentation. :P

Disclaimer: :P

This post is more for memory then for my two or three readers.. :) I should, like everyone else, keep the tag 'Dear Diary' as I have so many posts which fits this category. :)