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(); }
Monthly Archives: November 2012
Convert DataTable To List
Get Row counts of all tables in a database
SELECT sysobjects.name TableName,sysindexes.rows TotalNoRow
FROM sysobjects inner join sysindexes ON sysobjects.id = sysindexes.id
WHERE type = ‘U’AND sysindexes.IndId < 2
order by sysindexes.rows desc
Restore Database
Restore the logical file from the backup file
RESTORE FILELISTONLY
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
RESTORE DATABASE DBName
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’
Reference:
Pinal Dave (http://blog.sqlauthority.com/2007/02/25/sql-server-restore-database-backup-using-sql-script-t-sql/)
Pinal Dave (http://blog.SQLAuthority.com)
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.
WCF Archicture
Contract
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.
Syntax
public delegate bool Predicate<in T>(T obj)
Find() method takes the input as Perdicate delegate and return the boolean value.
Example:
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. |