© 2006 itt educational services inc. course name: it390 business database administration unit 9...

72
© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 IT 390 Business Database Administration Unit 9: Database Access Standards

Upload: meghan-miles

Post on 27-Dec-2015

214 views

Category:

Documents


1 download

TRANSCRIPT

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 1

IT 390 Business Database Administration

Unit 9: Database Access Standards

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 2

Objectives

• Identify and classify ODBC, OLE DB, and ASP standards. Introduce database access standards. Explain ODBC, OLE DB and ASP standards.

• Define and apply basic XML and ADO .NET• Explain XML and ADO.NET

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 3

• You need interfaces to enable applications interact and exchange data with databases. • ODBC is a Microsoft specification for creating a database application programming interface (API). The ODBC API is implemented in the form of drivers.

ODBC Introduction

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 4

More about ODBC• The ODBC works as an interface between an

RDBMS and Application Program. This setup works in a three-tier architecture.

• SQL Server 2000 connects to development modules using specific API drivers.

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 5

ODBC Architecture• The components of ODBC architecture

enable the ODBC API to communicate with a database. These components interact with each other to make the database accessible to the user.

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 6

ODBC Visual Overview

API

SQL Server2000

ODBC

ODBC

API

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 7

Functions of ODBC

• Enables applications to communicate with different databases• Facilitates SQL grammar conversion• Enables a single application to use different drivers• Enables applications to interact with different types of databases• Allows the use of enhanced DBMS features • Enables applications to achieve a three-layered architecture

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 8

There are four components of the ODBC architecture that interact with each other to to make the required output available to the user.

• Application: Applications are the programs that call the ODBC API to

communicate with the DBMS.

Components of ODBC

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 9

Driver manager: It is the component that enables communication between an application and a driver by monitoring the transactions between them. A driver manager also performs basic error- handling tasks after a connection is established between the application and the driver.

Components of ODBC

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 10

• Drivers: Drivers are software components that provide functions in the ODBC API. • Data source: A data source stores all the information that is necessary to connect to a database or a DBMS that is stored on the same computer as the client computer or on another computer on the network.

Components of ODBC (cont.)

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 11

ODBC is NOT Microsoft exclusively

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 12

• You use the ODBC Data Source Administrator dialog box to create a DSN. The ODBC Data Source Administrator function is available in Control Panel in the Windows 98 operating system. In Windows 2000, the ODBC Data Source Administrator function is available under Administrative Tools.• To set up an ODBC Data Source:

Double-click the Data Sources icon in the Control Panel.

Setting Up an ODBC Data Source

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 13

Then, on the ODBC Data Source Administrator screen, click the System DSN tab.

Setting Up an ODBC Data Source (cont.)

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 14

In the System DSN tabbed page, click the Add button.

Setting Up an ODBC Data Source (cont.)

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 15

Clicking the Add button displays the Create New Data Source dialog box. In this dialog box, select the SQL Server option, and click the Finish button.

Setting Up an ODBC Data Source (cont.)

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 16

The Create a New Data Source to SQL Server wizard appears. In the first screen of the Create New Data Source Wizard, specify the name for a data source, a description for the data source, and the name of the SQL Server that you want the DSN to connect.

Setting Up an ODBC Data Source (cont.)

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 17

On the next screen, click the With SQL Server authentication using a login ID and password entered by the user option. Then, specify a login ID and password.

Setting Up an ODBC Data Source (cont.)

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 18

After specifying the login ID and password for SQL authentication, select the Change the default database to option, and select the name of the database from the drop-down list. Accept the default selections for other options, and then click the Next button.

Setting Up an ODBC Data Source (cont.)

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 19

On the next screen of the wizard, accept all the default selections, and then click the Finish button.

Setting Up an ODBC Data Source (cont.)

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 20

You can see the data source name included in the list of other data sources on

the System DSN tabbed page.

Setting Up an ODBC Data Source (cont.)

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 21

To connect to the database, you need a front-end application. In addition, you need to call the following functions in the code of the front-end application.

1. Call the SQLAllocEnv or SQLAllocHandle function to get an environment handle.

2. Call the SQLAllocConnect function.

3. Call the SQLConnect function.

4. Call the SQLExecDirect function to execute the SQL statements.

5. Call the SQLFreestmt function to close the connection.

Using an ODBC Data Source

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 22

State whether True or False

• The functions of ODBC are:1) Enables applications to communicate with

only SQL Server 2000.

2) Enables a single application to use different drivers.

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 23

Solution (True or False)

1) False

2) True

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 24

Class Activity

• Choose the correct ODBC components from the following list: Application File system Driver manager Driver Operating system Data source

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 25

Solution

• Application• Driver manager• Driver• Data source

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 26

• OLE DB consists of three components: Data providers Data consumers Service components

OLE DB and its Components

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 27

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 28

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 29

•An ADO object model uses object-oriented programming techniques to communicate with the underlying data source. ADO creates a layer between the applications and the OLE DB provider. • The ADO object model consists of nine objects and four collections.

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 30

The nine objects are: • Connection• Error• Command• Recordset • Record• Parameter • Field • Property• Stream

The ADO Object Model (cont.)

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 31

The four collections are: • Fields • Properties• Parameters• Errors

The ADO Object Model (cont.)

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 32

The generic steps to access databases using ADO are:

1. Set up reference to an ADO Connection object.

2. Define the connection string to be used when opening the connection object. The connection string can be defined in two ways, with a DSN or without a DSN.

3. Open the connection object by using the Open method of the connection object.

4. Use the state property of the connection object to check whether or not a connection is established successfully.

Accessing Databases by Using ADO

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 33

5. Execute SQL statements after the connection is established.

6. Create a recordset object and execute it by using the Open method of the recordset object.

7. Close the recordset object. In addition, close the connection object by calling the Close method of the connection object.

Accessing Databases Using ADO (cont.)

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 34

Active Data Objects (ADO)

• Active Data Objects (ADO) characteristics: A simple object model for OLE DB data

consumers. It can be used from VBScript, JScript,

Visual Basic, Java, C#, C++. It is a single Microsoft data access

standard. Data access objects are the same for all

types of OLE DB data.

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 35

Invoking ADO from Active Server Pages

• In Microsoft’s Active Server Pages (ASP) are Web pages where: Statements are enclosed within the

characters <% . . .%>. ASP statements are processed on the

Web server. Other (HTML) statements are processed

by the client Web browser.

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 36

The ADO Object Model

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 37

Connection Object

• A connection object establishes a connection to a data provider and data source. Connections have an isolation mode.

• Once a connection is created, it can be used to create RecordSet and Command objects.

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 38

RecordSet Objects

RecordSet objects represent cursors: They have both CursorType and LockType

properties. RecordSets can be created with SQL

statements. The Fields collection of a RecordSet can

be processed to individually manipulate fields.

The Errors collection contains one or more error messages that result from an ADO operation.

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 39

Command Object

The command object is used to execute stored parameterized queries or stored procedures: Input data can be sent to the correct ASP

using the HTML FORM tag. Table updates are made using the

RecordSet Update method.

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 40

ADO Constants:Isolation Levels

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 41

ADO Constants:Cursor Levels

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 42

ADO Constants:Lock Types

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 43

Connection Object:ASP Code

<% Dim objConn Set objConn = Server.CreateObject

(“ADODB.connection”) objConn.IsolationLevel =

adXactReadCommitted ‘ use ADOVBS

objConn.Open “ViewRidgeSS”,%><!--#include virtual

=“ADOExamples/ADOVBS.inc --><%

objConn.Open “DSN=ViewRidgeOracle2;UID=DK1;PWD=Sesame”

%>

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 44

RecordSet Object:ASP Code

<%

Dim objRecordSet, varSql

varSQL = “SELECT * FROM ARTIST”

Set objRecordSet = Server.CreateObject(“ADODB.Recordset”)

objRecordSet.CursorTye = adOpenStatic

objRecordSet.LockType = adLockReadOnly

objRecordSet.Open varSQL, objConn

%>

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 45

Fields Collection:ASP Code

<%

Dim varI, varNumCols, objField

varNumCols = objRecordSet.Fields.Count

For varI = 0 to varNumCols - 1

Set objField = objRecordSet.Fields(varI)

‘ objField.Name now has the name of the field

‘ objField.Value now has the value of the field

‘ can do something with them here

Next

>%

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 46

Errors Collection:ASP Code

<%

Dim varI, varErrorCount, objError

On Error Resume Next

varErrorCount = objConn.Errors.Count

If varErrorCount > 0 Then

For varI = 0 to varErrorCount - 1

Set objError = objConn.Errors(varI)

‘ objError.Description contains

‘ a description of the error

Next

End If

>%

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 47

Command Object:ASP Code

<%Dim objCommand, objParam, objRs

‘Create the Command object, connect it to objConn and set its format

Set objCommand = Server.CreateObject(“ADODB.command”)

Set objCommand.ActiveConnection = objConn objCommand.CommandText=“{call FindArtist (?)}” ‘Set up the parameter with the necessary value Set objParam = objCommand.CreateParameter

(“Nationality”, adChar, adParamInput, 25)

objCommand.Parameters.Append objParam objParam.Value = “Spanish” ‘Fire the Stored Proc Set objRs = objCommand.Execute

>%

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 48

ADO Example: Reading a TableArtist.asp

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 49

ADO Example: Reading a TableThe Artist.asp Results

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 50

Class Activity

• Identify the objects in the ADO Model: Connection Error Recordset File Attribute Stream

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 51

Solution

• Connection• Error• Recordset• Stream

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 52

• XML provides a way to define meaningful data structures and eases the process of data exchange. • The advantages of using XML are:

Provides extensible tags to define application- specific data structures

Enables the creation of platform-independent application

Requires only updated document to be uploaded on the Internet instead of the complete document

Displays the same information in different formats on the Web

Accessing Databases by Using XML

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 53

More about XML

• Provides extensible tags for defining application-specific data structures.

• Enables the creation of platform-independent applications.

• Helps reduce the Internet traffic.

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 54

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 55

• XML can be used to present any kind of information in a simple, structured format.

The following are the parts of an XML document: An XML document begins with a

<?xml version =“1.0”?> declaration tag. The second component in an XML document is

called an element. An element is referred to as a root element, when it describes the details about all other elements.

Below the root element, there is a hierarchy of elements.

XML Documents

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 56

All the elements in an XML document contain some data. The data is called content.

• When you create an XML document, you need to follow certain rules. These rules are:

Every start tag should have a closing tag called the end tag.

Tags should not overlap because XML documents follow a hierarchy.

There can be only one root element.

XML Documents (cont.)

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 57

• The architecture of an application has three layers.

The business layer The data layer The user interface

• These layers communicate with each other and exchange data to perform the functions required in an application. • In this entire process of data exchange, XML is used extensively at each stage.

XML for Data Exchange

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 58

SQL Server 2000 and Relational Data in XML

• SQL Server 2000 provides the OPENXML function to insert and update records in the database from an XML document. The OPENXML function reads the data from an XML document and inserts it into the database.

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 59

• SQL server 2000 is an XML-enabled RDBMS that retrieves data from an SQL database and presents it as XML data. To retrieve data, you need to use the FOR XML clause

in the SELECT statement.• To get the XML output for a SQL query, an additional clause is added at the end of the SQL statement:

[FOR XML {RAW|AUTO|EXPLICIT} [, XMLDATA] [, ELEMENTS] [, BINARY base64]] • The FOR XML clause has three distinct options: RAW, AUTO, and EXPLICIT.

Integrating XML with SQL Server 2000

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 60

• SQL Server 2000 provides the OPENXML function to insert and update records in a database from an XML document.• To insert and update records, the OPENXML function uses two system stored procedures:

sp_xml_preparedocument sp_xml_removedocument

Inserting and Updating Relational Data from XML Data

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 61

Class Activity

• Identify the error in the following XML code displaying the employee name:

<?xml version ="1.0"?><EmployeeInfo><Employee ID="001"><EmployeeName>

Joe</EmployeeInfo>

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 62

Solution

• The correct code is:

<?xml version ="1.0"?><EmployeeInfo><Employee ID="001"><EmployeeName>

Joe</EmployeeName> /*the closing tag was missing*/</EmployeeInfo>

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 63

Rules for Creating an XML Document

• Start tag has a closing tag called the end tag.• Tags should not overlap because an XML

document follows a hierarchy.• There can be only one root element.• XML is a case-sensitive language.

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 64

Class Activity

• Identify the various XML formatting options:1) RAW

2) AUTO

3) TEXTSPACE

4) EXPLICIT

5) NAME

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 65

Solution

• RAW• AUTO• EXPLICIT

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 66

• ODBC is a specification for creating a database API. • There are four main components of ODBC:

Application Driver Manager Driver Data Source

• You use the ODBC Data Source Administrator dialog box to create a DSN.

Summary

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 67

• OLE DB and ADO provide a common method to access data from different data sources.• OLE DB has three components:

Data provider Data consumers Service components

Summary

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 68

• The ADO object model consists of the following nine objects: Connection Error Command Recordset Record Parameter Field Property Stream

Summary

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 69

• The steps to access database using ADO are:1. Set up reference to an ADO Connection object.

2. Define the connection string to be used.

3. Open the connection object.

4. Use the state property to check the establishment of the connection.

5. Execute SQL statements.

6. Create a recordset object.

7. Close the recordset object and the connection object.

Summary

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 70

• XML is a standard that can present structured data in the text format on the Web.

• Parts of an XML document: Declaration statement Tags Elements

Summary

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 71

• You use the FOR XML clause in the SELECT statement to integrate XML with SQL Server.• The FOR XML clause has three distinct options:

RAW AUTO EXPLICIT

• SQL Server 2000 provides an OPENXML function to insert and update records in a database from an XML document.

Summary

© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 72

Did you understand the key points from the Lesson?

Do you have any questions??

Summary