Connecting to a Database

Connecting to a data source is the same whether you are connecting on behalf of a Windows application or a Web application. Where Web applications are concerned, how you use the data will differ. Before we get started I do want to take a minute to show you how you can externalize the connection string. This step will allow you to modify a connection string and even change providers—if you program with interfaces—without recompiling your application.

In this section I will demonstrate how to define your database connection string in a Web application's Web.config file. I will also show you how to read those externalized settings, define a generic Database class by using ADO.NET interfaces, and how to write test code.

Get Visual Basic® .NET Power Coding now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.