Tải bản đầy đủ (.pdf) (26 trang)

Instructor Inputs - Session 14 pot

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.02 MB, 26 trang )

Instructor Inputs
Session 14

¤NIIT Instructor Inputs 14.3
This session includes Chapter 9 and Chapter 10 of the Student Guide.
Slide 1
Slide 1 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
In this session, you will learn to:
Understand managed code
Create managed database objects
Define the Hypertext Transfer Protocol endpoints
Implement the Hypertext Transfer Protocol endpoints for Web
services
Objectives
Start the session by sharing the objectives with the students. In this session, the students
will learn the importance of managed objects and how to create them. In addition, they
will also learn how to implement Web services in SQL Server 2005 using HTTP
endpoints.
Session Overview
14.4 Instructor Inputs ¤NIIT
Slide 2
Slide 2 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
CLR integration:
Allows the database developer to write the code in any of the
.NET supported languages
Allows to run managed code within a database
Provides the following functions and services required for


program execution
Introduction to SQL Server CLR Integration
In this topic, you need to explain the students about CLR. As they have already read about
CLR in the chapter 1, you need not to go into the details of CLR.
Explain how CLR has been incorporated in the SQL Server itself. Also explain the
benefits of integrating CLR inside SQL Server itself. You can use the examples provided
in the Student Guide to clarify the concept to the students.
T-SQL has been the conventional language to write database objects, such as stored
procedure, triggers and functions. SQL Server 2005 provides the new possibilities to the
database developer by integrating .NET Framework in it. SQL Server 2005 allows the
database developers to write stored procedures, triggers, user-defined types, user-defined
aggregates, and user-defined functions in any of the .NET supported language, build a
.dll, register and use it inside a SQL Server.
It is very important that the students understand that you are not removing the business or
data layer by hosting the C# code in the SQL Server. SQL Server is still a database and is
not intended to be used as an application server in your architecture.
¤NIIT Instructor Inputs 14.5
Slide 3
Slide 3 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
Managed database objects can be created in the following
situations:
To implement complicated programming logics
To access external resources
To implement a CPU-intensive functionality that can run more
efficiently as compared to the managed code.
T-SQL statements can be used in the following situations:
To perform data access and manipulation operations that can
be done using the T-SQL statements.

To implement programming logic tat can be easily
implemented using T-SQL programming constructs.
Identifying the Need for Managed Code
In this topic, you need to explain the need for managed code to the students. You need to
explain the limitations of T-SQL to the students, and how those limitations can be
overcome by introducing managed code in SQL Server.
T-SQL is a language that is used to manipulate and query data from a database server. It
provides a number of database features, such as query plans and caching of query plans
and their results. Because of all these features, T-SQL is the best choice for the operations
in the SQL Server. But the procedural aspect of T-SQL makes it complicate to use in
situations that involve functions such as, complex mathematical computations, recursive
operations, and heavily procedural.
In addition, T-SQL can not take the advantage of code reuse. If you try to implement all
this using T-SQL, the network traffic of your company goes into a loop and results in
slow query processing. With the ability to write and host .NET code inside SQL Server
2005, you now can prevent the network roundtrips and host the necessary .NET code right
inside SQL Server.
14.6 Instructor Inputs ¤NIIT
Slide 4
Slide 4 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
Just a minute
Which of the following is supported by .NET and not by
T-SQL?
1. Writing queries
2. Creating procedures
3. Object-Orientation
4. Writing triggers
Answer:

3. Object-Orientation
Reiterate the concept taught by asking the given question.
Slide 5
Slide 5 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
Assemblies:
Are created to attach the managed code
Are created using the CREATE ASSEMBLY command
Syntax:
CREATE ASSEMBLY assembly_name
FROM { <client_assembly_specifier
> |
<assembly_bits>
[ , n ] }
[ WITH PERMISSION_SET =
{ SAFE | EXTERNAL_ACCESS | UNSAFE } ]
Let’s see how…
Importing and Configuring Assemblies
In this topic, you need to explain the concept of assemblies to the students. In addition,
you also need to teach how to import the .NET assembly inside the SQL Server. To
clarify the concept, you may provide the students with the example provided in the
Student Guide.
¤NIIT Instructor Inputs 14.7
The students have learned about the assemblies in .NET framework. To clarify the doubts
of the students, you can specify that the assemblies in .NET are the .dll or .exe files that
have provide a specific functionality. In SQL Server 2005, an assembly is a database
object that stores the code of .NET assembly.
Slide 6
Slide 6 of 31Session 14

Ver. 1.0
Querying and Managing Data Using SQL Server 2005
Just a minute
Which of the following PERMISSION_SET will you use to
access another database server?
1. SAFE
2. EXTERNAL_ACCESS
3. UNSAFE
Answer:
2. EXTERNAL_ACCESS
Reiterate the concept taught by asking the given question.
Slide 7
Slide 7 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
Managed database objects can be of the following types:
Stored Procedures
Functions
Triggers
UDTs
Creating Managed Database Objects
14.8 Instructor Inputs ¤NIIT
Note
In this topic, you need to explain the various types of managed database objects that can
be created in SQL Server. As students are already aware of these all database objects, you
need not differentiate between them.
In the following topics, you will show examples given in the Student Guide to
demonstrate how to create different types of managed codes.
Slide 8
Slide 8 of 31Session 14

Ver. 1.0
Querying and Managing Data Using SQL Server 2005
Managed stored procedure:
Is implemented by creating a procedure that refers to an
imported assembly
Syntax:
CREATE PROCEDURE <Procedure Name>
AS EXTERNAL NAME <Assembly Identifier>.<Type
Name>.<Method Name>,
Let’s see how…
Creating Managed Database Objects (Contd.)
In this topic, you need to explain the concept of creating a managed procedure to the
students. These managed stored procedures will have an assembly attached to it.
Whenever the stored procedure is executed, the code written in the assembly will be
executed. To explain the concept, you can use the example provided in the Student Guide.
Before executing the code, you need to copy the ConvertXML.dll file in the C drive of
the server. This file is given in the Datafiles_for_faculty\QMDS2005\Chapter 09 folder
of the TIRM CD.
When explaining the syntax of the command, mention that the EXTERNAL NAME
clause specifies the database server to use an external assembly as the code for the
procedure.
¤NIIT Instructor Inputs 14.9
Note
Slide 9
Slide 9 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
Managed function:
Is implemented by creating a function that refers to an
imported assembly

Syntax:
CREATE FUNCTION <Function Name>
(
<Parameter List>
)
RETURNS <Return Type>
AS EXTERNAL NAME <Assembly Identifier>.<Type
Name>.<Method Name>
Let’s see how…
Creating Managed Database Objects (Contd.)
In this topic, you need to explain the concept of managed functions to the students. Use
the example provided in the Student Guide to demonstrate the concept.
Before executing the code, you need to copy the CalSalAssembly.dll file in the C drive
of the server. This file is given in the Datafiles_for_faculty\ QMDS2005\Chapter 09
folder of the TIRM CD.
14.10 Instructor Inputs ¤NIIT
Note
Slide 10
Slide 10 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
Managed trigger:
Is implemented by creating a trigger that refers to an imported
assembly
Syntax:
CREATE TRIGGER <TriggerName>
ON <Table or View> <FOR | INSTEAD OF | AFTER>
< INSERT | UPDATE | DELETE >
AS EXTERNAL NAME <Assembly Identifier>.<Type
Name>.<Method Name>

Let’s see how…
Creating Managed Database Objects (Contd.)
In this topic, you need to explain the concept of managed triggers to the students. Use the
example provided in the Student Guide to demonstrate the concept.
Before executing the code, you need to copy the ValidateMail.dll file in the C drive of
the server. This file is given in the Datafiles_for_faculty\ QMDS2005\Chapter 09 folder
of the TIRM CD.
¤NIIT Instructor Inputs 14.11
Note
Slide 11
Slide 11 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
Managed user-defined type:
Is created by using the CREATE TYPE command
Syntax:
CREATE TYPE [ schema_name. ] type_name
{
FROM base_type [ (precision [ , scale ] ) ]
[ NULL | NOT NULL ]
| EXTERNAL NAME assembly_name[.class_name]
}
Let’s see how…
Creating Managed Database Objects (Contd.)
In this topic, you need to explain the concept of managed user-defined types to the
students. To clarify the concept to the students, you need to run the examples provided in
the Student Guide.
Before executing the code, you need to copy the ZipCode.dll file in the C drive of the
server. This file is given in the Datafiles_for_faculty\ QMDS2005\Chapter 09 folder of
the TIRM CD.

14.12 Instructor Inputs ¤NIIT
Slide 12
Slide 12 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
Just a minute
When will you use managed code instead of T-SQL?
1. When you need to write queries.
2. When you need to access external resources.
3. When you need to perform an administrative task on the
database.
Answer:
2. When you need to access external resources.
Reiterate the concept taught by asking the given question.
Slide 13
Slide 13 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
Problem Statement:
The management of AdventureWorks, Inc. has decided that
they want to include the details of the spouse of employees in
the database. The application that is used to enter the
employee detail will accept the name and date of birth of the
spouse of an employee. In addition, it will concatenate the two
values separated by a ";". As a database developer, you need
to store the spouse details in the following format:
Spouse Name: <name of the spouse> ; Spouse Date of Birth :
<date of birth>
To implement this, you have decided to create a managed
user-defined data type. How will you create this data type?

Demo: Implementing Managed User-Defined Types
At the end of this demo, the students will be able to create a user-defined type using a
.NET assembly.
¤NIIT Instructor Inputs 14.13
Note
Slide 14
Slide 14 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
Solution:
To solve the preceding problem, you need to perform the
following tasks:
1. Enable CLR in the database.
2. Create an assembly.
3. Create a managed database user-defined data type.
4. Create a table that will implement the user-defined data type.
5. Verify the output.
Demo: Implementing Managed User-Defined Types (Contd.)
Before executing the code, you need to copy the SpouseDetails.dll file in the C drive of
the server. This file is given in the Datafiles_for_faculty\ QMDS2005\Chapter 09 folder
of the TIRM CD.
Slide 15
Slide 15 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
SOA:
Is an extension of distributed computing based on the
request/reply design pattern
Modularizes the business logic of an application and presents
them as services

Allows to create objects, such as, Web services that can be
accessed from heterogeneous systems
Introduction to Service-Oriented Architecture (SOA)
14.14 Instructor Inputs ¤NIIT
In this topic, you need to explain the concepts of SOA to the students. The concept of
SOA is new to the students. Therefore, you need to clarify the concept.
The term service-oriented architecture expresses a perspective of software architecture
that defines the use of loosely coupled software services to support the requirements of
the business processes and software users.
SOA is a collection of services. These services communicate with each other. The
communication can involve either simple data passing or it could involve two or more
services coordinating some activity. Some means of connecting services to each other is
needed. Service-oriented architectures are not a new thing. The first SOA for many people
in the past was with the use DCOM or Object Request Brokers (ORBs) based on the
CORBA specification.
Slide 16
Slide 16 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
Flash presentation: Introduction to Web Services
Web Service is a collection of methods that provide
programmable logic used by client applications over the
Internet.
SQL Server 2005 provides native XML Web services by
using the following open standards:
Hypertext Transfer Protocol (HTTP)
Simple Object Access Protocol (SOAP)
Web Services Definition Language (WSDL)
Introduction to Web Services
Show the flash presentation to introduce Web services to the students. Through this

presentation the students will learn about the Web services.
Inputs for Flash Presentation
Screen 1
A user sends a request to a Web server to view a website. The website further sends
request for data to a Web service. The web service provides the required data that is used
by the website.
¤NIIT Instructor Inputs 14.15
Screen 2
A web services provides a set of functionalities to various clients. These clients are
websites that need to show a common data. The example that is shown is of stock rates.
Various websites need to show stock rates and update them frequently. A Web service
provides update stock details to all the websites.
Screen 3
If a Web service takes data from a database server, it requires opening access through
additional ports on the Internet firewall. This increases the security threat to the
organization. As a solution to this, SQL Server 2005 allows you to create Web services
inside the database engine. Therefore, the Web service can now access the database
within the same database instance or server.
The websites can directly get connected to the Web services created on SQL Server.
HTTP endpoints are the connecting points through which users can get connected to the
Web services.
In addition, you can tell the students that Web services implemented in SQL Server
contain the stored procedures and functions as Web methods.
In addition, you also need to introduce the various technologies used in the creation,
searching, and deploying web services. You need not explain the details of
implementation of HTTP, SOAP, and WSDL but clarify the concept to the students.
 HTTP: Is a protocol used on the World Wide Web to transfer information. The
original purpose of HTTP is to publish and retrieve HTML pages.
HTTP is a request/response protocol between clients and servers. The originating
client, such as a web browser, spider, or other end-user tool, is referred to as the user

agent. The destination server, which stores or creates resources such as HTML files
and images, is called the origin server. In between the user agent and origin server
may be several intermediaries, such as proxies, gateways, and tunnels.
 SOAP: Is a protocol for exchanging XML-based messages over a computer network,
normally using HTTP. SOAP forms the foundation layer of the Web services stack.
It provides a basic messaging framework.
There are several different types of messaging patterns in SOAP, but by far the most
common is the Remote Procedure Call (RPC) pattern, in which one network node
(the client) sends a request message to another node (the server), and the server
immediately sends a response message to the client.
 WSDL: Is an XML-based service description on how to communicate using the web
service; namely, the protocol bindings and message formats required to interact with
the web services listed in its directory. The supported operations and messages are
described abstractly, and then bound to a concrete network protocol and message
format. This means that WSDL describes the public interface to the web service.
14.16 Instructor Inputs ¤NIIT
Slide 17
Slide 17 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
Just a minute
Which of the following describes the Web services?
1. WSDL
2. SOAP
3. UDDI
Answer:
1. WSDL
Reiterate the concept by asking the given question.
Slide 18
Slide 18 of 31Session 14

Ver. 1.0
Querying and Managing Data Using SQL Server 2005
Just a minute
Which of the following helps in finding a Web service?
1. WSDL
2. SOAP
3. UDDI
Answer:
3. UDDI
Reiterate the concept by asking the given question.
¤NIIT Instructor Inputs 14.17
Slide 19
Slide 19 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
HTTP Endpoint:
Is the gateway through which HTTP-based clients can query
the database server
Created for use with SQL Server 2005 can listen and receive
requests on the TCP port (port 80)
Identifying the Role of HTTP Endpoints in Native Web Service Architecture
In this topic, you need to explain the concept of HTTP Endpoints to the students. To
explain the concept of the Web services, you may refer to the examples provided in the
Student Guide.
SQL Server allows the database developers to create and host native Web services inside
SQL Server only.
Slide 20
Slide 20 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005

Identifying the Role of HTTP Endpoints in Native Web Service Architecture (Contd.)
HTTP Endpoint Architecture:
14.18 Instructor Inputs ¤NIIT
In this topic, you need to explain the execution of a native Web service to the students.
Explain to the students that if SQL Server is running of Windows 2003 Server, SP1 they
need not to have an additional Web Server to host the web service created using SQL
Server.
The reason why you need not have a Web server is that Windows 2003 server architecture
has a separate HTTP listener with it. This listener is hosted in http.sys file and listens for
any http requests made over the network.
Slide 21
Slide 21 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
Just a minute
On which of the following ports does the SQL Server listen
for HTTP requests?
1. 80
2. 90
3. 70
Answer:
1. 80
Reiterate the learning by asking the given question.
¤NIIT Instructor Inputs 14.19
Slide 22
Slide 22 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
Involves the following tasks:
1. Creating the required database code to access the data.

2. Creating an HTTP Endpoint using the CREATE ENDPOINT
statement.
Creating HTTP Endpoints
In this topic, you need to explain the process of creating an HTTP Endpoint to the
students. Tell them that firstly they need to create a required code in the form of one or
more stored procedures or functions. While creating the endpoint, you will refer to the
code written. This code will further be converted into a Web method and the data returned
by the code will be converted into XML. In addition, the SQL Server will also write the
WSDL document for the Web service.
Slide 23
Slide 23 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
Syntax:
CREATE ENDPOINT endpoint_name
STATE = { STARTED | STOPPED | DISABLED }
AS HTTP (
AUTHENTICATION =( { BASIC | DIGEST |
INTEGRATED | NTLM | KERBEROS },
PATH = 'url', PORTS = (CLEAR) )
FOR SOAP(
[ { WEBMETHOD [ 'namespace' .] 'method_alias'
( NAME = 'database.owner.name'
[ , SCHEMA = { NONE | STANDARD | DEFAULT } ]
[ , FORMAT = { ALL_RESULTS | ROWSETS_ONLY } ])
} [ , n ] ]
[ BATCHES = { ENABLED | DISABLED } ]
[ , WSDL = { NONE | DEFAULT | 'sp_name' } ]
Let’s see how…
Creating HTTP Endpoints (Contd.)

14.20 Instructor Inputs ¤NIIT
In this topic, you need to explain the syntax of CREATE ENDPOINT to the students. To
clarify this, you can refer to the example provided in the Student Guide.
Slide 24
Slide 24 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
Just a minute
While creating an HTTP Endpoint, which of the following
format will you use to return only the result set to the user?
1. ROWSET_ONLY
2. ALL_RESULT
3. NONE
Answer:
1. ROWSET_ONLY
Reiterate the concept taught by asking the given question.
Slide 25
Slide 25 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
Problem Statement:
The database server of AdventureWorks, Inc. is located at
Bothell. The organization has various offices located at various
locations spread across the globe.
According to the requirements, the users need to access the
data of all the employees at various locations. Users might
need to use PDAs or mobile phones to access these details.
As a database developer, you have decided to implement a
Web service that allows the users to access the data using the
Internet.

How will you implement this service inside the AdventureWorks
database?
Demo: Implementing HTTP Endpoints
By the end of this demo, the students will be able to create an HTTP Endpoint.
¤NIIT Instructor Inputs 14.21
Note
Slide 26
Slide 26 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
Solution:
To solve the preceding problem, you need to perform the
following tasks:
1. Create a procedure.
2. Create an HTTP Endpoint for SOAP.
3. Verify the creation of HTTP endpoint. `
Demo: Implementing HTTP Endpoints (Contd.)
During this activity, you can verify the creation of the HTTP endpoint in the following
two ways:
 Open the Web service node for the database in the Object Explorer
 To give a real life experience to the students, you can copy the client.exe data file
from the Datafiles_for_faculty\QMDS2005\Chapter 10 folder in the TIRM CD to the
database server. Execute the .exe file. The .exe file will open an interface of a user
application. The form contains a button. When the user clicks on this button, the
application calls a Web method of the Web service and displays a result set.
Ensure that you copy the client application to the database server in the server room. If
you will copy the application on the client node in the CR, the application will not be
able to connect. You will need to use Remote Desktop on the remote server to show the
execution of the application.
You can tell the students that our focus is not on learning how to code the connectivity

between client and application. Therefore, you are showing them a precompiled
application.
14.22 Instructor Inputs ¤NIIT
Slide 27
Slide 27 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
In this session, you learned that:
The database objects created in any of the .NET supported
languages are called managed database objects.
CLR integration provides the following benefits:
Better programming model
Common development environment
Ability to define data types
T-SQL can be used to perform data access and manipulation
operations that can be implemented using the programming
constructs provided by T-SQL.
Summary
Summarize the session.
Slide 28
Slide 28 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
Managed database objects can be used in the following
situations:
To implement complicated programming logic for which you can
reuse the functionality provided by the .NET base class libraries.
To access external resources, such as calling a Web service or
accessing the file system.
To implement a CPU-intensive functionality that can run more

efficiently as compared to the managed code.
By default, the SQL Server does not allow running managed
code on the server.
Before creating a managed database object in your database,
the CLR integration feature should be enabled in the database
using the sp_configure stored procedure.
The .NET code that is used to create the managed database
objects is compiled in .NET assemblies, .dll or .exe files.
To create a managed database object, first first the.NET
assemblies are imported in the database engine.
Summary (Contd.)
¤NIIT Instructor Inputs 14.23
Slide 29
Slide 29 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
The assemblies in the database engine can be given any of
the following three permissions:
SAFE
EXTERNAL_ACCESS
UNSAFE
Managed stored procedure can be created using the CREATE
PROCEDURE command.
Managed function can be created using the CREATE
FUNCTION command.
Managed trigger can be created using the CREATE TRIGGER
command.
Managed data type can be created using the CREATE TYPE
command.
A Web service is the piece of code that is exposed over the

Internet.
Summary (Contd.)
Slide 30
Slide 30 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
Web services have following advantages:
Interoperability
Multilanguage support
Reusing existing applications
SOAP is a standard communication protocol to interchange
information in a structured format in a distributed environment.
WSDL is a markup language that describes a Web service.
UDDI provides a standard mechanism to register and discover
a Web service.
HTTP endpoints allow you to create and use Web services
within the SQL Server.
Before creating an HTTP endpoint, you need to first create
stored procedures or functions that form a Web service.
Summary (Contd.)
14.24 Instructor Inputs ¤NIIT
Slide 31
Slide 31 of 31Session 14
Ver. 1.0
Querying and Managing Data Using SQL Server 2005
HTTP endpoints provide the users with a connecting point
through which they can access the implemented functions.
You can create HTTP endpoints by using the CREATE
ENDPOINT statement.
Summary (Contd.)

¤NIIT Instructor Inputs 14.25
1. What is a service?
Ans: A service is a function that is well-defined, self-contained, and does not depend on
the context or state of other services.
2. In which kind of scenarios Web services can be implemented?
Ans: Web services can be implemented in the following scenarios:
 Any Web service application built on heterogeneous environment can access an
instance of SQL Server
 Native Web services in SQL Server enables access to an instance of SQL Server
anywhere at any time. This makes it easier to develop applications for mobile or
intermittently connected devices.
FAQs

×