Wednesday, January 08, 2014

Enable Change Data Capture (CDC) in your SQL server database

-- First enable CDC at database level.
USE MyDb
GO
EXEC sys.sp_cdc_enable_db
GO

-- Then enable CDC for all the tables in the database (excluding sys table and tables that starts with '_')

BEGIN
IF OBJECT_ID('tempdb..#tempTables') IS NOT NULL DROP TABLE #tempTables

SELECT
Row = ROW_NUMBER() OVER (ORDER BY t.Name),
t.Name
INTO #tempTables
FROM
sys.tables t LEFT JOIN
sys.schemas s ON t.schema_id = s.schema_id
WHERE
type='U' and -- only user tables
t.Name NOT LIKE '[_]%' and -- ignore table that have a name that starts with '_'
t.Name NOT LIKE 'sys%' and -- ignore table that have a name that starts with 'sys'
s.name = 'dbo' and -- only dbo tables
t.is_tracked_by_cdc = 0 -- exlcude tables where cdc is already enabled
ORDER BY Row

Declare @row int = 0
Declare @tableName nvarchar(50)

SELECT @row=Row, @tableName=Name FROM #tempTables WHERE Row=1
WHILE @tableName IS NOT NULL
BEGIN
print 'Enabling cdc for table ' + @tableName

EXEC ('EXEC sys.sp_cdc_enable_table @source_schema = N''dbo'', @source_name   = N''' + @tableName + ''', @role_name = NULL')

SELECT @row=min(Row) FROM #tempTables WHERE Row>@row
SELECT @tableName=Name FROM #tempTables WHERE Row=@row
END

IF OBJECT_ID('tempdb..#tempTables') IS NOT NULL DROP TABLE #tempTables
END

Tuesday, December 04, 2012

Howto create a build definition on TFS

This morning I had the great idea to setup a build definition and make it run on our TFS server.
This build definition is for an ASP.NET website project that uses also some msbuild tasks. This is how it went.

First let's say that you have your TFS installed and running: at this point congrats to yourself because this is not a small achievement. I'm doing it now...

Then we try to create the build definition. And here we have the first error:

TF225001: Creating a build definition requires a build controller be defined for this team project collection. There may not be any controller configured or you may not have permission to view them

So let's say what google have for us. Here is a guy that explains how to fix this. Be aware that you will need to remote desktop your TFS server to solve this issue and the others I found.
After creating the build controller and agent I found out that I still had the same error. So I double checked and came out that I selected the wrong "Project Collection". So pay attention to select the right collection.
You will also need to create a shared folder for the output of the build: I created a c:\temp folder and shared it as \\server\temp. Yes not a great name but we can change that later (don't name it builds because tfs creates a c:\builds folder and I'm not sure what  will happen if you name it the same: better not to try!).

http://mohamedradwan.wordpress.com/2010/05/15/cant-create-new-build-definition-in-tfs-2010/

Finally you can create your build definition from the team explorer under visual studio (see view menu). It's quite straightforward. You select the probject(s) you need to build and that's and when to build it: for example on every checkin (continuous integration) or on request.

So I tried to build the project(s) and here came the first build error. In our project we are using some msbuild tasks so I needed to install this on the server:

https://github.com/loresoft/msbuildtasks

Tried to build again and here is the next error:

error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

Came out that even Microsoft MVPs and consultants most of the times don't know what they are doing:
http://social.msdn.microsoft.com/Forums/da-DK/tfsbuild/thread/fc5e7c6b-0ecd-4c5f-bda2-e5c7f19221a8

Anyway at the end of the post a user found the solution is to install the VS 2010 shell you can find here:
http://www.microsoft.com/en-us/download/details.aspx?id=115

Next run complains about missing Silverlight SDK so let's install it on the server:
http://www.microsoft.com/en-us/download/details.aspx?id=7335

Try to build agian and... this is funny!
C:\Program Files (x86)\MSBuild\Microsoft\Silverlight\v4.0\Microsoft.Silverlight.Common.targets (104): The Silverlight 4 SDK is not installed.

But... I just installed it! Ok so let's google for the problem:
http://stackoverflow.com/questions/3001083/msbuild-command-line-error-silverlight-4-sdk-is-not-installed
At the very end of this question a guy having the same problem with tfs suggests the solution:
http://stackoverflow.com/a/9252174/789165

Ok... I feel a little scared but let's try to build it agian.... damn I knew it! So let's see what we have this time:
The type or namespace name 'Interactivity' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)

This is an error about Silverlight. But I have the SDK so what am I missing...
http://blakenui.codeplex.com/discussions/228884
oh... the Blend SDK...
http://www.microsoft.com/en-us/download/details.aspx?id=10801
Sorry the Blend SDK for silverlight 4 becasue they are different of course! The other on is for WPF...
http://www.microsoft.com/en-us/download/details.aspx?id=3062

And now what....
The type or namespace name 'NumericUpDown' could not be found (are you missing a using directive or an assembly reference?)
You need to install the silverlight toolkit to fix this:
http://silverlight.codeplex.com/downloads/get/117046

Finally it seemed to work. The very last problem I had was something about the AssembltInfo.cs FileUpdate task we have to update the assembly version on each build. The error was:
The process cannot access the file '...\AssemblyInfo.cs' because it is being used by another process.

It came out that on a project we were referencing too much AssemblyInfo.cs files so I replaced this:

<CreateItem Include="**\AssemblyInfo.cs">
<Output TaskParameter="Include" ItemName="AssemblyInfoFiles" />
</CreateItem>

With this:

<CreateItem Include="$(ProjectDir)Properties\AssemblyInfo.cs">
<Output TaskParameter="Include" ItemName="AssemblyInfoFiles" />
</CreateItem>

This is what I have for now. It's not bad but it's not enough because on the "drop" folder (the folder where tfs puts the output of the build) I don't have the zip files that are generated by the msbuild tasks. I will save this for another day!

Sunday, July 29, 2012

The most amazing week in London so far


The last few days here have been amazing! London is a continuous surprise and unexpected is sometimes so unexpected!
Last week a colleague of mine invited me to a show. She sad it was something really interesting and very difficult to get tickets for. I usually say yes to wherever they invite me, and this time wasn't an exception. So on Sunday we went to Stratford to attend the “bum bum train”. First of all let me tell you it's something I can't talk much about because it's a kind of a secret. I mean, people are invited not to talk about it too much to not ruin the surprise to other people who may go to the show. Anyway the least I have to say is that is an inspiring and overwhelming experience. Something you should try at least once in your life. Unfortunately it's sold out for this year until September so if you would ever like to go you will need to wait for the next year. But if you'll ever have the chance to go listen to me: go! Just one suggestion: get involved. Really!
On Thursday I went to see Mika again! This time it was a real show, not a short gig like the one I saw at Lovebox. The show was in Heaven club, actually the most famous gay club in London. I don't care! I just wanted to see Mika on a proper venue. Again, amazing! The show did last at least one hour and half. One song after another. All people singing and screaming. He performed really well, singing some of the new songs from the new album that is going to release on September. When he went back stage at the end of the show all people were screaming “Mika, Mika” so he came out and performed the song that gives the title to the new album “The origin of love”: a really touching interpretation.
So you could say that it was enough! And here it comes the unexpected...
I was drinking a beer with my colleagues after work talking about the olympics and the pain that will cause to the transports and to the people that actually lives and works here in London. I was feeling like kind of lucky to be quite far from the crowd and the traffic that the opening ceremony starting in less than three hours would have caused. And then the call... Luigi I have a spare ticket for the ceremony: would you like to come?.................................... Are you kidding me? Yes!!!!
So I started to run! I needed to be on the other side of London in an hour or so. I left my bike in the office run to the tube than back the office (I forgot the house keys in the back pack) then back again to the tube. Took the central line to Stratford from Hanger Lane. After 40 minutes I was in Stratford. From there I took the DLR and finally I was behind the shopping centre. Lucky me, I was in time!
So we entered the stadium area and passed all the security checks. It was like an airport checkin. Then we went towards the stadium and finally got into it. And then again another surprise. We wouldn't have been on the terraces. We were going to see the show from a very different perspective: from the middle of it!!!
So we entered the “standing area” and then they locked us in. We couldn't get out of there for reasons you can imagine. So they started to train the audience for how to take part of the show. Every seat had a led lamp they could use to make choreographies. Then at 9pm the show begun.
There were too much things. A lot of people involved. A lot of things. You probably have seen that on the tv. But being there was so exciting.
One of the most spectacular thing was the rings fireworks they did in the first part of the show. Most of the people saw it from a side or over it on the tv. But I actually saw it from the under. Probably the best view!
After the first part completed the athletes of each nation started to come into the stadium. This part wasn't so exciting at least not until the italian's athletes came out. So I run to the rail. They were there at no more than 2 meters. I screamed and took a whole lot of pictures!
And in the end the GB team came out and all the stadium went crazy. Then there were a few people talking and finally they light up the torch. And then everybody home!

Saturday, June 23, 2012

The bus drivers strike

Yesterday I went to an Italian restaurant. We wanted to have a real Italian dinner. We went to "La porchetta" in Holborn. It's a really nice and friendly place. The waitress and the manager were both Italians. It didn't take too long for us to become best friends! We had some italian red wine: 1 litre actually! It was really good. Also the "bruschetta" and pasta were really good. And finally the "tiramisu" and italian coffee. Good! I was missing all that.
After that we want to the Sway Bar that is not too far from the restaurant. Again a nice place. There were two dance floors with different music. We had some fun there for a couple of hours. When it was almost two o'clock we decided to quit. Valentina took a ride to Willesden Green and I started to wait for the N207. But it didn't took too long before I understood that it would have never come. I still didn't know why. Anyway I decided to get the first bus towards west in order to try to reach Acton with some other routes. In the bus I discovered that there a were a strike! The first after 30 years!!! Fuck! The bus drivers are complaining because for the Olympics they want them to work more but they don't want to pay them more. They are absolutely right! But the point is that people needs to get home in some way during the night and there aren't so much alternatives. So I got off the bus at Marble Arch. Still far from Acton but a little bit nearer. There I waited for the 390 and I reached Notting Hill Gate. And then I found myself stuck! Fuck! There where no more buses towards west!
Don't ask me how... actually here it's something that happens continuously... I met a Californian girl with his boyfriend: an half Finnish half Italian guy with some punk style hair. And after one minute another guy came and the minute later the four of us we were sharing a taxi to Ealing Broadway (that is beyond Acton). It was a really strange situation on the ride to Acton. Talking with this people... really crazy. I don't know how to explain the situation. It was like a movie.

Tuesday, June 19, 2012

A month later, still in London

It's been a month since I updated my blog. Really a lot of things happened and I didn't had the time to write it down all nor a little of it.
So let's start from the end.Yesterday I watched the Italy vs Ireland match. I went to Mattia's house with his colleagues. I took with me the champagne I won singing at Roadhouse, so now it's gone and I need to go there again to win another one! The evening was amazing: we had some real Italian typical food from Naples and Rome. Just to name one we had some original "taralli".
Sunday, the 17th, I went to Lovebox. It is a concert in Victoria park with a lot of artists and three or four different stages. I went there to see Mika. He was amazing as usual but he just played for half an hour. So bad! I saw also Grace Jones closing the event and some other more or less known artists. I stood up for ten hours and now after two days I don't feel really good yet.
Friday I went to Guanabara! When they told me the name I was thinking it was a joke. In Italy with my friend we usually do word games like this just to name a place that we don't remember the name or doesn't exists at all. But trust me, this is the real name of this place and it exists! It's a Brazilian club near convent garden. It's a really nice place and I went there with some cs friends. There where a Brazilian band performing at the beginning and after 11.30pm they started with the disco music. I enjoyed it and had some fun. After the disco we went to Mc Donalds just to get back some energy. It was 3am and really cold. When I managed to get back to Acton it was 5pm but there where so much light that it did look like a 9am in Italy.
I'm really starting to get busy and it' just two month that I'm here. It's good of course but it's a little stressing.
A couple of weeks ago I bought a bike and now it's more than a week that I'm going to work riding my bike. They call it commuting, but don't ask me the meaning of this word. I'm lucky because it's really just a few miles but it's all uphill. I always thought that London was plain but again I was wrong. Of course when I go back home it's all downhill so it gets really relaxing.
The job is going pretty much good. After the initial couple of boring weeks now it's getting more interesting and I'm starting to work on something I'm more used to. I'm also starting to better understand people, even if I still have some difficulties when they speak fast or have strange or unknown accents.
I was thinking about going back to Italy on September for an holiday to see my friends but I got intrigued by a colleague proposal to go to a really interesting place... I need the passport!

Wednesday, May 16, 2012

First new job day

Today I had my new job's first day.
I got out of the house 45 minutes before entry time. I thought that was enough to cover less than 4km (2.3mi). I was wrong: the traffic was so jammed that the bus was crawling between cars.
I managed to get just few minutes late. Not bad as a first day!
Someone was so kind to take me to my office and then my new manager introduced me to at least half of the  stuff. I could be damn if I remember a name!
I watched a DVD about security. Really interesting... ok really boring! And after that I started to setup my new box with all the stuff I need to do my job. The most interesting part is that they gave me a brand new 24inch LED display. It's amazing to finally work with a screen that can hold all the windows you need at the same time! I never understood why companies in Italy keep on supplying 17inch screens to their developers: it's so stupid!
I had launch with my new Italian colleague: I was so hungry! I ate a lot so during the afternoon, considering also that the setup of all the stuff was taking a lifetime, I risked to fall asleep. Luckily the exit time came to rescue me! For me was really strange to get home at 6 o'clock. I was used to get back far later. And I was hungry again!
With so spare time in the evening I definitely need to find something like a gym. But let's wait for the first earnings to come in before spending more money: it's so weird and painful to pay pounds with euros! For example yesterday I bought some shirts for a total of 100£ that are 125€! To discover that now I will need to buy also the cuff links!

Sunday, May 13, 2012

We are the italian mob

Yesterday I received my uk debit card! Now I feel more comfortable: I don't clearly understand way but uk people don't like money if it's not coming from an uk account... I really don't get it! But you know, they are strange people and you need to adapt to some of their weirdness. It's fair, I mean: it's their country here!
So I could finally had my mobile contract sim card with three. It was really ugly to have an iphone without a data connection because it really becomes helpful when you need to take a bus to go home and you don't know where the hell you are.
So after having my brand new sim I finally met Mattia. He is a guy from Italy. I never actually met him in person. We have a friend in common who gave me his number before moving to London. He helped me in the first days giving me some advices about how to find a room and a job.
So we went out with some of his colleagues and I had my first after work friday here in London! There were an English guy, another Swedish one, two French guys and then five italians! Actually there were more poeple but I didn't had a chance to speak with them so much to understand where they came from.
We went of course to a pub and tried to get drunk with the discounted drinks but after three of them I was still far from getting drunk. The place was really nice and big. They suggested there could some girls because near this place there is the Lorèal UK office. No luck as usual! There were of course some girls actually but not as many as the huge Lorèal building suggests to be inside it.
We staid there a couple of hours speaking about... you could say about life. Then we took a bus and we went to an italin pizzeria. The pizza wasn't bad, even if I'm not a big fun of the neapolitan one.
After that we went to a pub with a 5£ entry fee. Here in London seems to be common to pay to enter a pub on a friday night. The place was nice and not so crowded so we were also able to speak. I was tired so after an hour or so I decied to quit.
I really met a lot of new people in just one night, more than in the last three weeks I think. But I didn't know what expect me the day after...