0% found this document useful (0 votes)
57 views

Unit 6 - Question Bank

ActiveX Data Objects (ADO) provides a programmatic interface for accessing data sources from client applications. It contains four collections of twelve objects for connecting to data sources, sending queries or stored procedures, retrieving recordsets of records, and handling errors. The two main standards for connecting to databases are ODBC, which handles SQL and other languages, and OLE DB, which provides access to different file formats including SQL. To establish a connection, an application first creates a connection object using a connection string, opens the connection, then executes queries on the connection to retrieve recordsets which can be iterated through.

Uploaded by

Snehal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

Unit 6 - Question Bank

ActiveX Data Objects (ADO) provides a programmatic interface for accessing data sources from client applications. It contains four collections of twelve objects for connecting to data sources, sending queries or stored procedures, retrieving recordsets of records, and handling errors. The two main standards for connecting to databases are ODBC, which handles SQL and other languages, and OLE DB, which provides access to different file formats including SQL. To establish a connection, an application first creates a connection object using a connection string, opens the connection, then executes queries on the connection to retrieve recordsets which can be iterated through.

Uploaded by

Snehal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Unit 6 Questions

1) What is ADO? Explain its Objects


ActiveX Data Objects (ADO) is a collection of software components providing a
programmatic interface to access the data sources from client applications. ADO acts as a
layer to access any data store in a generic way from the application code. It eliminates the
need to possess the knowledge of database implementation and reduces the complexity of
dealing with the low level code needed to handle the data.

Released in 1996, activeX data object (ADO) originated from the concept of RDO
(remote data object) and DAO (data access object). One of the constituents of MDAC
(Microsoft data access components), ADO and other MDAC constituents provides a
framework of components used by client applications to access SQL, semi-structured and
legacy data stores.

The object model of ADO contains four collections of twelve objects. The different
collections are fields, properties, parameters and errors. Each collection consists of the
following twelve objects:
1. Connection - for connecting to data source through OLE DB
2. Command - for sending an instruction (SQL query or stored procedure) to data
provider
3. Recordset - a group of records representing the data
4. Immediate - a recordset locked in optimistic or pessimistic way
5. Batch - for committing or doing a rollback database transaction
6. Transaction - the database transaction
7. Record - a set of fields
8. Stream - for reading and writing a stream of bytes
9. Parameter - for changing the functionality
10. Field - a column in the database
11. Property - the ability of OLEDB provider
12. Error - the error faced by the OLEDB provider during its execution
2) Discuss ODBC and OLEDB
ODBC
It is short for Open Database Connecting. It is an interface standard, designed for
communication between different apps and operating systems (OS).ODBC was created by
SQL Access Group and first released in September 1992. ODBC was originally created for
Structured Query Language (SQL). It has since expanded to handle more programming
languages.

The four different components of ODBC are:


Application: Processes and calls the ODBC functions and submits the SQL statements;
Driver manager: Loads drivers for each application;
Driver: Handles ODBC function calls, and then submits each SQL request to a data source;
and
Data source: The data being accessed and its database management system (DBMS) OS.

OLEDB
OLE BD is short for Object Linking and Embedding Database. This is a group of
API’s designed to provide access to app data in different file formats. This included SQL
capability (like ODBC), and many other languages.

The objects in OLE DB consist mainly of a data source object, a session object, a
command object, and a rowset object. An application using OLE DB would use this request
sequence:

1 Initialize OLE.
2 Connect to a data source.
3 Issue a command.
4 Process the results.
5 Release the data source object and uninitialize OLE.

3) Write in brief: To establish a connection with database.


Before a database can be accessed from a web page, a database connection has to be
established.
Create a DSN-less Database Connection
The easiest way to connect to a database is to use a DSN-less connection. At first we
must create an instance of the connection object and feed it the location of the database we
wish to connect to and the driver that we intend to use. For these purposes we will use
a connection string. You can choose an ODBC or an OLEDB connection string. We will use
OLEDB for our example as it's faster and more stable. Next, we should open the connection
to the database:

<%
'declare the variable that will hold new connection object
Dim Connection
'create an ADO connection object
Set Connection=Server.CreateObject("ADODB.Connection")

'declare the variable that will hold the connection string


Dim ConnectionString
'define connection string, specify database driver and location of the database
ConnectionString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= c:\inetpub\wwwroot\db\examples.mdb"

'open the connection to the database


Connection.Open ConnectionString
%>

Now we have an active connection to our database. Let's retrieve all the records
from the 'Cars' table. For that we have to create an instance of the recordset object and
feed it an SQL statement.
<%
'declare the variable that will hold our new object
Dim Recordset
'create an ADO recordset object
Set Recordset=Server.CreateObject("ADODB.Recordset")

'declare the variable that will hold the SQL statement


Dim SQL
SQL="SELECT * FROM CARS"

'Open the recordset object executing the SQL statement and return records
Recordset.Open SQL, Connection
%>

We have returned a recordset based on our SQL statement so let's now print out
them in the browser.
<%
'first of all determine whether there are any records
If Recordset.EOF Then
Response.Write("No records returned.")
Else
'if there are records then loop through the fields
Do While NOT Recordset.Eof
Response.write Recordset("Name")
Response.write Recordset("Year")
Response.write Recordset("Price")
Response.write "<br>"
Recordset.MoveNext
Loop
End If
%>
Finally, need to close the objects and free up resources on the server.
<%
Recordset.Close
Set Recordset=Nothing
Connection.Close
Set Connection=Nothing
%>

4) Explain any two LockType properties of RecordSet Object.


ADO LockType Property:- The LockType property sets or returns
a LockTypeEnum value that specifies the type of locking when editing a record in a
Recordset. Default is adLockReadOnly. This property is read/write on a closed Recordset and
read-only on an open Recordset.
Syntax
objRecordset.LockType

LockTypeEnum Values
Constant Value Description
adLockUnspecified -1 Unspecified type of lock. Clones inherits lock
type from the original Recordset.
adLockReadOnly 1 Read-only records
adLockPessimistic 2 Pessimistic locking, record by record. The
provider lock records immediately after editing
adLockOptimistic 3 Optimistic locking, record by record. The
provider lock records only when calling update
adLockBatchOptimistic 4 Optimistic batch updates. Required for batch
update mode

Example
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("northwind.mdb"))
set rs=Server.CreateObject("ADODB.recordset")
sql="SELECT * FROM Customers"

rs.CursorLocation=adUseClient
rs.CursorType=adOpenStatic
rs.LockType=adLockBatchOptimistic

rs.Open sql,conn

rs.Close
conn.Close
%>

5) Explain any two CursorType properties of RecordSet Object.


CursorType Property:- The CursorType property sets or returns the cursor type to use
when opening a Recordset object. This property can take a CursorTypeEnum value. Default
is adOpenForwardOnly.

Syntax
objRecordset.CursorType

CursorTypeEnum Values
Constant Value Description
adOpenUnspecified -1 Does not specify the type of cursor.
adOpenForwardOnly 0 Default. Uses a forward-only cursor. Identical to a
static cursor, except that you can only scroll forward
through records. This improves performance when
you need to make only one pass through a Recordset.
adOpenKeyset 1 Uses a keyset cursor. Like a dynamic cursor, except
that you can't see records that other users add,
although records that other users delete are
inaccessible from your Recordset. Data changes by
other users are still visible.
adOpenDynamic 2 Uses a dynamic cursor. Additions, changes, and
deletions by other users are visible, and all types of
movement through the Recordset are allowed, except
for bookmarks, if the provider doesn't support them.

adOpenStatic 3 Uses a static cursor. A static copy of a set of records


that you can use to find data or generate reports.
Additions, changes, or deletions by other users are not
visible.

6) List out Locktype property of Recordset object.


LockTypeEnum Values
Constant Value Description
adLockUnspecified -1 Unspecified type of lock. Clones inherits lock
type from the original Recordset.
adLockReadOnly 1 Read-only records
adLockPessimistic 2 Pessimistic locking, record by record. The
provider lock records immediately after editing
adLockOptimistic 3 Optimistic locking, record by record. The
provider lock records only when calling update
adLockBatchOptimistic 4 Optimistic batch updates. Required for batch
update mode

7) List out Cursortype property of Recordset object.


CursorTypeEnum Values
Constant Value Description
adOpenUnspecified -1 Does not specify the type of cursor.
adOpenForwardOnly 0 Default. Uses a forward-only cursor. Identical to a
static cursor, except that you can only scroll forward
through records. This improves performance when
you need to make only one pass through a Recordset.
adOpenKeyset 1 Uses a keyset cursor. Like a dynamic cursor, except
that you can't see records that other users add,
although records that other users delete are
inaccessible from your Recordset. Data changes by
other users are still visible.
adOpenDynamic 2 Uses a dynamic cursor. Additions, changes, and
deletions by other users are visible, and all types of
movement through the Recordset are allowed, except
for bookmarks, if the provider doesn't support them.
adOpenStatic 3 Uses a static cursor. A static copy of a set of records
that you can use to find data or generate reports.
Additions, changes, or deletions by other users are not
visible.

8) Write a script to add new student record in a table.


9) Explain Command Object of ADO
The ADO Command object is used to execute a single query against a database. The query
can perform actions like creating, adding, retrieving, deleting or updating records.
If the query is used to retrieve data, the data will be returned as a RecordSet object. This
means that the retrieved data can be manipulated by properties, collections, methods, and
events of the Recordset object.
ProgID
set objCommand=Server.CreateObject("ADODB.command")
Properties
Property Description
ActiveConnection Sets or returns a definition for a connection if the connection is
closed, or the current Connection object if the connection is open
CommandText Sets or returns a provider command
CommandTimeout Sets or returns the number of seconds to wait while attempting to
execute a command
CommandType Sets or returns the type of a Command object
Name Sets or returns the name of a Command object
Prepared Sets or returns a Boolean value that, if set to True, indicates that
the command should save a prepared version of the query before
the first execution
State Returns a value that describes if the Command object is open,
closed, connecting, executing or retrieving data
Methods
Method Description
Cancel Cancels an execution of a method
CreateParameter Creates a new Parameter object
Execute Executes the query, SQL statement or procedure in the CommandText
property
Collections
Collection Description
Parameters Contains all the Parameter objects of a Command Object
Properties Contains all the Property objects of a Command Object
Example
<%
Set objcommand.CommandText="SELECT * FROM Customers"
objCommand.Execute
%>
or
<%
Set objcommand.CommandText="Customers"
objCommand.Execute(,,adCmdTableDirect)
%>

10) Explain Connection Object of ADO.


The ADO Connection Object is used to create an open connection to a data source. Through
this connection, you can access and manipulate a database.
If you want to access a database multiple times, you should establish a connection using the
Connection object. You can also make a connection to a database by passing a connection
string via a Command or Recordset object.
ProgID
set objConnection=Server.CreateObject("ADODB.connection")

Properties
Property Description
CommandTimeout Sets or returns the number of seconds to wait while attempting to
execute a command
ConnectionString Sets or returns the details used to create a connection to a data source
ConnectionTimeout Sets or returns the number of seconds to wait for a connection to open
CursorLocation Sets or returns the location of the cursor service
DefaultDatabase Sets or returns the default database name
Mode Sets or returns the provider access permission
Provider Sets or returns the provider name
State Returns a value describing if the connection is open or closed
Version Returns the ADO version number

Methods
Method Description
BeginTrans Begins a new transaction
Cancel Cancels an execution
Close Closes a connection
CommitTrans Saves any changes and ends the current transaction
Execute Executes a query, statement, procedure or provider specific text
Open Opens a connection
RollbackTrans Cancels any changes in the current transaction and ends the transaction

Events
Event Description
BeginTransComplete Triggered after the BeginTrans operation
CommitTransComplete Triggered after the CommitTrans operation
ConnectComplete Triggered after a connection starts
Disconnect Triggered after a connection ends
ExecuteComplete Triggered after a command has finished executing
InfoMessage Triggered if a warning occurs during a ConnectionEvent operation
RollbackTransComplete Triggered after the RollbackTrans operation
WillConnect Triggered before a connection starts
WillExecute Triggered before a command is executed

Collection
Collection Description
Errors Contains all the Error objects of the Connection object
Properties Contains all the Property objects of the Connection object

Example
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0"
conn.open server.mappath("database.mdb")

conn.close
%>
11) List out property of Recordset object.(Remember Any Six)
Property Description
AbsolutePage Sets or returns a value that specifies the page number in the Recordset object
AbsolutePosition Sets or returns a value that specifies the ordinal position of the current record in
the Recordset object
ActiveCommand Returns the Command object associated with the Recordset
ActiveConnection Sets or returns a definition for a connection if the connection is closed, or the
current Connection object if the connection is open
BOF Returns true if the current record position is before the first record, otherwise
false
CacheSize Sets or returns the number of records that can be cached
CursorLocation Sets or returns the location of the cursor service
CursorType Sets or returns the cursor type of a Recordset object
DataSource Specifies an object containing data to be represented as a Recordset object
EOF Returns true if the current record position is after the last record, otherwise false
Filter Sets or returns a filter for the data in a Recordset object
Index Sets or returns the name of the current index for a Recordset object
LockType Sets or returns a value that specifies the type of locking when editing a record in
a Recordset
MaxRecords Sets or returns the maximum number of records to return to a Recordset object
from a query
PageCount Returns the number of pages with data in a Recordset object
PageSize Sets or returns the maximum number of records allowed on a single page of a
Recordset object
RecordCount Returns the number of records in a Recordset object
Sort Sets or returns the field names in the Recordset to sort on
Source Sets a string value or a Command object reference, or returns a String value that
indicates the data source of the Recordset object
State Returns a value that describes if the Recordset object is open, closed,
connecting, executing or retrieving data
Status Returns the status of the current record with regard to batch updates or other
bulk operations

12) List out Metods of Recordset object.(Remember Any Six)


Method Description
AddNew Creates a new record
Cancel Cancels an execution
CancelBatch Cancels a batch update
CancelUpdate Cancels changes made to a record of a Recordset object
Close Closes a Recordset
Delete Deletes a record or a group of records
Find Searches for a record in a Recordset that satisfies a specified
criteria
GetRows Copies multiple records from a Recordset object into a two-
dimensional array
Move Moves the record pointer in a Recordset object
MoveFirst Moves the record pointer to the first record
MoveLast Moves the record pointer to the last record
MoveNext Moves the record pointer to the next record
MovePrevious Moves the record pointer to the previous record
Open Opens a database element that gives you access to records in a
table, the results of a query, or to a saved Recordset
Save Saves a Recordset object to a file or a Stream object
Update Saves all changes made to a single record in a Recordset object
UpdateBatch Saves all changes in a Recordset to the database. Used when
working in batch update mode

13) Explain MoveNext, MoveLast and MovePrevious Methods


MoveFirst Method
This method is used to move to the first record in a Recordset object. It also makes the first
record the current record. If you call MoveFirst() when the Recordset is empty, it generates
an error.

MoveLast Method
This method is used to move to the last record in a Recordset object. It also makes the last
record the current record.If you call MoveLast() when the Recordset is empty, it generates an
error.

The MoveNext Method


This method is used to move to the next record in a Recordset object. It also makes the "next"
record the current record. If you call MoveNext() when the current record is the last record, it
generates an error.

The MovePrevious Method


This method is used to move to the previous record in a Recordset object. It also makes the
"previous" record the current record. If you call MovePrevious() when the current record is
the first record, it generates an error.

Syntax
objRecordset.MoveFirst
objRecordset.MoveLast
objRecordset.MoveNext
objRecordset.MovePrevious
14) Explain System DSN
Data Source Name (DSN) provides connectivity to a database through an ODBC driver. The
DSN contains database name, directory, database driver, UserID, password, and other
information. Once you create a DSN for a particular database, you can use the DSN in an
application to call information from the database.The developer creates a separate DSN for
each database. To connect to a particular database, the developer specifies its DSN within a
program. In contrast, DSN-less connections require that all the necessary information be
specified within the program.

 System DSN -- can be used by anyone who has access to the machine. DSN info is
stored in the registry.if you set up a System DSN, it does not matter who logs on to
the machine; all users that logon to that workstation will have access to that Data
Source.

To do that you need to follow a couple of steps:


Open the 'ODBC Data Source Administrator'
( Start -> Control Panel -> Administrative Tools -> Data Sources )
Click Add...
In the box that will appear you should select the Microsoft Access driver and click Finish

Type in a name that is easily remembered and relevant to your database in the 'Data Source
Name' textbox
Click Select and browse to your local database file
Click OK all the way out

You have now created a DSN which will come in handy when you try to connect and retrieve
information from your database

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy