0% found this document useful (0 votes)
20 views89 pages

Unit 3 VB

Uploaded by

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

Unit 3 VB

Uploaded by

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

Unit- III

ODBC and Data Access Objects: Data Access Options, ODBC,


Remote data objects,

ActiveX EXE and ActiveX DLL: Introduction, Creating an ActiveX


EXE Component, Creating ActiveX DLL Component.
System Architectures
Three Types
• Centralized System Architecture
• File Server Architecture
• Client Server Model
Centralized System Architecture
• Centralized computing refers to a system where all processing and data
storage is handled by a single, central device or system.

• Responsible for processing all requests and managing all data, and all
other devices in the system are connected to it.

Ex: Mainframe System

• central mainframe computer handles all processing and data storage for
the system.

• Users access the mainframe through terminals or other devices that are
connected to it.
• Merits
• Excellent Security

• Centralized Administration logic and data reside on same


Machine.

• De-Merits
• Expensive to buy,Maintain

• Application and DB resides inside same machine,no way to


partition because of physical limitations.
File Server Architecture
• Application logic executed in Client Workstation instead on
server.
• Servers also provided access for computing resources like
printer and large hard drives.
• Merits
• Low Cost, Flexible Arrangement
• Resources can be added /Removed
• De-Merits
• Application logic executed on client machine – needs large
power to run the application.
• File server- provides files to store the data
Client - Server Model
• It is a process of involving minimum of 2 independent
entities client and server.
• Client – Places Request (SQL Query)
• Server – services Request and result sent back to client.
• 2 separate application operating independently work together
to complete task.
• It doesn’t return a file as a request instead it returns as series
of disk blocks.
• 2 independent process work together to complete a task.
Two-Tier Client / Server Model
• In two-tier, the application logic is inside the User Interface
on the client or within the database on the server (or both).

• System interface is usually located in the user’s desktop


environment

• Database management services are usually in a server that is


a more powerful machine that services many clients.
2
Three-Tier Client / Server Model
• In the three-tier architecture, a middle tier was added
between the user system interface client environment and
the database management server environment.

• Three-tier systems are more scalable, robust and flexible.


In addition, they can integrate data from multiple sources.
Data access options
Data Access Objects (DAO):It communicates
with the Microsoft access and other ODBC data
sources through the JET engine.
ODBC Direct :It allows accessing ODBC data sources through
the RDO (Remote Data Objects) and DAO objects bypassing
the JET database engine.

Data Control: It binds data-aware


controls to Microsoft access or other
ODBC data sources.
Data access options
Remote Data Objects (RDO):It
provides a frame work for using
code to create and manipulate
components of a remote ODBC
Remote
database Database
system. Control: It binds
to controls to an ODBC remote
Active Data
database.
Objects(ADO):Designed to provide
a common bridge between different
databases, file systems and e-mail
servers
ODBC and Data Access Objects
• Data Access Object or DAO - organizing code to handle the
communication between your program and a database.

• It’s a blueprint that developers use to create a structured and


orderly system for getting information from a data source, like a
database.

• DAO - abstracting away the complexities and offering a clear way


to interact with the data.
Data access objects
Database Object : Used to define the database’s table, relations, and
stored queries and to open record set objects.

Table Def : Corresponds to a stored table definition.

Query Def : A stored query definition, which is a precompiled SQL


statement. Used for executing predefined SQL queries.

Recordset : A cursored view into a database table, storing rows of data


in a buffer and pointing to one row of data at a time (current record).
Allows manipulation and traversal of database records.

Field Object : Represents a single column in a table or query result


Index Object : A stored index associated with a Table Def or table type
Recordset object.Used to speed up data retrieval and enforce
uniqueness.

Parameter Object : Allows parameterized queries for dynamic SQL


execution.

User Object : Used to define and enforce database security and


Manages user access and permissions.

Group Object: A collection of users with similar access rights and


Facilitates the management of user permissions by grouping users.

Relation: Represents a relationship between files in tables or queries.


Property Object : Stores additional metadata about data access objects.

Document Object: Holds metadata and settings for individual database


objects.

Container Object : Holds information describing the objects that are


grouped into that container. Organizes and manages collections of related
database objects.
Accessing and navigating databases
To work with data access objects, reference has to be set to the appropriate
DAO library. The two DAO libraries supported by Visual Basic 6.0

•Microsoft DAO 3.51 Object Library

•Microsoft DAO 2.5/3.51 Compatibility Layer

Steps to be followed to set a reference to the DAO library:

• Select references from the Project Menu

• Select the DAO 3.51 object library

• Click on OK.
Opening a Database
To open an existing database, the openDatabase method of the Workspace Object is
used.
• Syntax: OpenDatabase(dbname,[options], [readonly], [connect])
• dbname: The name of the database to open. This could be a full path to an
external database file.
• options (optional): Specifies how to open the database. This can be omitted or set
to True or False:
•True: Opens the database in exclusive mode, meaning no other user can open
it at the same time.
•False (default): Opens the database in shared mode, allowing multiple users.
• read-only (optional): Indicates whether the database should be
opened in read-only mode.
•True: Opens the database as read-only.
•False (default): Opens the database with both read and write
access.
• connect (optional): Connection information for an external
database. Typically used for connecting to ODBC or other
external databases.
Recordset Object
• RecordSet: A recordset is an object that contains a set of records
from the database. There are five major types

• Table-Type

• Dynaset-Type

• Snapshot-Type

• Forward-Only

• Dynamic Type
• TableTypeRecordset: Fastest type of Recordsets representing a single table
used to add, change or delete records.
• DynasetTypeRecordset:It represents a table, or attached tables or the results of
queries. Dynaset enables us to update data from more than one table.
• Snapshot Type Recordset:Snapshot can refer to any table, attached table or query.
It cannot be updated and does not reflect any changes made by users.
• Dynamic Type Recordset:It represents a query result set from one or more
table. We can add, change or delete records from row-returning query. It is only
available in ODBC Direct Workspaces.
• Forward Only Type Recordset: This is identical to snapshot recordset except that
we can only scroll forward through its records
Creating a Recordset
• Open recordset method is used to open a recordset and create a
recordset variable.

Dim rs as Recordset
Set rs =
db.OpenRecordSet(“employee”,dbOpenTable,dbReadOnly)

Db - variable represents DB objects


dbOpenTable – type of recordset to be created
Navigating a Recordset
• After recordset creation, move methods can be used
to navigate through the records in a recordset.
• MoveFirst
• MoveNext
• MovePrevious
• MoveLast
• BOF & EOF: when user moves beyond the first and
last record
Modifying and Deleting Records
• Edit & Methods : User can edit the current record.

• Update Method : update the necessary changes in the record.

• AddNew Method : Used to create new records in record set.

• Delete Method : used to delete a record using dynaset or


Tabletype recordset.(without warning/messages it will be
deleted)
Find Records
• Find methods can be used to locate a record in a dynaset or
snapshot type.
• FindFirst – moves to first record satisfying specified criteria
• FindLast - moves to Last record satisfying specified criteria
• FindNext - moves to next record satisfying specified criteria
from the current record.
• FindPrevious - moves to previous record satisfying specified
criteria from the current record.
Seek Method
• Seek method is used to locate a record in a table type
recordset.

• It performs indexed search for the first occurrence of the


record that matches the indexed criteria.

• Dynasets and shapshots cannot be used.


Manipulating stored queries using
Querydef
• Object contains information about stored SQL Query.

• These objects are faster than SQL queries because VB preprocesses the
SQL query before executing.

• Stored queries are already processed.

• 2 Methods – Execute Method & OpenRecordset Method

• Execute Method-used to perform action queries that does some actions


on the dB.

• OpenRecordset – Used to retrieve data from the DB.


Tabledef Data object
• Collection of table objects that contain detailed definition about each datatable
in DB, 5 Methods are available

• openRecordSet method – used to open a table

• RefreshLink – method updates and refreshes any attached table links for
tabledef object.

• CreateProperty – used to create and store a user-defined property.

• CreateIndex – used to add an index to tabledef object.

• CreateField – method used to add a new field to an existing Tabledef object.


Modifying and Deleting Existing Tables
• Adding new fields – Append method

• Deleting existing Fields – Delete Method

• Create Table Queries

• Insert Table Queries


ODBC (Open DataBase
• ODBC is a windows Connectivity)
Technology, lets client Application connects to a
external DB.
• To use ODBC, we need ODBC driver to access a particular DB
application.
• IF this driver is available client machine should be configured with this
driver.
• Database login and password should be configured on client machine.
• It is called DataSource.
• Many data sources can be configured for a multiple drivers.
• 3 Parts
• ODBC Driver Manager
• One or more drivers
• One or more Data Sources
Creating ODBC Data source
Using ODBC with DAO
Remote Data Objects
• Select References from Project Menu.
• Select Microsoft Remote Data Object 2.0 from the list
• Click Ok.

• RDO consists of objects and collections form a framework.


• Relationship b/w objects and collections represents logical
structure of DB.
rdoEngine

RDO
Hierarchy
Hierarchy of RDO
• rdoEngine : Used to access remote data. All requests by
RDO handled by rdoEngine.
• rdoEnvironment: contains information about current
environment for Data connections.
• rdoConnection : contains details needed to establish
connection between Application and Remote data
Source.
• rdoResultset : contains direct reference to all the rows
and columns in the recordset.
• rdoTable : information about all columns of base table
• rdoColumn : information about contents and properties
of each data column.
• rdoQuery : method for creating and executing queries.
• rdoParameter : manages the parameter passes during
processing of Queries.
Establishing a Connection
• Set Connection = Environment.OpenConnection
( dsname[, prompt[, readonly[,connect [, options ]]]])

• Openconnection – opens a connection to ODBC


Datasource.

• Connection : checks the rdoconnection that user is


opening.

• Environment : evaluates existing rdoenvironment

• dsname : registered ODBC dataSource name.


• Prompt : Determines which operation is carried out.
• rdDriverNoPrompt: No user prompt; uses the connection
string as it is.

• rdDriverPrompt: Prompts the user for missing information.

• rdDriverComplete: Prompts for all missing information.

• rdDriverCompleteRequired: Requires the user to complete all


necessary information.

• readonly: Optional. A Boolean value (True or False)


that specifies whether the connection is read-only.
Establishing a Connection
• connect:Optional. provide additional connection
parameters if required by the database driver.
(credentials, timeout settings, etc.)

• Options :Optional to specify additional options for the


connection, such as cursor type, command timeouts, or
other database-specific settings.
Executing SQL Statements
• After connection establishment users can execute
queries on the database.

• openResultSet method of Connection object is used


to run queries.

• Syntax:

Set rs=rdoconn.openResultSet(name,type,

locktype,option )
Executing SQL Statements
• rs (Result Set Object):hold the result set
returned from the database query, used to
navigate through the records, update data.

• rdoconn (Connection Object):used to open


the result set from the connected database.
• name: SQL query string that you want to execute (e.g.,
"SELECT * FROM Students")
• type:Mentions type of result set to be opened.
• rdOpenStatic: A static copy of the data; changes made by
others are not visible.
• rdOpenDynamic: A dynamic result set that reflects all
changes made to the data by other users.
• rdOpenKeyset: can move forward and backwarda and no
visibility in changes.
• rdOpenForwardOnly: A result set that can only be moved
forward; it’s generally faster.
Lock Type
• locktype: specifies the locking behavior for the result set,
determining how records are locked during editing.

• rdConcurReadOnly: The result set is read-only; no updates


can be made.

• rdConcurLock: Locks the record when it is read.(full Page)

• rdConcurRowVer: Uses row versioning to manage


concurrent changes.(row Lock)

• rdConcurValues: Similar to rdConcurRowVer but allows


updates.
ActiveX EXE and ActiveX DLL
• ActiveX components are a set of technologies from
Microsoft that allow for the creation of reusable
software components.
• ActiveX EXE and ActiveX DLL are two types of
ActiveX components that you can create in Visual
Basic to build reusable software components.
• ActiveX EXE and ActiveX DLL components are to
reuse code, making our applications more modular
and maintainable.
ActiveX DLL
• Servers can be implemented as ActiveX DLL or
ActiveX EXE .
• Difference lies in how the server is executed.
• ActiveX DLL – In-Process Server
• An dynamic link library (DLL) is a in-process server
that runs within the same process space as the calling
application.
• When a client application needs to use a component
provided by the in-process server, the server is loaded
into the client's memory space.
ActiveX EXE
• ActiveX EXE– out Process Server

• An ActiveX EXE is a standalone executable file that runs in its own


process.

• A separate process, communication between the client application


and the ActiveX EXE involves inter-process communication (IPC).

• Slower than In-process Application

• ActiveX EXEs can handle multiple clients simultaneously with each


client having its own instance of the component.

• Typically used for creating server applications, background services,


or components by multiple clients.
Creating ActiveX EXE
Using ActiveX EXE

You might also like