Free mag vol1 | Page 869

CHAPTER 21  ADO.NET PART I: THE CONNECTED LAYER // Open, use, and close connection... } Console.ReadLine();  Note To use the ConfigurationManager type, be sure to set a reference to the System.Configuration.dll assembly and import the System.Configuration namespace. At this point, you have authored some ADO.NET code that allows you to specify the underlying connection dynamically. One obvious problem, however, is that this abstraction is only used within the MyConnectionFactory.exe application. If you were to rework this example within a .NET code library (e.g., MyConnectionFactory.dll), you would be able to build any number of clients that could obtain various connection objects using layers of abstraction. However, obtaining a connection object is only one aspect of working with ADO.NET. To make a worthwhile data provider factory library, you would also have to account for command objects, data readers, data adapters, transaction objects, and other data-centric types. Building such a code library would not necessarily be difficult, but it would require a considerable amount of code and time. Since the release of .NET 2.0, the kind folks in Redmond have built this exact functionality directly into the .NET base class libraries. You will examine this formal API in just a moment; however, first you need to create a custom database to use throughout this chapter (and for many chapters to come).  Source Code You can find the MyConnectionFactory project under the Chapter 21 subdirectory. Creating the AutoLot Database As you work through this chapter, you will execute queries against a simple SQL Server test database named AutoLot. In keeping with the automotive theme used throughout this book, this database will contain three interrelated tables (Inventory, Orders, and Customers) that contain various bits of data representing order information for a fictional automobile sales company. The assumption in this book is that you have a copy of Microsoft SQL Server (7.0 or higher) or a copy of Microsoft SQL Server Express Edition. If you do not have either of these, please go here to download a copy: www.microsoft.com/sqlserver/en/us/editions/2012-editions/express.aspx This lightweight database server is perfect for your needs in this book: it is free, it provides a GUI front end (the SQL Server Management Tool) to create and administer your databases, and it integrates with Visual Studio/Visual C# Express Edition. To illustrate the last point, the remainder of this section will walk you through the construction of the AutoLot database using Visual Studio. If you use Visual C# Express, you can perform operations similar to what is explained here by using the Database Explorer window (you can load this from the View  Other Windows menu option). 815