Client Server Databases

download Client Server Databases

of 20

Transcript of Client Server Databases

  • 8/8/2019 Client Server Databases

    1/19

  • 8/8/2019 Client Server Databases

    2/19

    y Advantages: o Excellent security and control over applicationso High reliability - years of provenMF technologyo Relatively low incremental cost per user (just add a terminal)

    y Disadvantages:

    o

    Unable to effectively serve advanced user interfaceso Users unable to effectively manipulate data outside of standard applications

    P ersonal Computer - Stand-Alone Database

    y Database (or files) reside on a PC - on the hard disk.y Applications run on the same PC and directly access the database. In such cases, the

    applicationis the DBM S.y Business rules are enforced in the applications running on the PC.y A single user accesses the applications.

    F ile Sharing Architecture

  • 8/8/2019 Client Server Databases

    3/19

    y PCs are connected to a local area network (LAN).y A single file server stores a single copy of the database files.y PCs on the LAN map a drive letter (or volume name) on the file server.y Applications run on each PC on the LAN and access the same set of files on the file

    server. The application is also the DBM S.y

    Business rules are enforced in the applications - Also, the applications must handleconcurrency control. Possibly by file locking.y Each user runs a copy of the same application and accesses the same files.y Example: SharingM S Access files on a file server.y Advantages:

    o (limited) Ability to share data among several userso Costs of storage spread out among userso M ost components are now commodity items - prices falling

    y Disadvantages: o Limited data sharing ability - a few users at most

    Classic Client/Server Architecture

    y Client machines:o Run own copy of an operating system.o Run one or more applications using the client machine's CPU, memory.o Application communicates with DBM S server running on server machine through

    a Databa se Dr iver o Database driver (middleware) makes a connection to the DBM S server over a

    network.o Examples of clients: PCs withM S Windows operating system.F orms and reports

    developed e.g. Oracle Developer/2000, etc.y Server M achines:

    o Run own copy of an operating system.o Run a DatabaseM anagement System that manages a database.o Provides a Listening daemon that accepts connections from client machines and

    submits transactions to DBM S on behalf of the client machines.

  • 8/8/2019 Client Server Databases

    4/19

    o Examples: Sun Sparc server running UNIX operating system. RDBM S such asOracle Server, Sybase, Informix, DB2, etc.

    PC with Windows NT operating system.

    y M iddleware:o Small portion of software that sits between client and server.o Establishes a connection from the client to the server and passes commands (e.g.,

    SQL) between them.o See ODBCbelow.o Examples:

    F or Oracle: SQL*Net (or Net8) running on both client and server.F or Sybase: Sybase Open Client and Open Server.F

    or IBM

    DB2: Client Application Enablersy Business rules may be enforced at:

    1. The client application - so called "F at Clients".2. Entirely on the database server - so called "Thin Clients"3. A M ix of both.

    We can also call this a "Two Tier" or "Two Level" Client/Server ArchitectureAdvantages of client/server:

    0. Processing of the entire Database System is spread out over clients and server.1. DBM S can achieve high performance because it is dedicated to processing

    transactions (not running applications).

    2.

    Client Applications can take full advantage of advanced user interfaces such asGraphical User Interfaces.Disadvantages of client/server:

    0. Implementation is more complex because one needs to deal with middleware andthe network.

    1. It is possible the network is not well suited for client/server communications andmay become saturated.

    2. Additional burden on DBM S server to handle concurrency control, etc.3. As more business rule logic is programmed into the client side applications, they

    can become unwieldy.Stored procedures and triggerscan help in this case.Examples:

    o Oracle Server RDBM S running on a server.

    Oracle Developer/2000running on a client PC (connected with SQL*Net as themiddleware).

    o Oracle Server RDBM S running on a server.

  • 8/8/2019 Client Server Databases

    5/19

    Sybase-PowerSoft PowerBuilder running on a client PC.

    o Oracle Server RDBM S running on a server.

    M S Visual Basic application running on a client PC.

    o Sybase Adaptive Server RDBM S running on a server.

    C++ application running on a UNIX workstation.

    Three-Tier Client Server

    y Same general situation as traditional client/server.y Difference is the enforcement of business rules (applications logic) is done in a "middle"

    layer. Sometimes called "application logic" server.y Another option is to aggregate transactions from multiple users with aTransaction

    Monitor y Is "web friendly". The web browser becomes the user interface on the client.y Advantages:

    o Centralize applications logic (one place to make changes)o Relieves clients from having to load up on applications logic (the "fat client"

    approach).o F rees up DBM S server to efficiently process transactions

    y Disadvantages: o System complexity - extremely complex to program and debugo Security issues

    y Examples:o Oracle Server RDBM S running on a server.

  • 8/8/2019 Client Server Databases

    6/19

    BEA TuxedoTransaction Processing System running on the "M iddle tier"Sybase-PowerSoft PowerBuilder running on a client PC.

    o Oracle Server RDBM S running on a server.

    Oracle Web Applications Server running on the "M iddle tier"M S Internet Explorer (web browser) running on a client PC.

    o Sybase Adaptive Server RDBM S running on a server.

    Sybase Enterprise Application Server including the Sybase Jaguar CTStransaction processing system running on the "M iddle tier"C++ application running on a UNIX workstation.

    o M icrosoft SQL Server running on a Windows NT Server

    M icrosoft Transaction Server (M TS) running on theM iddle tier M icrosoft Visual Basic application running on the client PC

    o IBM DB2 RDBM S running on the back end

    IBM CICStransaction management

    COBOL application

    BTW, for those of you from the UNIX world, simply replace "PCs" with "UNIX Workstations"in the phrases above.

    Ex ample Study : Sybase Client-Server Databases

  • 8/8/2019 Client Server Databases

    7/19

    Mainframe Computing

    M ainframe computing was the popular computing model before the client/server model becamethe widespread standard. In mainframe computing, the mainframe performs all processing anduses a "dumb" terminal (one with no processing power of its own) as a display unit.F or

    example, retrieving and displaying employee information on a terminal requires the followingsteps:

    1. Display a form on the terminal into which a user can enter an employee ID

    2. Accept the employee ID information.

    3. Validate the format of the information.

    4. Check the availability of the employee information.

    5. Get the employee information from the database.6. F ormat the data for display on the users terminal.

    7. Display the employee information on the terminal.

    y We can categorize these tasks as those related to data presentation (steps 1, 6, and 7),those related to data validation (steps 2 and 3), and those related to data access (steps 4and 5). The mainframe performs all of the steps because the terminal has no processingcapability.

    y In the mainframe processing model, the server is heavily loaded because it performs allof the processing for every client (mainframes are computing monsters) In theclient/server model, however, clients can perform some portion of the application processing, such as data presentation and some data validation. This off-loading of sometasks to clients with processing power improves performance because the server has moretime for processing requests.

    Client/Server Computing in the Database E nvironment

    In just the last few years, the client/server model has gone from being the "new trend" indistributed (networked) computing to the "traditional model" for implementing distributedcomputing. It divides processing intocl ien t app l ic at ions and ser ver app l ic at ions that cooperate

  • 8/8/2019 Client Server Databases

    8/19

    to accomplish tasks for the integrated application.

    H ere are a few of the many advantages that client/server computing offers over thecomputing models that came before it:

    y Simplifies computer interactions for the user because smart clients implemented ondesktop workstations present graphical user interfaces (GUIs) and multimediaapplications. The cost of developing applications that use these types of interfaces for desktop workstations is less expensive than it is for the servers in mainframe computing.

    y Reduces network traffic, which improves performance. Consider the example given previously in the section `M ainframe Computing''. The mainframe model requires three

    network events: in step 1 when the host must display the form on the screen; in step 2when the client sends the employee ID back to the host; and in step 6 when the host sendsthe employee information back to the terminal and displays it. The same example usingthe client/server model requires only two network events: for step 4 when the client sendsthe employee ID to the server and in step 6 when the server sends the employeeinformation back to the client.

    y Allows an organization to use a variety of equipment to meet the needs of different

    applications and users because it supports ahet er ogeneous environment. Programmerscan get the processing power they need from workstations, and managers can work withcomputers that are best for creating schedules and other spreadsheets using desktopcomputers. The organization can save money by giving each employee the right amountof computing power needed to do their jobs.

    y F acilitates implementation of open systems because it is built around the InternationalStandards Organization (ISO) ReferenceM odel for networked systems. This model

    specifies an application programming interface (API) layer which hides the intricacies of lower level software, making it easy to add new hardware and applications.

    Client/Server Nodes and Implementation

  • 8/8/2019 Client Server Databases

    9/19

    Client and server applications can reside on the same computer, or node ; however, in adistributed computing environment, they usually reside on different nodes. Nodes aredistinguished ascl ien t nodes and ser ver nodes depending on their role.

    Client nodes tend to be generalized. Computers that run client applications may include many

    types of clients, such as a directory client, a file client, and a print client. There are often manynodes running the same client applications so that a single server node, such as a print server,serves several client nodes. Although a single server node can accommodate more than oneserver application, system designers often implementserver applications on dedicated servernodes because servers tend to be more specialized and require more processing and systemresources than clients.

    A server application is typically acontinuous process (for example, ad aemon in UNIX) while aclient application is most often a standard application program. During the course of its normal processing, a client application calls API routines to send the requests to a server. When theclient has finished its work, it stops execution. As a dedicated process, the server runs

    continuously: it waits for requests, detects them, processes them, returns the results, and thenwaits for the next request.

    Relative Roles of Clients and Servers

    The terms "client" and "server"characterize relative roles rather than absolute roles. F or example, in executing a print request, the print server becomes a client if it has to ask a fileserver to send it a copy of the file it is going to print.

    Architecture is fully functional when it allows clients to act as servers and servers to act as

    clients when necessary.F

    or example, Sybase implements this capability with the Open Clientand Open Server products. Sybase applications that have both client and server functionalityincorporateboth Open Client and Open Server libraries.

    F igureClientServer shows an example in which an application acts as both a client and a server.As a server, it responds to requests from and returns results to the Open Client application. As aclient, it makes requests of the SQL Server and processes the results of those requests.

    F igureClientServer: An application can act as both client and server

  • 8/8/2019 Client Server Databases

    10/19

    Sybase Client/Server Database E nvironment

    In the Sybase client/server database environment, SQL Server runs all of the actual databasemanagement systemit does all the processing associated with database access. The databaseserver carries out the tasks initiated by client requests directed to the database. It is built on amultithreaded architecture and ensures data integrity, concurrency control, and the ability torecover from failures. The database server also maintains thed ata dic t ionary which defines thestructure and contents of the database. The database client performs all the processing notassociated with database access.

    The Two-Tier Model

    In a two-tier configuration, client applications connect directly to server applications and submitrequests using Open Server applications or remote procedure calls (RPCs). RPCs allow users toopen a connection to a single SQL Server, and that SQL Server can then access data from manyother servers. A SQL Server application programmer can write custom event handlers to processclient requests.

    The first tier in a two-tier configuration consists of presentation and application logic. Examplesof applications at this layer are:

    y SQL access toolsy Application development tools (code generators)

    The second tier in a two-tier configuration offers direct service management and handlesconnections. It can include database servers and general purpose servers such as e-mail and printservers. Examples of these applications are:

  • 8/8/2019 Client Server Databases

    11/19

    y SQL Server applications that do not require global distributed transaction supporty Print, mail, or compute servers built with Open Server y Client messaging services built on event notification that use Open Server as a messaging

    hub

    F igureTwoTier shows SQL Server and Open Server applications in a two-tier configuration.

    F igure TwoTier: Two-tier architecture

    The Three-Tier Model

    When developers design and implement software using acomponent model , they create self-contained software blocks or c om ponen t s, each with a specific function. A component can bereplaced by another that has the same specifications without rewriting or changing surroundingcomponents. This component model for software design also results in the ability to reusecomponents.

    Three-tier architecture, based on thec om ponen t mode l , is a popular design solution for large or complex server applications that run under some type of middleware , such as a transaction processing monitor or an object-oriented environment. The three-tier architecture allows theflexibility and freedom to replace components without affecting the rest of the system.

  • 8/8/2019 Client Server Databases

    12/19

    Advertissment ????? Sybase is the only database company that makes it easy to implement anindependent application in the middle tier of a three-tier software architecture.F igureThreeTier illustrates the three-tier topology using Sybase products.

    F igure ThreeTier: A Sybase three-tier model

    The functionality of each tier is as follows:

    y The f ir st t ier supports presentation services on the client system.M inimally, it helpswindowing systems display and manipulate data. This tier might also validate user input.This tier consists of Sybase products from the "tools" layer, such as PowerBuilder or Optima++.

    y The sec ond t ier (or midd l e t ier ) can enforcebusiness rules and referential integrity across all components of the third tier, supports global distributed transaction

    management, and supports service mapping similar to a gateway application. This tier isimplemented as an intermediate server. It consists of Sybase products from the"middleware" layer, such as OmniCONNECT or Open Server.

    y The t hir d t ier is a back-end server that handles data integrity and local transaction branches. It has local responsibility for controlled resources, which are often databasesystems. This tier consists of Sybase products from the "database" layer, such as SQLServer, SybaseM PP, Sybase IQ, and SQL Anywhere.

    Three-tier architecture gives the application complete independence with respect to both thefront-end tool and the back-end datastore and makes it easy to extend database functionality.M any M IS developers find the three-tier construct essential.

    In environments that do not support a three-tier topology, developers must integrate businessrules either in the front-end tool or the back-end datastore. Business rules can be integrated withthe back-end datastore by programming them in stored procedures or atr igge r , a special kind of

  • 8/8/2019 Client Server Databases

    13/19

    stored procedure that automatically executes whenever data is inserted, updated, or deleted in thecolumns with which the trigger is associated. Programming business rules in triggers results independence on the datastore, so if business rules change, the database might need to bereoptimized.

    Open DataBase Connectivity (ODBC)

    y M iddleware has historically been proprietary. Note also subtle differences in SQL andhow it is implemented in various DBM S.

    y How can a single client access multiple DBM S servers with minimal changes ?y ODBC is middleware software that can connect a client to multiple servers from different

    vendors.y ODBC has two main portions that reside on the client: ADriver Manager and one or

    more DBMS drivers. y

    The Driver M anager presents a uniform interface to all clients. This consists of a set of function calls to query, update and manipulate data on a server y A DBM S Driver is typically supplied by the individual DBM S vendor and contains

    routines to convert requests from the Driver M anager into commands the specific DBM Sunderstands.

    y Try this: Visit several DBM S vendor's web sites and see if they offer an ODBC driver that can be downloaded to your PC.

  • 8/8/2019 Client Server Databases

    14/19

    Ex ample of the use of Open DataBase Connectivity (ODBC)

    What ODBC means to application developers

    ODBC was designed to allow application developers to decide between using the least common

    denominator of functionality across DBM Ss or exploiting the individual capabilities of specificDBM Ss.

    ODBC defines a standard SQL grammar and set of function calls that are based upon the SAGCLI specification, called the core grammar and core functions, respectively. If an applicationdeveloper chooses only to use the core functionality, they need not write any additional code tocheck for specific capabilities of a driver.

    With core functionality, an application can:

    y Establish a connection with a data source, execute SQL statements, and retrieve results.y

    Receive standard error messages.y Provide a standard logon interface to the end user.y Use a standard set of data types defined by ODBC.y Use a standard SQL grammar defined by ODBC.

    ODBC also defines an extended SQL grammar and set of extended functions to provideapplication developers with a standard way to exploit advanced capabilities of a DBM S. Inaddition to the above features, ODBC includes a set of extensions that provide enhanced performance and increased power through the following features:

    y Data types such as date, time, timestamp, and binary.y

    Scrollable cursors.y A standard SQL grammar for scalar functions, outer joins, and procedures.y Asynchronous execution.y A standard way for application developers to find out what capabilities a driver and data

    source provides.

    ODBC e x ample: Win32::ODBC and P erl script

    The following two tables will be used :

    Table 1: Sauces

    F ield Name Type Length Notes

    ProductID AutoNumber n/a Sequence / Primary keyProductName Text 25Quantity Number Double in ounces

  • 8/8/2019 Client Server Databases

    15/19

    Price Number DoublePepperType Text 20 main type of pepper in sauce

    Scoville Text Long rating of heat content; Jalapeo pepper = 3-4,000 units,Scotch Bonnets (Habaero) = 2-300,000 units!

    Table 2: State

    F ield Name Type Length Notes

    PID Number Integer Process ID -M ulti-key Primary keyProductID Number Long F oreign Key into Sauces table -M ulti-key Primary keySequence Number Integer M ulti-key Primary key

    To get started, let's write a simple script that extracts all the data from the database and writesthem out in a table. The first thing to do, as when using any Perl module, is to tell the script thatwe want touse the module.

    use Win32::ODBC; Next we tell it to create a new ODBC object:

    my($db) = new Win32::ODBC("Article");This creates an object ($ db ) which connects to the data source named 'Article'. If we had a user name and password associated with this data source, we could supply them all using an ODBCconnect string:

    my($db) = new Win32::ODBC("dsn=Article; uid=foo; pwd=bar");where 'Article' is the Data Source Name, 'foo' is the User ID, and 'bar' is the Password.

    Next, we write the SQL to extract the data (the capitalization is for stylistic reasons):$db->Sql("SELECT * FROM Sauces");

    and then the loop to fetch the data, one row at a time:while ($db->FetchRow()) {

    ...}

    Inside thewhile loop we actually get the data. In Win32::ODBC, there are two actions, one tofetch the row, and one to get the data that was fetched. There are also two ways to get the fetcheddata, Data() and Data H ash() . The former returns the data into an array, in the order it wasselected in the SQL statement. The latter returns the data into a hash, in the form'$ hash{ F ieldName} = DataValue '. If you select all fields using the "*" wildcard, as we did, then

    the field order that the data comes back in is undefined, so usingData() might not make sense.We'll use Data H ash() . F inally, we close the ODBC handle before the end of the program.

    Putting it all together, the script should look something like the following:

    use Win32::ODBC;

    my($db) = new Win32::ODBC('Article');

  • 8/8/2019 Client Server Databases

    16/19

    $db->Sql("SELECT * FROM Sauces");

    while ($db->FetchRow()) {my(%data) = $db->DataHash();

    print HTML "$data{'ProductName'}";print HTML " $data{'Quantity'} ounces";print HTML " \$$data{'Price'}";print HTML " $data{'PepperType'}";print HTML " $data{'Scoville'} Scoville Units";

    }

    $db->Close();Transactions Some ODBC drivers support transactions, with commits and rollbacks (seeData Sources to findout how to determine if your driver supports this). Sometime after connecting (usuallyimmediately after, but it depends on your logic flow) you can set the AutoCommit option off,and then rollback or commit depending upon program flow:

    $db->SetConnectOption('SQL_AUTOCOMMIT', 'SQL_AUTOCOMMIT_OFF');...if ($fatal_error) {

    $db->Transact('SQL_ROLLBACK');die "Error - rolling back\n";

    }...$db->Transact('SQL_COMMIT');

    Data Sources Sometimes you don't know ahead of time which database you need to connect to. You can querythe ODBCM anager and get a list:

    print HTML "\n";

    my(%dsn, $key) = Win32::ODBC::DataSources();

    foreach $key (sort keys %dsn) {print HTML "$key\n";

    }

    print HTML "\n";This will produce a box with all of the data sources listed. But suppose you knew you onlywanted Oracle databases. The value of the returned hash contains the name of the driver, so youcould filter them:

    my(%dsn, $key) = Win32::ODBC::DataSources();

    foreach $key (sort keys %dsn) {

    print HTML "$key\n" if $dsn{$key} =~ /Oracle/;}Once you have connected to a driver, you can query it to see if it can handle a specific ODBCAPI function, such as transactions:

    my(%data) = $db->GetFunctions($db->SQL_API_SQLTRANSACT);my($transOK) = $data{$db->SQL_API_SQLTRANSAC};

    $db->SetConnectOption('SQL_AUTOCOMMIT', 'SQL_AUTOCOMMIT_OFF')if ($transOK);

  • 8/8/2019 Client Server Databases

    17/19

    or you could query the connection for things like the database name and version:my($db_ver) = $db->GetInfo($db->SQL_DBMS_VER);my($db_name) = $db->GetInfo($db->SQL_DBMS_NAME);

    H igh-level ODBC

    y Look in the Control Panel (shown here, from Windows 95):

    y Open up the32bit ODBC icon. This is called theO DBC Data Sour c e Adminis trat or or O DBC Adminis trat or for short.

    y Click on theODBC Drivers tab to see which drivers are installed:

  • 8/8/2019 Client Server Databases

    18/19

  • 8/8/2019 Client Server Databases

    19/19

    If necessary, a username and password required to gain access to the databaseF Inally, any other options the particular ODBC driver requires