Tuesday, December 20, 2011


Get the TFS build (MSBuild) information from C#.Net code

Suppose you have daily build going on which is created using TFS 2010 and if you want to get the information like how many build created, how many fails etc.

You can write small C#.net program to get all this information, you requires to pass TFS url and Team project name, see the following code for details

Namespace
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.Build.Common;
using Microsoft.TeamFoundation.VersionControl.Client;

Source Code
private void button1_Click(object sender, EventArgs e)
{ 
 //prepare list view to set column header
 lstResult.View = View.Details;
 // add columns in ListView
 lstResult.Columns.Add("Build Status", 70, HorizontalAlignment.Left);
 lstResult.Columns.Add("BuildDefinition", 150, HorizontalAlignment.Left);
 lstResult.Columns.Add("LabelName", 120, HorizontalAlignment.Left);
 lstResult.Columns.Add("Reason", 100, HorizontalAlignment.Left);
 lstResult.Columns.Add("StartTime", 100, HorizontalAlignment.Left);
 lstResult.Columns.Add("FinishTime", 100, HorizontalAlignment.Left);
 lstResult.Columns.Add("RequestedBy", 100, HorizontalAlignment.Left);
 lstResult.Columns.Add("Drop Location", 100, HorizontalAlignment.Left);
 // add Items in ListView
 lstResult.Items.Add("Loading.....");

TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("VSTS URL"));

var vcs = tfs.GetService<VersionControlServer>();

var proj = vcs.GetTeamProject("Team Project Name");

IBuildServer buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer));

var builds = buildServer.QueryBuilds(proj.Name);
           
lstResult.Items.Clear();

//Bind all column in listview
foreach (IBuildDetail build in builds)
{
string [] columns = new string [8];
       ListViewItem Item;
       columns[0] = build.Status.ToString();
       columns[1] = build.BuildDefinition.Name;
       columns[2] = build.LabelName;
       columns[3] = build.Reason.ToString();
       columns[4] = build.StartTime.ToString();
       columns[5] = build.FinishTime.ToString();                   
       columns[6] = build.RequestedBy;
       columns[7] = build.DropLocation;
                   
       Item = new ListViewItem(columns);
       lstResult.Items.Add(Item); 
    }  
}

Note: I am unable to get the information, if build fails then why fails complete details (Log) in one of the columns in above list view column, if someone able to do that please let me know, Thanks
  

Saturday, November 26, 2011

Differences between Oracle to SQL Server

When you thing to migrate database from oracle to SQL Server or some other database then most important is to compare with other databases with Oracle and decide whether will go for migration or Upgrade. If you go for Oracle to some other database then It will be complete migration whereas Oracle to Oracle higher version then it will consider as database upgrade.

Following table will describe the differences between SQL Server 2008 R2 and Oracle 11g R2.  

     Key Features
SQL Server 2008 R2
Oracle 11g R2
ü  Support for 256 logical processors
ü  Improvements in multi-server management
ü  Master Data Services
ü  Geospatial visualizations in Reporting Services
ü  Self-service BI with Project Gemini

ü  Automatic Memory Tuning
ü  SQL Performance Analyzer (Fully Automatic SQL Tuning) 
ü  Automated Storage Load balancing
ü  Automatic Diagnostic Repository

Database Comparison

SQL Server 2008 R2
Oracle 11g R2
Database Change
Migration
Upgrade
Migration Tools
SSMA (SQL Server Migration Assistant 2008) from Microsoft.
Database Upgrade Assistant (DBUA)
License cost
Extra License cost
Existing Oracle License can be used
Offline Version
SQL Server Personal Edition
Express - Free limit 1 processor, 10 gig db Note that SQL Server 2008 had a 4gig limit
Oracle Database Express Edition 11g
Express (XE) Free 1 processor, 4 gb db, 1 gig ram
OS Supports
Windows XP, Windows Vista, Windows 2003, Windows 2008 (runs in both 32-bit and 64-bit)
Linux, Unix, Windows 2003, Windows 2008 (runs in both 32-bit and 64-bit), (R2 does not yet work on Mac apparently,10G seems to be the last to work on Mac. )
.NET connectivity
using  ADO.NET  Data provider
(System.Data.SqlClient.SqlException)
Oracle Data Provider for .NET (ODP.NET)
(Oracle.DataAccess.Client)
Existing Interfaces Compatibility
Need to customize the interfaces to work with SQL server 2008
No customization requires for other interfaces
Testing After Migration
More Testing efforts
Ø  Performance Testing
Ø  Rollback/Failover Testing
Ø  Volume and Load Stress Testing
Ø  Validation of database objects
Ø  Integration Testing

Less Testing efforts
Ø  Upgrade Testing
Ø  Minimal Testing/Smoke testing

               
Different Versions and Licensing Cost
Express - free limit 1 processor, 10 gig db Note that SQL Server 2008 had a 4gig limit
Standard - starts at ~$7500 per processor limit 4 processors
Enterprise ~$29,000 per processor
Datacenter - ~$58,000 per processor
Parallel Data Warehouse - ~$58,000 per processor
Express (XE) Free 1 processor, 4 gb db, 1 gig ram
Personal Edition ~$450 per user
Standard Edition One ~$5800 per proc
Standard Edition ~$17,500 per proc
Enterprise Edition ~47,500 per proc + option to buy Oracle Spatial add on for another $17,500 per proc
Free Object/Relational Mapping
NHibernate.Spatial: Spatial extensions for NHibernate, allows you to connect NHibernate to a spatially enabled database and manipulate geometries in HQL or in .NET code using NetTopologySuite, providing you with a fully integrated GIS programming experience.
Hibernate Spatial: Generic extension to Hibernate for handling geographic data. Hibernate Spatial is open source and licensed, like Hibernate, under the LGPL license.
Hibernate Spatial allows you to deal with geographic data in a standardized way. It abstracts away from the specific way your database supports geographic data, and provides a standardized, cross-database interface to geographic data storage and query functions.
Reports
Microsoft Sql Reporting Services
Crystal Report .NET
Crystal Report .NET
Dialect of SQL supported
T-SQL
PL/SQL
Development Tools available
SQL Server Management Studio,
Visual Studio 2010 etc.
Toad, Oracle Console,
Oracle SQL Developer 3.1 etc.




Friday, October 21, 2011

How to create SSIS package using SQL Server Business Development Studio 2008 R2

How to create SSIS package using SQL Server Business Development Studio 2008 R2

I found very useful site below to start and understand SSIS package creation and deployment.

Creating a Package
Scheduling a SSIS Package with SQL Server Agent
http://www.sql-server-performance.com/2008/scheduling-a-ssis-package-in-sql-server-agent/2/

Thursday, September 01, 2011

Sort in descending order with multiple columns using LINQ to Object, C#.NET 4.0


Sort in descending order with multiple columns using LINQ to Object, C#.NET 4.0

Below the example of sorting list object in descending order with multiple columns.

NameSpace

using System.Linq;

C#.NET

List<Country> countryList = new List<Country>();

Load countryList Object from source

Descending Order

countryList = countryList.OrderByDescending(c => c.Column1).ThenByDescending(c => c.Column2).ToList<Country>();

Ascending Order (Default)

countryList = countryList.OrderBy(c => c.Column1).ThenBy(c => c.Column2).ToList<Country>();

Note:  For more than 2 columns, you can again use “.ThenBy” clause for column3, column4 etc.

SQL Server Database DML Operation (Insert/ Update /Delete) with Microsoft Entity Framework 4.0


SQL Server Database DML Operation (Insert/ Update /Delete) with Microsoft Entity Framework 4.0

When you use Entity Framework for database DML (Insert, Update and Delete) operation then it is very common to get errors like
  • “Foreign Key References”
  • “The DELETE statement conflicted with the REFERENCE constraint”

Here you need to be very careful when sending object into entity methods
Normally we use following methods to do database operation using entity framework 
  • AddObject
  • ApplyChanges
  • Attach
  • DeleteObject

Suppose you have some objects which is having child objects like

Object Structure

-Country
----Airports
------Name
--------Address
----FerriesTerminal
------Name
--------Address 

Namespace (.Net Entity Framework 4.0)

using System.Collections.Generic;
using System.Linq;
using System.Transactions;
using System.Data.Entity; 
      
Now if you are doing some operation on one particular object like delete “Country”, you have to nullify all the under laying objects before sending it for delete operation.

Like: Let’s say you are working with “Country” object only, not dealing with other under laying object ex: “Airport”, “Name” etc.

List<Country> country = new List<Country>();

Load country object from source or from sample data.

Important

Before doing any database DML operation (Delete/Update/Insert) makes sure all under laying object is NULL

foreach (Country con in country)
{
   con.AirPorts =  null;
   con.FerriesTerminal  = null; 
}

I solved lots of error applying above for loop in my input objects.

Delete

using (var ctx = DBContext)
{
  using (var tc = new TransactionScope())
   {
      foreach (Country con in country)
      {
        //Mark con Object for Delete
        con.MarkAsDeleted();
        ctx.Country.Attach(con);
        //Delete data from Country Table
        ctx.Country.DeleteObject(con);
      }

    ctx.SaveChanges();
    tc.Complete();
  }
} 
Another Way of Delete

using (var ctx = DBContext)
{
    using (var tc = new TransactionScope())
    {
       foreach (Country con in country)
       {
          //Mark con Object for Delete
   con.MarkAsDeleted();
        //Delete data from Country Table
          ctx.Country.ApplyChanges(con);
       }

    ctx.SaveChanges();
    tc.Complete();
  }
} 
Update

using (var ctx = DBContext)
{
    using (var tc = new TransactionScope())
    {
       foreach (Country con in country)
       {
         //Mark Object as Modified
  con.MarkAsModified()
         //Update data into Country Table
         ctx.Country.ApplyChanges(con);
       }

    ctx.SaveChanges();
    tc.Complete();
  }
} 
Insert
           
using (var ctx = DBContext)
{
  using (var tc = new TransactionScope())
   {
      foreach (Country con in country)
      {
        //Insert data into Country Table
        ctx.Country.AddObject(con);
      }

    ctx.SaveChanges();
    tc.Complete();
  }
}

Note: I observed, sometime its take lots of time to figure out what the problem going on and what’s the solution, if it’s really taking so much time to solve the issues with entity framework then I would suggest to use STORED PROCEDURE for complex DML operations.