Skip to main content

Posts

Showing posts with the label SQL Server 2005

SQL Bulk Copy with C#.Net

Bulk copying of data from one data source to another data source is a new feature added to ADO.NET 2.0. Bulk copy classes provides the fastest way to transfer set of data from once source to the other. Each ADO.NET data provider provides bulk copy classes. For example, in SQL .NET data provider, the bulk copy operation is handled by SqlBulkCopy class, which is described in Figure 1. As you can see from Figure 1, data from a data source can be copied to one of the four types - DataReader, DataSet, DataTable, or XML. Figure 1. Bulk Copy operation in ADO.NET 2.0 Using bulk copy operation, you can transfer data between two tables on the same SQL Server, between two different SQL Servers, or even two different types of database servers. using System.Data.SqlClient; public static void CopyData(DataTable sourceTable, SqlConnection destConnection, SqlTransaction destTrans, string destTableName) { // new method: SQLBulkCopy: using (SqlBulkCopy s = new SqlBulkC...

LOCK in SQL Server

In SQL Server 2000 (Enterprise Manager) 1. Expand server – management-current Activity-expand Locks/processid and you will be able to see all the locks related information. 2. Expand server – management-current Activity-expand Locks/object you can see locks by object information. In SQL Server 2005 (SSMS, object Explorer) Expand-server-management-double click Activity Monitor. On left side you have three options to choose from, select those options and you can see all the locks related information. Run this stored procedure in the database. 1.  sp_lock To know the running process in the sql server, run this query, 2. select * from sysprocesses (in sql server 2000) 3. select * from sys.sysprocesses (in sql server 2005) 4. sp_who 5. sp_who2 will also give you some good information. To work around the locks, you can run profiler to check which query is creating a lock and if that is necessary. Types of locks on object level, (general idea) Database : Database....