Configuring Connections and Connecting to Data in Microsoft .NET Framework 3.5
- Before You Begin
- Lesson 1: Creating and Configuring Connection Objects
- Lesson 2: Connecting to Data Using Connection Objects
- Lesson 3: Working with Connection Pools
- Lesson 4: Handling Connection Errors
- Lesson 5: Enumerating the Available SQL Servers on a Network
- Lesson 6: Securing Sensitive Connection String Data
- Chapter Review
- Suggested Practices
- Take a Practice Test
To further practice and reinforce the skills you learned in this chapter, you can perform the following tasks:
Review the chapter summary.
Complete the case scenarios. These scenarios set up real-world situations involving the topics of this chapter and ask you to create a solution.
Complete the additional practices.
Take a practice test.
You create connection objects by setting a valid connection string and enabling communication between your application and a data source. ADO.NET provides four primary connection objects that you can use to connect to almost any standard database.
Connection objects contain several properties, methods, and events that are used for opening and closing connections to a data source, providing information on the current state of the connection and surfacing warnings and informational messages from a data source.
Connection objects enable connection pooling by default. By setting connection–pooling specific connection string keywords, you can control how connections interact with the connection pool.
By wrapping connection calls in a try-catch block, you can process errors returned from SQL Server by using the SqlException and SqlError classes.
By using Windows Authentication and application configuration files, you can protect sensitive information such as passwords in your programs.
Do you know what these key terms mean? You can check your answers by looking up the terms in the glossary at the end of the book.
In the following case scenarios, you will apply what you’ve learned about configuring connections and connecting to data. You can find answers to these questions in the Appendix A section at the end of this book.
Case Scenario 1: Troubleshooting a SQL Connection
You just landed a sweet job at the Alpine Ski House and have been assigned to maintain the application that keeps track of inventory in the ski rental hut. The client application connects to a SQL Server database where the inventory data is stored. You decide to test the application before the season begins, and the first time you run the application and try to check inventory you get an unhandled exception originating from the SQL server.
How can you modify the application so that users can better identify and troubleshoot connection problems?
Case Scenario 2: Securing Sensitive Data
You are working as an application developer at Contoso Pharmaceuticals and have been asked to rewrite their in-house research and development application. The first thing you notice is that they store user name and password information in plain text within the application code base.
Create a list of suggested remedies to present to upper management.