SIGN UP MEMBER LOGIN:    
ARTICLE

ADO.NET Enhancements in .NET Framework 2.0 for SQL Server Data Provider: Part II

Posted by Muhammad Mosa Articles | ADO.NET in C# January 05, 2006
ADO.NET 2.0 includes enhancements for SQL Server client application developers. Understanding these enhancements will help you design and implement effective client applications on the .NET Framework 2.0 platform
Reader Level:
 

Introduction

In this article we will continue our talking about ADO.Net 2.0 Enhancements. Here we will explore:
  • Bulk copy
  • Notifications (not SQL Server Notification Services but something else as we will see)

Bulk Copy

ADO.NET 2.0 provides the System.Data.SqlClient.SqlBulkCopy class, which can be used to perform efficient bulk copy operations to SQL Server.

But the data source is not limited to SQL Server; any data source can be used, as long as the data can be loaded to a DataTable instance or read with a IDataReader instance. The SqlBulkCopy class supports:
  • single or multiple bulk copy operations.
  • Perform a bulk copy operation within a transaction.

This feature was not supported by previous release of .Net Framework. But bulk copy can be performed in old version using Transact-SQL BULK INSERT statement using the SqlCommand object.

Example:

SqlBulkCopy bcp = new SqlBulkCopy(connection); //Assuing you have DbConnection object named connection.
bcp.DestinationTableName = "BulkCopyDemoTable";
bcp.WriteToServer(reader); //Assuing you have IDataReader object named reader and ready to use.

You can Review the attached demo for demonstration.

Notifications:

SQL Server 2005 can notify client applications when data they have previously retrieved has been updated on the server. This makes it possible for client applications to refresh their local copy of the data when it becomes out-of-date.

ADO.NET provides two ways to take advantage of this notification functionality:

  • Using a high-level SqlDependency class with an OnChanged event
  • Using a lower-level SqlNotifcationRequest class that can be used to access custom notification queues on the server.

SqlDependency requires the .NET Framework version 2.0 and SQL Server 2005.

Most non-ASP.NET application should use SqlDependency object, while ASP.NET appications should use the higher level SqlCacheDependency object which wraps SqDependency and provides a frame work for administrating the notification and cache objects.

Also you should note that SqlDependency was designed to be used in ASP.NET or middle-tier services where there is a relatively small number of servers having dependencies active against the database. It was not designed for use in client applications, where hundreds or thousands of client computers would have SqlDependency objects set up for a single database server.

You can demonstrate SqlDependency, download the attached demo. You may need to change the connection string in the GetConnectionString method.

How to run the demo:

Compile and run both applications. Clicking Get Data on the watcher application should fill the application's grid with data and register a notification request. Examine the data in the grid, noting a product ID for a product whose inventory is zero. Then, using the updater application, enter the product ID and a new quantity of one, and click Update. You should see the watcher application automatically update itself moments after the updater changes the data on the server. Observe that the listbox control displays information about the update. Repeat the process for other quantities and products.


Hope you enjoyed ADO.Net 2.0 Enhancements.

Login to add your contents and source code to this article
share this article :
post comment
 

Asllam-A-Laikum, I m Wahid, complited Computer Science Graduation along with Diploma In Copmuter I would like become a .Net software developer i have alredy done VB 6.0 can u pleas help me how to get start or what to do to become a .Net Software developer AkhatarW@gmail.com Allah-Hafiz

Posted by Wahid Akhtar Oct 18, 2008

Hi,

i am trying to export data from database to excel sheet in .Net Framework 2003.  By using bcp command how to do this in web application using C#.

thanks

Radhakanta

Posted by Radhakanta Nanda Oct 31, 2006
Posted by Muhammad Mosa Aug 07, 2006

mmm sorry, I cannot support you on this, but I would try to change the configuration on the control pannel. it is related to code access security and code group I think but I'm not sure.

Posted by Muhammad Mosa Aug 01, 2006

Sorry sorry sorry for being late, but really my internet connection is limmitted.

ok, there is an article about transactional bulk copy on msdn

ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/WD_ADONET/html/f6f0cbc9-f7bf-4d6e-875f-ad1ba0b4aa62.htm

in your case, try to use TransactionScope class. and please infrom us with your results

Posted by Muhammad Mosa Aug 01, 2006
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor