.NET (298) administrative (41) Ajax (42) AngularJS (2) ASP.NET (146) bicycle (2) books (185) browser (10) C# (135) cars (1) chess (29) CodePlex (10) Coma (8) database (52) deployment (3) Entity Framework (2) essay (116) flash/shockwave (2) flex (1) food (3) friend (2) game (21) idea (5) IIS (8) javascript (84) LInQ (2) Linux (6) management (4) manga (43) misc (688) mobile (1) movies (96) MsAccess (1) murder (2) music (64) mysql (1) news (101) NuGet (1) permanent (1) personal (68) PHP (1) physics (2) picture (318) places (12) politics (14) programming (514) rant (120) religion (3) science (43) Sharepoint (3) software (58) space (1) T4 (2) technology (12) Test Driven Development (4) translation (2) VB (2) video (102) Visual Studio (45) web design (46) Windows API (8) Windows Forms (3) Windows Server (6) WPF/Silverlight (63) XML (11)

Friday, February 27, 2015

"The transaction associated with the current connection has completed but has not been disposed." Well, not really

I was trying to solve another problem, that operations creating, altering or dropping databases cannot be made inside a .Net transaction. Therefore I created a new TransactionScope inside the main one, using the TransactionScopeOption.Suppress option, but then I started getting this weird exception: The transaction associated with the current connection has completed but has not been disposed. The transaction must be disposed before the connection can be used to execute SQL statements. But I did Complete and Dispose all my transaction scopes, so what was going on? Long story short, this is really confusing message for a simple problem: your transaction probably timed out. Create the transaction scope with a large TimeSpan as the Timeout and it will get through. If you can, you can use a try/catch/finally block in which you Dispose the transaction (just remember that a using construct is basically a try/finally block). In my case, I was conditionally creating this new TransactionScope, so I wasn't using using. The transaction would fail, bleed into the other transaction where the confusing exception was being thrown.

Thursday, February 26, 2015

T-SQL AVG function fails when SUM fails

I have another SQL quirk for you today, particularly in Microsoft's SQL Server. It concerns the AVG function when the SUM of the averaged values would result in an overflow for that type: AVG fails with the same error. Let's imagine for a moment that we wouldn't have an AVG function. In that case, our code would use SUM and COUNT to average values. For the integer column x, the naive SUM(x)/COUNT() would fail when the sum goes over the INT maximum value (I am not sure that SUM should fail, either, but that is another discussion). So our solution would be something like CONVERT(INT,SUM(CONVERT(BIGINT,x)))/COUNT(). Obviously, this is the solution for the AVG issue, just average the values converted to the biggest type available. So it seems that in their flagship SQL server, Microsoft implemented the naive version, hmm... To be fair, this behaviour is documented in the T-SQL function page: If the sum exceeds the maximum value for the data type of the return value an error will be returned.

As I see it, it is a bug, as this should have been handled internally, and one is logged in Microsoft Connect here: AVG function causes Arithmetic overflow error. Read the funny comment from some Microsoft employee who says there is a solution proposed, but they don't have time to implement it in SQL Server 2008, so probably they will do that in a future version. I'm trying on SQL Server 2014; it's 7 years later, Microsoft!!

Just for kicks, I tried the same in MySQL and it works there. More than that, it doesn't fail for SUM, either, as it automatically returns a BIGINT value, pushing the issue to an eventual insert or update in an INT column.

Monday, February 23, 2015

Star Trek: Aurora. Will the wonders never stop?

Just days after I was saying how great Star Trek New Voyages/Phase II was, I stumble upon this gem of a story: Star Trek Aurora. It is a 3D animated full movie set in the Star Trek universe. Even if the animation is primitive, give it a few minutes. The acting is good and the story is really nice and original, with a believable female character and a fresh perspective on the Star Trek universe. I am embedding here the full movie, but also go to their web site and YouTube channel, since they have more work coming!

Friday, February 20, 2015

Star Trek New Voyages - Simply Amazing!

A while ago I wrote a post about "unofficial" Star Trek series and movies, made by fans for the fans. Some quite awful, to my chagrin, but some quite engaging and with good production values. But I have to say that Star Trek New Voyages is just wonderful. Yet another series continuing the original, with captain Kirk at the helm of the Enterprise, it has some of the best Star Trek scripts I have ever seen and the acting is not bad, considering they are all amateurs, and the production values are good, considering that it is made by German studios (in English with American actors, have no fear!)

When I fell in love with Star Trek I did it in the time of Jean Luc Picard and The Next Generation. As much as it irks me to admit it, I liked it for the same reason my father liked it: the stories! The sci-fi was great, but it only enhanced what was already there: great stories about real people in real situations, focusing on positive traits like friendship, loyalty, love, intelligence, skill, courage, happiness, passion. With Star Trek, people have found that there is a higher ideal that they can aspire to.

Well, New Voyages has all of that: dedicated people doing the series out of passion, having the courage to get together and do something out of friendship and loyalty, but with intelligence, skill and soul. I present to you a team of people actually living their dream, and making the fans dreams come true as well. Just great stuff! And if it isn't enough, all the episodes are free to watch on their website, in high definition and with subtitles in several languages. And just in case you were wondering, original actors from the original series like George Takei (Sulu) and Walter Koenig (Chekov) are helping out.

Just watch it, it's just fantastic! I leave you with one of the best episodes (so far): World Enough and Time

Wednesday, February 18, 2015

House of Cards, by Robyn Dawes

Book cover House of Cards - Psychology and Psychotherapy Built on Myth is a very good book that needs more recognition. It describes and really criticizes the lack of scientific method in psychology and debunks the myth of the experienced psychologist as well as many others that are now taken for granted in the field. Unfortunately the book is also very detailed, filled with expositions, repetitions of concepts and statistical information on the studies that prove the author's point, so it is rather difficult to read; it is certainly not a book you take to help you relax. Every psychologist in the world should read it, though, as well as any aspiring students or people considering going to therapy.

To make it clear, this is not an anti-psychology book. It continuously says that therapy helps. What it also says is that the amount of training and experience of the therapist is statistically irrelevant. That irritates the author tremendously, as he is a psychologist himself and desires that his chosen scientific field evolve and ... well... become a real science. Robyn Dawes unfortunately died in 2010, at the ripe age of 74. During his life he studied human irrationality, intuitive expertise and statistical applications in medicine and psychology. No wonder that in House of Cards, he is ranting against the practice of psychology as it is today.

A few concepts in the book are very interesting and quite frightening. After WW2, a lot of people came traumatized and needed mental attention. At the time, a psychologist needed to be a psychiatrist as well, having gone through the university and studied medicine; they were all doctors, with a Ph.D. degree. So what they did in the US was to create another type of degree, called Psy.D, letting people without medical training enter the field, with only minimal instruction. This created the myth of the intuitive expert who can tell things about people because he has experience, having little else. Dawes proceeds to mercilessly debunk this myth.

In order to do that, he uses - what else - the scientific method. He gathers data as objectively as possible and then tries to find correlations. One correlation that is not found is one between amount of experience (or indeed, formal training) and positive results. One that is, though, is that therapy does help. We just don't know (or better said, we don't know how to quantify) why. One obvious reason would be that, in order to come to therapy, people need to accept they have a problem and then make the first step in solving it: showing up. This alone shows that the person is already actively pursuing healing, a major step into healing themselves. He also analyses diagnosis, often using standardized tests that presumably can help a specialist determine mental issues and their type. However, presented only with test results, the experts don't really get to any useful conclusion.

Dawes is not stopping at psychology, even if that is his main focus. In one chapter he speaks of studies that have proven that doing a thing for a long time doesn't necessarily teach you anything, especially if there is no immediate feedback on whether what you did was good or bad. This also applies to some types of medical diagnosis. And yes, those people went through school - that has the main purpose to promote people who can get through it much more than to provide a comprehensive body of knowledge - and graduated, but when faced with ambiguous symptoms, they pretty much randomly guess what the patient is afflicted by. Think about that when you go to just one doctor and he tells you that he knows what you have because he's experienced.

Anyway, as I said, the book is difficult to read, it is more like a scientific paper and, as much as I wanted to finish it, I realize that I am not an aspiring psychologist, nor am I planning to go to therapy soon. Also, since I have people close to me interested in the field, it wouldn't help to talk to them about how they don't use the scientific method and they are not real doctors ;). Joke aside, this book is invaluable for anyone in the field. Not for me, though, and so I decided to indefinitely postpone reading it to the end.