Monthly Archives: November 2012

Convert DataTable To List

static List<string[]> ConvertTable(DataTable table)
            return table.Rows.Cast<DataRow>()
                .Select(row => table.Columns.Cast<DataColumn>()
                    .Select(col => Convert.ToString(row[col])).ToArray()).ToList();

Backup Time Information For a Database

select dbinfo.Name , COALESCE(CONVERT(VARCHAR(20),backuplog.backup_finish_date,100 ),”) as BackupTime
FROM sys.sysdatabases dbinfo
LEFT OUTER JOIN msdb.dbo.backupset backuplog ON backuplog.database_name =
where dbinfo.Name=’DataBase Name’

Get Row counts of all tables in a database

SELECT TableName,sysindexes.rows TotalNoRow

FROM sysobjects inner join sysindexes ON =

WHERE type = ‘U’AND sysindexes.IndId < 2

order by sysindexes.rows desc

Restore Database

Restore the logical file from the backup file

FROM DISK = ‘Backup file full path\filename.extension’

Restore the database in same path as in the backup database path and file name

Restore database DBName

to disk=’Backup file full path\filename.extension’

Restore the database with different logical name and path

FROM DISK = ‘Backup file full path\filename.extension’
WITH MOVE ‘YourMDFLogicalName’ TO ‘New Restore file full path\filename.extension’,
MOVE ‘YourLDFLogicalName’ TO ‘New Restore file full path\filename.extension’


Pinal Dave (

Pinal Dave (

Find Current Location of Data and Log File of All the Databas

We restored the database in the client development server for out client development and testing purpose.This time we need to take back and restore it in the client production machine. while am doing this we are unable to restore it. Later we found in client development machine client move the ‘.mdf and .ldf’ to different folder.

SELECT name, physical_name AS current_file_location
FROM sys.master_files

The above SQL script helped us to sort out the issue. We can also use this same script to clean up the junk database folder.


Contract in WCF


A contract is a Standard way of describing way a service can do. In the real world contract is an agreement between two or more parties about doing service or some other things. Similarly in WCF it is the agreement between the Service and Clients, through which message can be passed to and from service endpoints.

The Contract consist of three major types

1)      Service contract

2)      Data contract

3)      Message contract

4)      Polices and binding

Service Contract

Service contract is a class or an interface that specifies the direction and type of message. This contract describes the operation, that can be avail by our world. Example: – To know the current market price based on the company shares. So Service contract is a gate way to the external application to avail the functionality and operations and there must be atleast one operation contract.

Data Contract

Data Contract describe data structures that are used by the service to communicate with clients. It also describes the custome data type which is exposed to the client. The system define datatype are automatically identify by the client, because it is already define in XML schema defination language doument(XSD), but custom created class or datatype cannot be identified by the client.

Example:- Product datatype, by using  DataContract client can understand that Product is the custom datatype for a method that is returning or passing the parameter.

If ‘DataMember’ attributes are not specified for a properties in the class that property can’t be passed to or from web service.

For more:-

Message Contract:-

Message contract allow the service to interact directly with messages. It can be typed or untyped and are useful in interoperability. Message contract provide control over the soap header and bodies. MessageContracts are used to explicitly describe the soap message format.

WCF runtime provide SOAP message formatting for comminication between client and service.If it is not meeting your requirements then we can create our own message format. This can be achieved by using Message Contract attribute.

For more:-

Policy and Binding

Policies and bindings stipulate the conditions required to communicate with a service. For example, the binding must (at a minimum) specify the transport used (for example, HTTP or TCP), and an encoding. Policies include security requirements and other conditions that must be met to communicate with a service.

WCF Archicture


A contract is a Standard way of describing way a service can do. In the real world contract is an agreement between two or more parties about doing service or some other things. Similarly in WCF it is the agreement between the Service and Clients, through which message can be passed to and from service endpoints.

Service Runtime

Service runtime define the behavior of the service. we can achieve through puts, reliability and performance using various WCF Service behavior techniques and handling errors. Most application differs widely in their scalability and performance strategies. WCF service behaviors provide various possible ways to configure key run time behaviors.

Message Layer

This layer defines what kind of formats and data exchange patterns can be used during service communication, this communication are happening through channels. Normally the channels are used to send and receive messages to and from  the service endpoint. There are two parts of Channels

1) Transport Channel

2) Protocol Channel

Activation and Hosting

Once WCF service is ready to make it available to outside world service can be hosted in following types

1)      In IIS

2)      As Windows Activation Service

3)      Self Hosting

4)      Windows service

List.Find() and Predicates

List.Find() is the powerful method used to filter the values from the tones of  list items. It  reduce the line of code and improve the performance while filtering or searching the items.  You can specify a lambda expression as the argument to a List method that receives a Predicate type.


public delegate bool Predicate<in T>(T obj)

Find() method takes the input as Perdicate delegate and return the boolean value.


 public class ProductInfo
public int ProductNumber { get; set; }
public string ProductName { get; set; }
public string ProductDesctiption { get; set; }
public string ProductBatchNumber { get; set; }

 public class ProductList
//Holds list of product Information
List<ProductInfo> objInfo = new List<ProductInfo>();

public void getProducts(string productname)
// Return the matching Value
ProductInfo prodInfo = objInfo.Find(delegate(ProductInfo info) { return info.ProductName == productname; });

//Other way
ProductInfo prodInfoLamdaParameter = objInfo.Find(O => O.ProductName == productname);


Steps For Repeatable Database Integration Activities

SNO Activity  Description
1 Drop database  Drop the database and remove the associated data so that you can create a new database with the same name.
2 Create database Create a new database using Data Definition Language (DDL).
3 Insert system data Insert any initial data (e.g., lookup tables) that your system is expected to contain when delivered.
4 Insert test data Insert test data into multiple testing instances.
5 Migrate database and data Migrate the database schema and data on a periodic basis (if you are creating a system based on an existing database).
6 Set up database instances in multiple environments Establish separate databases to support different versions and environments.
7 Modify column attributes and constraints Modify table column attributes and constraints based on requirements and refactoring.
8 Modify test data Alter test data as needed for multiple environments.
9 Modify stored procedures(along with functions and triggers) Modify and test your stored procedures many times during development (you typically need to do this if you are using stored procedures to provide behavior for your software).
10 Obtain access to different environments Log in to different database environments using an ID, password, and database identifier(s).
11 Back up/restore large data sets Create specialized functions for especially large data sets or entire databases.
%d bloggers like this: