Manage Data Connections and Databases

5 downloads 553 Views 382KB Size Report
98-363 Web Development Fundamentals. LESSON 2.6. Lesson Overview. What role do databases play in a Web application? In this lesson, you will learn:.
LESSON

2.6

98-363 Web Development Fundamentals

Manage Data Connections and Databases

LESSON

2.6

98-363 Web Development Fundamentals

Lesson Overview What role do databases play in a Web application? In this lesson, you will learn: •

How database connections are managed in a Web application using •

Connection objects



Connection pooling



Transaction objects

LESSON

2.6

98-363 Web Development Fundamentals

Guiding Questions 1.

What does it mean to establish a database connection?

2.

How do you connect to a database?

LESSON

2.6

98-363 Web Development Fundamentals

General Information ƒ

To bring data into your application (and send changes back to the data source), two-way communication must be established.

ƒ

This two-way communication is typically handled by a connection object (for example, a SqlConnection) that is configured with a connection string, the information it needs to connect to the data source.

LESSON

2.6

98-363 Web Development Fundamentals

LESSON

2.6

98-363 Web Development Fundamentals

Creating a Connection Programmatically

LESSON

2.6

98-363 Web Development Fundamentals

Connection Objects ƒ

To access data using your data environment, a connection object must be created. y — Every data environment should include at least one connection object. y — A connection object represents a connection to a remote database that is used as a data source.

LESSON

2.6

98-363 Web Development Fundamentals

Connection Pooling

ƒ

Connection pooling reduces the number of times that new connections need to be opened.

ƒ

The pooler maintains ownership of the physical connection.

ƒ

It manages connections by keeping alive a set of active connections for each given connection configuration.

LESSON

2.6

98-363 Web Development Fundamentals

Connection Pooling (continued) 1.

When a user calls Open on a connection, the pooler looks to see if there is an available connection in the pool.

2.

If a pooled connection is available, it returns it to the caller instead of opening a new connection.

3.

When the application calls Close on the connection, the pooler returns it to the pooled set of active connections instead of actually closing it.

4.

Once the connection is returned to the pool, it is ready to be reused on the next Open call.

ƒ

Only connections with the same configuration can be pooled.

ƒ

ADO.NET keeps several pools concurrently—one for each configuration.

LESSON

2.6

98-363 Web Development Fundamentals

Transaction Objects ƒ

Transactions are operations combined into a logical unit of work. y — Used to control and maintain the consistency and integrity of each action in a transaction despite errors that might occur in the system.

ƒ

Connection and transaction objects are used to begin, commit, and roll back a transaction.

LESSON

2.6

98-363 Web Development Fundamentals

Assignment ƒ

Complete Student Activity Worksheet 2.6.

ƒ

You may work in a group, but you are responsible for your own work.

ƒ

Turn in the completed assignment to your instructor for review.

LESSON

2.6

98-363 Web Development Fundamentals

Lesson Review 1.

Describe methods for creating a database link.

2.

List the benefit of connection pools.

Suggest Documents