Deploy a database project with TFS Build

When you develop web application you often have this scenario. Some people are testers, they are testing the application in dev all day, and they want always to test latest version. Moreover testers usually fills data into web application, so they want their data to be preserved between various deploy. If you simply clear all data in test database you will end with a lot of furious tester so do not even think to do this.
 
If a developer needs to change database schema, we need to automate not only the deploy of the web application, but we need also to sync test database with the latest changes. This is necessary so the test site can work with the new version, but old data is preserved for the happiness of the testers.
 
This is quite simple using TFS and Database project. The situation is this one

 

When a developer does a check-in, the build server grabs the tip from TFS, then it runs the builds script and deploy the new version of the site in the test web server. At the same time test database gets updated with the latest database schema.

Next we need the ability to automatically deploy changes to a specific database, this task is quite simple and you can find some details here in msdn, but we need to insert this command into the msbuild script. Here is the code:

<Target Name="AfterDropBuild"><Message Text="Deploy of project database" />
<MSBuild Projects="$(SolutionRoot)srcDbEditionNorthwindTestNorthwindTestNorthwindTest.dbproj"
Properties="OutDir=$(DropLocation)$(BuildNumber)debug;
TargetDatabase=NorthwindCiTest;
DefaultDataPath=C:Program FilesMicrosoft SQL ServerMSSQL.4MSSQLData;
TargetConnectionString=Data Source=VM2003R2_1SQLTEST%3Buser=sa%3Bpwd=Pa$$w0rd;
DeployToDatabase=true;" 
Targets="Deploy"/> 
</Target>

 

Original post from Ricci Gian Maria

http://geekswithblogs.net/jakob/archive/2012/04/25/deploying-ssdt-projects-with-tfs-build/

Visual Studio 2012 running slow

Three months in and my Visual Studio 2012 is running slow, I’ll even go as far as saying it is freezing up some times, so I loaded up SysInternals Process Monitor and set a filter on Visual Studio and to my complete and utter amazement I found PerfWatson running wild in the system

PerfWatson is designed to drive performance improvements and make Visual Studio faster by automatically reporting back to Microsoft, this sounds great but it is just running crazy on my machine and I need to take it off.

To take it off you need to be in Visual Studio 2012, if you can get it loaded, then go to the Tools/Extensions and Updates sections and you’ll find Visual Studio PerfWatson installed, just uninstall and it will be gone.

Another area to clear out is the WebSiteCache, which Kevin Rintoul wrote about on his blog Slow Visual Studio Performance … Solved!, which can be found at:

C:\Users\jQuery152010256510121984808_1361448287186jQuery152010612401940409233_1361449184152jQuery15207433351762976833_1361449212578??\AppData\Local\Microsoft\WebsiteCache

If you are using TFS with Visual Studio then another great tip from Nick on his blog post How to fix slow Visual Studio + TFS,

Edit the Visual Studio config file found in C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe.config
and locate the following line:

<system.net>

Right below (above settings, NOT under), insert the following line of code:

<defaultProxy enabled="false" />

Your visual studio should now be more responsive!

Anyone else got any tips to increase the performance of Visual Studio 2012 are most welcome.

Who is locking my SQL database?

Need to know who is logged on to your SQL database ,here is a nice script that I got from Gary Dunne

DECLARE @spid1 int = NULL      /* server process id to check for locks */ 
DECLARE @spid2 int = NULL       /* other process id to check for locks */ 

set nocount on
/*
** Show the locks for both parameters.
*/ 
declare @objid int,
   @dbid int,
   @string Nvarchar(255)

CREATE TABLE #locktable
   (
   spid       smallint
   ,loginname nvarchar(20)
   ,hostname  nvarchar(30)
   ,dbid      int
   ,dbname    nvarchar(20)
   ,objId     int
   ,ObjName   nvarchar(128)
   ,IndId     int
   ,Type      nvarchar(4)
   ,Resource  nvarchar(16)
   ,Mode      nvarchar(8)
   ,Status    nvarchar(5)
   )
   
if @spid1 is not NULL
begin
   INSERT #locktable
      (
      spid
      ,loginname
      ,hostname
      ,dbid
      ,dbname
      ,objId
      ,ObjName
      ,IndId
      ,Type
      ,Resource
      ,Mode
      ,Status
      )
   select convert (smallint, l.req_spid) 
      --,coalesce(substring (user_name(req_spid), 1, 20),'')
      ,coalesce(substring (s.loginame, 1, 20),'')
      ,coalesce(substring (s.hostname, 1, 30),'')
      ,l.rsc_dbid
      ,substring (db_name(l.rsc_dbid), 1, 20)
      ,l.rsc_objid
      ,''
      ,l.rsc_indid
      ,substring (v.name, 1, 4)
      ,substring (l.rsc_text, 1, 16)
      ,substring (u.name, 1, 8)
      ,substring (x.name, 1, 5)
   from master.dbo.syslockinfo l,
      master.dbo.spt_values v,
      master.dbo.spt_values x,
      master.dbo.spt_values u,
      master.dbo.sysprocesses s
   where l.rsc_type = v.number
   and   v.type = 'LR'
   and   l.req_status = x.number
   and   x.type = 'LS'
   and   l.req_mode + 1 = u.number
   and   u.type = 'L'
   and   req_spid in (@spid1, @spid2)
   and   req_spid = s.spid
end
/*
** No parameters, so show all the locks.
*/ 
else
begin
   INSERT #locktable
      (
      spid
      ,loginname
      ,hostname
      ,dbid
      ,dbname
      ,objId
      ,ObjName
      ,IndId
      ,Type
      ,Resource
      ,Mode
      ,Status
      )
   select convert (smallint, l.req_spid) 
      --,coalesce(substring (user_name(req_spid), 1, 20),'')
      ,coalesce(substring (s.loginame, 1, 20),'')
      ,coalesce(substring (s.hostname, 1, 30),'')
      ,l.rsc_dbid
      ,substring (db_name(l.rsc_dbid), 1, 20)
      ,l.rsc_objid
      ,''
      ,l.rsc_indid
      ,substring (v.name, 1, 4)
      ,substring (l.rsc_text, 1, 16)
      ,substring (u.name, 1, 8)
      ,substring (x.name, 1, 5)
   from master.dbo.syslockinfo l,
      master.dbo.spt_values v,
      master.dbo.spt_values x,
      master.dbo.spt_values u,
      master.dbo.sysprocesses s
   where l.rsc_type = v.number
   and   v.type = 'LR'
   and   l.req_status = x.number
   and   x.type = 'LS'
   and   l.req_mode + 1 = u.number
   and   u.type = 'L'
   and   req_spid = s.spid
   order by spID
END
DECLARE lock_cursor CURSOR
FOR SELECT dbid, ObjId FROM #locktable WHERE Type ='TAB'

OPEN lock_cursor
FETCH NEXT FROM lock_cursor INTO @dbid, @ObjId 
WHILE @@FETCH_STATUS = 0
   BEGIN
   SELECT @string = 
      'USE ' + db_name(@dbid) + char(13)  
      + 'UPDATE #locktable SET ObjName =  object_name(' 
      + convert(varchar(32),@objId) + ') WHERE dbid = ' + convert(varchar(32),@dbId) 
      + ' AND objid = ' + convert(varchar(32),@objId) 
   
   EXECUTE (@string) 
   FETCH NEXT FROM lock_cursor INTO @dbid, @ObjId    
   END
CLOSE lock_cursor
DEALLOCATE lock_cursor
 
SELECT * FROM #locktable
DROP TABLE #locktable

sp_lock2.sql (3.44 kb)

How and setup and got my Gadgeteer to work

This is a quick start guide for .NET Gadgeteer and the FEZ Spider Kit. It includes instructions for the installation of necessary software and drivers of the Gadgeteer platform as well as for the first Gadgeteer program. 

Okay so it does not like Visual Studio 2012, so I next need to download is 

1.   Microsoft Visual C# Express 2010
You can still use professional or ultimate.
2.   Microsoft .NET Micro Framework 4.2 QFE2 SDK
This SDK must be installed before step three.
3.   GHI Software Package v4.2 Feb. 18, 2013
Includes NETMF and .NET Gadgeteer SDKs and components. See release notes and known issues.

Should you already have installed C# Express or a full version of Visual Studio 2010. In a second step install the Microsoft .NET Micro Framework 4.2 QFE2 SDK (not 4.1!). You need to create an account on the GHI Electronics website in order to download and install the GHI NETMF v4.2 and .NET Gadgeteer Package in the last step.

First Gadgeteer Application

Run Visual C# Express and create a new Project.

You will start within the hardware layout view. Drag and drop the following modules from the left toolbox onto the white space near the spider mainboard:

  • UsbClientDP module
  • T35_display module
  • Button module

Right click on the white space and select “Connect all modules”. The IDE will automatically connect all your selected modules to compatible ports on the spider mainboard. Now all you need to do is to connect your physical modules the same way. Notice that all sockets on the mainboard as well as on the modules have labels on them (X,Y,U;S, etc.) that describe their compatibility (e.g. socket A modules can only be plugged into A sockets on the mainboard).

Plug the USB mini cable into the UsbClientDB module and connect it with a USB2.0 port on your computer (Hint: USB 3.0 does not work for me!). When  the Spider Kit is connected via USB for the first time, Windows will try to install the driver. If it fails, point the driver installation routine to the following folder (you can find the device as EMX in your system device manager):

C:\Program Files (x86)\GHI Electronics\GHI Premium NETMF v4.2 SDK\USB Drivers\GHI_NETMF_Interface

Select the Program.cs tab which holds the skeleton code for your first Gadgeteer application. Enter the following lines and hit the “Start Debugger” button in the top of Visual Studio:

You can monitor the deployment process in the footer line of Visual Studio. If the process takes too long, try to reset the spider mainboard by pressing the reset button. If deployment is successful a debug window comes up. Press the button module and see what happens on the display. 

FEZSpider Starter Kit Guide.pdf (8.32 mb)

Tinyclr – Gadgeteer First Project

Hacking at its best with DNS

I received a tweet yesterday from @gravax who was the Epic Hack of the Day, so just check this out which is pretty cool

tracert -h 99 216.81.59.173

You get back

12  * * *

13  episode.iv (206.214.251.1)  155.693 ms  161.675 ms  163.572 ms

14  a.new.hope (206.214.251.6)  180.764 ms  171.357 ms  162.435 ms

15  it.is.a.period.of.civil.war (206.214.251.9)  164.476 ms  167.635 ms  155.173 ms

16  rebel.spaceships (206.214.251.14)  170.381 ms  159.131 ms  163.331 ms

17  striking.from.a.hidden.base (206.214.251.17)  155.447 ms  168.457 ms  161.968 ms

18  have.won.their.first.victory (206.214.251.22)  170.991 ms  163.975 ms  156.780 ms

19  against.the.evil.galactic.empire (206.214.251.25)  157.577 ms  161.265 ms  164.181 ms

20  during.the.battle (206.214.251.30)  174.856 ms  166.470 ms  192.210 ms

21  rebel.spies.managed (206.214.251.33)  158.729 ms  172.967 ms  167.352 ms

22  to.steal.secret.plans (206.214.251.38)  168.628 ms  158.817 ms  186.524 ms

23  to.the.empires.ultimate.weapon (206.214.251.41)  158.969 ms  155.680 ms  173.059 ms

24  the.death.star (206.214.251.46)  160.173 ms  179.227 ms  158.865 ms

25  an.armored.space.station (206.214.251.49)  154.652 ms  165.593 ms  159.269 ms

26  with.enough.power.to (206.214.251.54)  165.290 ms  170.299 ms  170.502 ms

27  destroy.an.entire.planet (206.214.251.57)  159.706 ms  163.257 ms  159.500 ms

28  pursued.by.the.empires (206.214.251.62)  159.571 ms  160.371 ms  163.285 ms

29  sinister.agents (206.214.251.65)  173.527 ms  170.109 ms  160.567 ms

30  princess.leia.races.home (206.214.251.70)  158.904 ms  178.839 ms  182.604 ms

31  aboard.her.starship (206.214.251.73)  168.096 ms  158.851 ms  160.790 ms

32  custodian.of.the.stolen.plans (206.214.251.78)  162.274 ms  171.099 ms  231.641 ms

33  that.can.save.her (206.214.251.81)  168.688 ms  167.075 ms  169.212 ms

34  people.and.restore (206.214.251.86)  160.793 ms  157.587 ms  161.663 ms

35  freedom.to.the.galaxy (206.214.251.89)  178.962 ms  154.471 ms  160.194 ms

36  0——————-0 (206.214.251.94)  159.720 ms  157.607 ms  165.869 ms

37  0——————0 (206.214.251.97)  161.146 ms  174.066 ms  161.739 ms

38  0—————–0 (206.214.251.102)  166.029 ms  164.294 ms  160.558 ms

39  0—————-0 (206.214.251.105)  190.757 ms  166.709 ms  186.424 ms

40  0—————0 (206.214.251.110)  157.325 ms  158.420 ms  181.166 ms

41  0————–0 (206.214.251.113)  160.496 ms  158.207 ms  160.479 ms

42  0————-0 (206.214.251.118)  161.534 ms  168.666 ms  157.581 ms

43  0————0 (206.214.251.121)  157.866 ms  159.754 ms  167.938 ms

44  0———–0 (206.214.251.126)  163.660 ms  179.243 ms  163.206 ms

45  0———-0 (206.214.251.129)  168.475 ms  163.112 ms  158.493 ms

46  0———0 (206.214.251.134)  157.329 ms  158.661 ms  161.612 ms

47  0——–0 (206.214.251.137)  161.833 ms  164.059 ms  166.384 ms

48  0——-0 (206.214.251.142)  169.368 ms  182.151 ms  161.276 ms

49  0——0 (206.214.251.145)  172.806 ms  159.547 ms  169.672 ms

50  0—–0 (206.214.251.150)  165.376 ms  156.775 ms  169.386 ms

51  0—-0 (206.214.251.153)  157.625 ms  163.558 ms  162.880 ms

52  0—0 (206.214.251.158)  179.708 ms  167.693 ms  159.625 ms

53  0–0 (206.214.251.161)  158.662 ms  163.736 ms  170.034 ms

54  0-0 (206.214.251.166)  160.455 ms  162.898 ms  172.839 ms

55  00 (206.214.251.169)  171.892 ms  181.111 ms  157.887 ms

56  * i (206.214.251.174)  165.980 ms  173.152 ms

57  by.ryan.werber (206.214.251.177)  166.216 ms  160.726 ms  165.419 ms

58  when.ccies.get.bored (206.214.251.182)  175.014 ms  180.888 ms  159.231 ms

59  ccie.38168 (206.214.251.185)  164.865 ms  166.514 ms  183.855 ms

60  fin (216.81.59.173)  169.747 ms  165.412 ms  165.241 ms

 
How did Ryan Werber do it?

Star Wars Traceroute

“Bored in the blizzard in Boston; I was inspired by my IRC friend ‘Plazma’ constantly making fun of my reverse dns of scrye.net I came up with this pretty neat hack.
 
It is accomplished using many vrfs on (2) Cisco 1841s. For those less technical, VRFs are essentially private routing tables similar to a VPN. When a packet destined to 216.81.59.173 (AKA obiwan.scrye.net) hits my main gateway, I forward it onto the first VRF on the “ASIDE” router on 206.214.254.1. That router then has a specific route for 216.81.59.173 to 206.214.254.6, which resides on a different VRF on the “BSIDE” router. It then has a similar set up which points it at 206.214.254.9 which lives in another VPN on “ASIDE” router. All packets are returned using a default route pointing at the global routing table. This was by design so the packets TTL expiration did not have to return fully through the VRF Maze. I am a consultant to Epik Networks who let me use the Reverse DNS for an unused /24, and I used PowerDNS to update all of the entries through mysql. This took about 30 minutes to figure out how to do it, and about 90 minutes to implement. All VRFs and DNS were generated by a PHP script. Disclaimer: I am not a very elegant programmer. I can do whatever I need to. I think very linearly and do not plan very well. Below is the code I used to generate the VRFs.”