Creating a Custom ADO.NET Data Provider

Creating a custom ADO.NET data provider is definitely a long process that needs to be designed thoroughly before proceeding. However, the use of standard interfaces and base classes makes the task slightly easier.

There aren't all that many reasons to create your own custom ADO.NET data provider. If you find that you need to access data that you want to expose through the connection/command/reader pattern, there is an extremely good chance that the underlying data can be accessed using either ODBC or OLE DB. Remember that you can use OLE DB to access data sources like Excel spreadsheets and even text files. However, if the data is proprietary, or can't be accessed through ODBC, OLE DB, Oracle, or SQL Server, you might find yourself in a situation where you want to create a data provider to expose your data to the .NET Framework in a relational manner.

To do this, you'll need to create a class library that contains implementations of several interfaces. To create a minimal data provider, you will need to create the following:

  • A connection To expose data via a data provider, the data provider must follow a connection model. A connection represents some live connection with a source of data, whether that connection is a reserved file handle, a network socket, or some other representation of a database connection.

  • A data reader You will need to create a class that provides a read-only, forward-only traversal over the underlying data contained within your provider

  • A data adapter Data adapters are responsible for executing commands in order to exchange data between the underlying data source and DataSets.

  • A command The command is a unit of instruction sent to the underlying data source. Traditional commands are typically in the form of stored procedures or SQL statements, but your data source can take any type of parameterized command that you feel appropriate. Commands can return both scalar data and data readers.

In the past, some example data providers have been created for ADO.NET that provide exposure for Microsoft Message Queues (MSMQ), Active Directory (AD), and even runtime type information provided by a Reflection data provider.

It's beyond the scope of this chapter to walk you through the implementation of a custom provider. In addition to providing implementations of a command, a data reader, a connection, and a data adapter, your data provider would also have to take into account things like transactional support and whether or not you want your provider to register itself with the list of data provider factories.

Microsoft Visual C# 2005 Unleashed
Microsoft Visual C# 2005 Unleashed
ISBN: 0672327767
EAN: 2147483647
Year: 2004
Pages: 298 © 2008-2017.
If you may any questions please contact us: