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.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access