 2004 Tau Yenny, SI - Binus M0194 Web-based Programming Lanjut Session 5.

Slides:



Advertisements
Similar presentations
Database Connections with ASP.Net
Advertisements

Site Collection, Sites and Sub-sites
Data Base. Objective Become familiar with database terminology. Create a project to display data for a single database table. Use a DataGrid control.
The Web Warrior Guide to Web Design Technologies
1 Chapter 12 Working With Access 2000 on the Internet.
Session 6 Server-side programming - ASP. An ASP page is an HTML page interspersed with server-side code. The.ASP extension instead of.HTM denotes server-side.
The ADO Data Control. Universal Data Access Open Database Connectivity (ODBC) –standard for accessing data in databases OLE-DB –allows access to data.
Using Visual Basic 6.0 to Create Web-Based Database Applications
Using Objects and Properties
1 Active Server Pages Active Server Pages (ASPs) are Web pages ASP = server-side scripts + HTML The appearance of an Active Server Page depends on who.
4/8/99 C. Edward Chow Page 1 Active Server Page It is a server-side scripting environment for creating dynamic content. ASP are files with.asp extension,
Web-based Programming Lanjut Pertemuan 5 Matakuliah: M0492 / Web-based Programming Lanjut Tahun: 2007.
4/8/99 C. Edward Chow Page 1 Internet Services Manager Click Start | Programs | Administrative Tools | Internet Services Manager.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
1 Chapter 1 Tour of Access. 1 Chapter Objectives Start and exit Microsoft Access Open and run an Access application Identify the major elements of the.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
ODBC Open DataBase Connectivity a standard database access method developed by Microsoft to access data from any application regardless of which database.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali.
Overview of SQL Server Alka Arora.
FireRMS SQL Audit, Archiving & Purging Presented by Laura Small FireRMS Quality Assurance.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
4-1 INTERNET DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
Chapter 7 PHP Interacts with Ms. Access (Open DataBase Connectivity (ODBC))
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
Installing the SAFARIODBC.EXE For use with Excel May 3, 2002.
© 2006 ITT Educational Services Inc. Course Name: IT390 Business Database Administration Unit 9 Slide 1 IT 390 Business Database Administration Unit 9:
3/8/00asp00 1 Active Server Pages from Microsoft Nancy McCracken Northeast Parallel Architectures Center at Syracuse.
Server Side Programming ASP1 Server Side Programming Database Integration (cont.) Internet Systems Design.
CIM6400 CTNW (04/05) 1 CIM6400 CTNW Lesson 6 – More on Windows 2000.
Using Visual Basic 6.0 to Create Web-Based Database Applications
ADO.NET A2 Teacher Up skilling LECTURE 3. What’s to come today? ADO.NET What is ADO.NET? ADO.NET Objects SqlConnection SqlCommand SqlDataReader DataSet.
McGraw-Hill/Irwin Programming in Visual Basic 6.0 © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Update Edition Chapter 11 Accessing Database.
© Michelle C. Heckman All Rights Reserved. v6.0 Dreamweaver “UltraDev” CS125UDF This course qualifies as a CAS Web Master Related Elective.
Mark Dixon 1 22 – Web applications: Writing data to Databases using ASP.Net.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
Eurotrace Hands-On The Eurotrace File System. 2 The Eurotrace file system Under MS ACCESS EUROTRACE generates several different files when you create.
Needs for Accessing Database To make your web site more dynamic and maintainable, you can display information on your web pages that are retrieved from.
Tutorial 10 by Sam ine1020 Introduction to Internet Engineering 1 Database & Server-side Scripting Tutorial 10.
ADO 2.5 Kamaljit Bath, Program Manager Data Access Group.
Oracle Data Integrator Procedures, Advanced Workflows.
What is database?  Any Method for access info into Application from DataBase?  ODBC is standard for Accessing Data.  Problem with ODBC:  Information.
Database Handling, Sessions, and AJAX. Post Back ASP.NET Functionality The IsPostBack method in ASP.NET is similar to the BlackBerry.refresh method –IsPostBack.
3-Tier Client/Server Internet Example. TIER 1 - User interface and navigation Labeled Tier 1 in the following graphic, this layer comprises the entire.
Tutorial 91 Databases A database is an organized collection of related information stored in a file on a disk A database allows companies to store information.
1 Chapter 20 – Data sources and datasets Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 7 1 Microsoft Office FrontPage 2003 Tutorial 8 – Integrating a Database with a FrontPage.
INSERT BOOK COVER 1Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Getting Started with VBA for Microsoft Office 2010 by.
ASP-12-1 Data Store Access Colorado Technical University IT420 Tim Peterson.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Database Connectivity What is ADO. What is ADO? ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a Microsoft Active-X component.
What’s new in ADO 2.5 Greg Hinkel Program Manager Data Access Group
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
What’s new in ADO 2.5 Greg Hinkel Program Manager Data Access Group
7-1 Active Server and ADO Colorado Technical University IT420 Tim Peterson.
Using databases ActiveX Data Objects (ADO) Connecting to a database Reading data from a database Inserting, updating and deleting records Using databases.
Generating XML Data from a Database Eugenia Fernandez IUPUI.
A S P. Outline  The introduction of ASP  Why we choose ASP  How ASP works  Basic syntax rule of ASP  ASP’S object model  Limitations of ASP  Summary.
COM621: Advanced Interactive Web Development Lecture 10 PHP and MySQL.
ASP.NET Programming with C# and SQL Server First Edition
, MS-Access, QBE, Access/Oracle
VISUAL BASIC INTRODUCTION TO DATA CONNECTIVITY.
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
Chapter 10 ADO.
Database Applications
Presentation transcript:

 2004 Tau Yenny, SI - Binus M0194 Web-based Programming Lanjut Session 5

 2004 Tau Yenny, SI - Binus 2 ActiveX Data Object (ADO) OLE DB and ADO Architecture The ADO Object Model  Connection Object  Command Object  Recordset Object  Record Object  Stream Object  Collections Connecting to Data Stores

 2004 Tau Yenny, SI - Binus 3 ADO Basics ActiveX Data Object (ADO)  The components that allow us to interact with data stores  One way to access data OLE DB  The underlying technology  Interfaces between our programs and the source of the data

 2004 Tau Yenny, SI - Binus 4 OLE DB and ADO Architecture Application VC++VBScriptJava ADO OLEDB Data Store Directory Services RDBMS

 2004 Tau Yenny, SI - Binus 5 OLE DB and ADO Architecture ADO is a COM component and can be used in any COM compliant language, such as Delphi, or scripting language that supports the Active Scripting interface. OLE DB was not designed to be used in all language, so ADO sits on top of OLEDB, and provides an interface for those languages, such as VB and scripting languages, which can’t access OLE DB directly.

 2004 Tau Yenny, SI - Binus 6 OLE DB and ADO Architecture Two main reasons why do we need OLEDB and ADO  First, OLEDB and ADO are designed to give you access to data stores. Note that ‘data store’ does not always be ‘databases’. Although databases are still the most widely used form of data storage, they don’t necessarily contain all of your data.  Second, the rise of Internet applications, and the stateless nature of the Web. The older data access methods aren’t designed to handle data when they are not permanently connected to their store of data. OLEDB and ADO provide disconnected recordsets.

 2004 Tau Yenny, SI - Binus 7 The ADO Object Model Active Connection Connection Errors Parameters Fields CommandRecordsetRecord Stream Collection Active Connection Collection Save() Open() Source SourceRecordset GetChildren() Open() Collection Execute() ActiveCommand Execute()ActiveConnection

 2004 Tau Yenny, SI - Binus 8 The ADO Object Model The Connection Object  The Connection object is what enables us to connect to data stores. Can be constructed or stored commands (for example SQL command or a stored procedure)  We can specify which OLEDB Provider we wish to use, the security details used to connect to the data store, and any other details.  It is not necessary to explicitly create a Connection object to connect to a data store. We can create Command, Recordset and Record objects without a Connection object  ADO implicitly creates a Connection object if we do not create one ourself.

 2004 Tau Yenny, SI - Binus 9 The ADO Object Model The Command Object  The Command object is designed for running commands against a data store.  Connection objects has restrictions on its facilities for handling commands, whereas the Command object was specifically created for dealing with all aspects of commands.  Implicitly created when we run a command from the Connection object.

 2004 Tau Yenny, SI - Binus 10 The ADO Object Model The Recordset Object  Probably is the most commonly used object in ADO, since it is this object that contains the sets of data we extract from our data stores.  The Recordset is the object that holds set of records.  It allows us to change the data (additions, updates and deletions), move around the records, filter the records, and so on.  Contains a Fields collection, where there is a Field object for each field (column) in the recordset.

 2004 Tau Yenny, SI - Binus 11 The ADO Object Model The Record Object  The Record object is used to model a semi- structured recordset in ADO.  Semi-structured recordset is the sets of data where the columns may be different (number of column and data type) for each row.

 2004 Tau Yenny, SI - Binus 12 The ADO Object Model The Stream Object  The Stream object is used to access the contents of a node, such as an message, or a Web page.  Have access to the actual contents of a file, or resource.  The Stream object is designed to handle binary data.  Another use for streams is XML, where we can access a set of data (structured or semi- structured) as a stream of XML.

 2004 Tau Yenny, SI - Binus 13 The ADO Object Model Collections  The Fields Collection Holds Fields object associated with a recordset or a record.  The Parameters Collection Used solely by the Command object, and identifies the parameters in stored commands.  The Errors Collection Contains details of the last ADO or OLE DB Provider error that was generated by a command, and can be only accessed through the Connection object.

 2004 Tau Yenny, SI - Binus 14 The ADO Object Model  The Properties Collection Designed to work with many different data stores, each of which might have different facilities Connection Record Recordset Command Properties Fields

 2004 Tau Yenny, SI - Binus 15 The ADO Object Model We can use the same structure of code to loop through the collections: The syntax in VBScript is : For Each Object In Collection ‘ Do Something with object Next For example, to loop through the Fields collection of a Recordset object : For Each objField In rs.Fields Response.Write objField.Name & “ ” Next If you prefer JScript, then you can use the Enumerator object : for ( objField = new Enumerator(rs.Fields); !objField.atEnd(); objField.moveNext() ) Response.Write (objField.item().Name + ‘ ’);

 2004 Tau Yenny, SI - Binus 16 The ADO Object Model Example of loop through Errors Collection : For Each objError In rs.ActiveConnection.Errors Response.Write objError.Name & “ ” Next Example of the OLE DB Provider for Jet allows us to access the Jet specific security properties: Set conDB = Server.CreateObject(“ADODB.Connection”) conDB.Open “DSN=NWind” conDB.Properties(“Jet OLEDB:Database Password”) = “LetMeIn”

 2004 Tau Yenny, SI - Binus 17 The ADO Object Model ADO Constants  The first method of reference the constants is to include them in your ASP file:  You can either copy the include file into your local directory, or reference it from the installation directory. One disadvantage of this method is that it makes your ASP page larger, since a whole host of constants are included, many of which you won’t typically need.  A better solution is to create a reference to the type library, which makes the constants available without having to include them in the file : <!– METADATA TYPE=“typelib” FILE=“C:\Program Files\Common Files\System \ado\msado15.dll” -->

 2004 Tau Yenny, SI - Binus 18 Connecting to Data Stores Several different ways connect to a data source:  A Connection String. Put the connection details in a string, or directly into the command that opens the data store.  A Data Link File. A file (with a.udl extension) that contains the connection details.  ODBC Data Source, or DSNs. Similar to Data Link files, but are only applicable to ODBC Data Sources. To be used in an ASP page, the Data Source must be a System Data Source.

 2004 Tau Yenny, SI - Binus 19 Connecting to Data Stores Connection Strings The connection string varies upon the Provider. The OLEDB Provider for ODBC is the default – therefore if you leave off the Provider= section, you will automatically use ODBC.  Microsoft Access If using an ODBC connection, without a DSN: Driver = {Microsoft Access Driver (*.mdb)}; DBQ=C:\MyData\thedata.mdb For native OLE DB Provider: Provider=Microsoft.Jet.OLEDB.4.0; Data Source= C:\MyData\thedata.mdb

 2004 Tau Yenny, SI - Binus 20 Connecting to Data Stores  Microsoft SQL Server Using the Provider for ODBC: Driver = {SQL Server}; Server=server_name; Database=database_name; UID=user_name; PWD=user_password For example: Driver = {SQL Server}; Server=MUGGLE; Database=pubs; UID=arine; PWD=letmein For the native OLE DB Provider: Provider =SQLOLEDB; Data Source=server_name; Initial Catalog=database_name; User Id=user_name; Password=user_password For example: Provider =SQLOLEDB; Data Source=MUGGLE; Initial Catalog=pubs; User Id=arine; Password=letmein

 2004 Tau Yenny, SI - Binus 21 Connecting to Data Stores  Microsoft Indexing Service The Indexing Service is only accessible through a native OLE DB Provider. The syntax is: For example, using the Web catalog: Provider =MSIDXS; Data Source=catalog_name Provider =MSIDXS; Data Source=Web

 2004 Tau Yenny, SI - Binus 22 Connecting to Data Stores ODBC Drivers In the example that use the OLE DB for ODBC, the Driver is shown in curly braces. For example: Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\MyData\database_name.mdb The name you should use be the exact name taken from the list of drivers when creating a new data source :

 2004 Tau Yenny, SI - Binus 23 Connecting to Data Stores Data Link Files Create a Data Link file by simply creating a blank text file and renaming the extension to.udl. Once you have the physical data link file, you can open it, either by double-clicking, or right-mouse clicking and selecting Open. You are presented with the following dialog:

 2004 Tau Yenny, SI - Binus 24 Connecting to Data Stores The details of this screen change depending upon the Provider selected. Note that if you select the Allow saving password option, the password you type will be saved in plain text in the UDL file. To change the Provider you can select the Provider tab:

 2004 Tau Yenny, SI - Binus 25 Connecting to Data Stores Alternatively, you can edit the file in a text editor : You can select that the UDL file is really just storing a connection string. To use the data link you simply specify the data link file when opening the connection: conDW.Open “File Name=C:BI\Batches.udl”

 2004 Tau Yenny, SI - Binus 26 Connecting to Data Stores ODBC Data Sources ODBC Data Sources (commonly called Data Source Names, or DSNs) are set up through the Data Sources option on the Administrative Tools menu. Previous versions of Windows had this as an applet in the Control panel. To access a DSN from an ASP page you must make sure that the DSN is set up as a System DSN. This simply involves selecting the System DSN tab on the Data Source Administrator, and then selecting the Add.. button: Once a DSN is set up, you use the DSN= attribute of the connection string. For example: conDW.Open “DSN=pubs“

 2004 Tau Yenny, SI - Binus 27 Using Include Files Using include files to contain connection strings gives a central place to store the connection details for a number of ASP pages. In your ASP pages, add this on the top of the page: This saves you having to type the connection details for each ASP page, and lets you change the connection used for the entire site from one central location. <% strConn = “Provider=SQLOLEDB; Data Source=MUGGLE; “ & _ “Initial Catalog=pubs; User Id=Arine; Password=letmein” Response.Write “” %> Connection.asp

 2004 Tau Yenny, SI - Binus 28 Using Connection State Storing the connection string in an Application variable is quite a common trick too, and equally as effective as using an include file. For example, you could add the following to your global.asa file: Sub Application_OnStart() strConn = “Provider=SQLOLEDB; Data Source=MUGGLE; “ & _ “Initial Catalog=pubs; User Id=Arine; Password=letmein” Set Application (“ConnectionString”) =strConn End Sub In your ASP pages you can then use the following : Set conDW = Server.CreateObject(“ADODB.Connection”) conDW.Open Application(“ConnectionString”)

 2004 Tau Yenny, SI - Binus 29 Connection Syntax If using an explicit Connection object, use the Open method: connection.Open [ConnectionString], [UserID], [Password], [Options] The arguments are as follows: ArgumentDescription ConnectionStringThe string containing the connection details. This can be the name of an ODBC DSN, the name of a Data Link file, or just the actual connection details. UserIDThe name of the user to use during the connection. This overrides any user name supplied in the connection string. PasswordThe password for the user. This overrides and password details supplied in the connection string. OptionsThis can be adAsyncConnect to specify that the connection be established asynchronously. Omitting this parameter ensures a synchronous connection. Connecting asynchronously is no use in an ASP environment, since scripting languages can’t receive events from ADO.

 2004 Tau Yenny, SI - Binus 30 Connection Examples To open a connection use the Open method of the Connection object. For example, assume that strConn contains a valid connection string: Alternatively, use the ConnectionString property: There is no difference between the two, and if you use the former method, then the ConnectionString property is filled in for you. Set conPubs = Server.CreateObject(“ADODB.Connection”) conPubs.Open strConn ‘ Some processing conPubs.Close Set conPubs = Server.CreateObject(“ADODB.Connection”) conPubs.ConnectionString = strConn conPubs.Open ‘ Some processing conPubs.Close