730 likes | 887 Views
Unit 9: Database Access Standards. IT 390 Business Database Administration. 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.
E N D
Unit 9: Database Access Standards IT 390 Business Database Administration
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
ODBC Introduction • 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.
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. More about ODBC
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. ODBC Architecture
API ODBC SQL Server 2000 ODBC API ODBC Visual Overview
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 Functions of ODBC
Components of ODBC 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 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 (cont.) • 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.
Setting Up an ODBC Data Source • 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 (cont.) Then, on the ODBC Data Source Administrator screen, click the System DSN tab.
Setting Up an ODBC Data Source (cont.) In the System DSN tabbed page, click the Add button.
Setting Up an ODBC Data Source (cont.) 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.) 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.) 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.) 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.) 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.) You can see the data source name included in the list of other data sources on the System DSN tabbed page.
Using an ODBC Data Source 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. • Call the SQLAllocEnv or SQLAllocHandle function to get an environment handle. • Call the SQLAllocConnect function. • Call the SQLConnect function. • Call the SQLExecDirect function to execute the SQL statements. • Call the SQLFreestmt function to close the connection.
The functions of ODBC are: 1) Enables applications to communicate with only SQL Server 2000. 2) Enables a single application to use different drivers. State whether True or False
1) False 2) True Solution (True or False)
Choose the correct ODBC components from the following list: Application File system Driver manager Driver Operating system Data source Class Activity
Application Driver manager Driver Data source Solution
OLE DB and its Components • OLE DB consists of three components: • Data providers • Data consumers • Service components
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.
The ADO Object Model (cont.) The nine objects are: • Connection • Error • Command • Recordset • Record • Parameter • Field • Property • Stream
The ADO Object Model (cont.) The four collections are: • Fields • Properties • Parameters • Errors
Accessing Databases by Using ADO The generic steps to access databases using ADO are: • Set up reference to an ADO Connection object. • 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. • Open the connection object by using the Open method of the connection object. • Use the state property of the connection object to check whether or not a connection is established successfully.
Accessing Databases Using ADO (cont.) • Execute SQL statements after the connection is established. • Create a recordset object and execute it by using the Open method of the recordset object. • Close the recordset object. In addition, close the connection object by calling the Close method of the connection object.
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. Active Data Objects (ADO)
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. Invoking ADO from Active Server Pages
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. Connection Object
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. RecordSet Objects
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. Command Object
<% 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” %> Connection 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 %> RecordSet Object: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 >% Fields 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 >% Errors Collection: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 >% Command Object:ASP Code
Identify the objects in the ADO Model: Connection Error Recordset File Attribute Stream Class Activity