Presentation is loading. Please wait.

Presentation is loading. Please wait.

In this session, you will learn to: Understand managed code Create managed database objects Define the Hypertext Transfer Protocol endpoints Implement.

Similar presentations


Presentation on theme: "In this session, you will learn to: Understand managed code Create managed database objects Define the Hypertext Transfer Protocol endpoints Implement."— Presentation transcript:

1 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

2 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

3 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

4 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

5 Assemblies: Are created to attach the managed code Are created using the CREATE ASSEMBLY command Syntax: CREATE ASSEMBLY assembly_name FROM { | [,...n ] } [ WITH PERMISSION_SET = { SAFE | EXTERNAL_ACCESS | UNSAFE } ] Let’s see how… Importing and Configuring Assemblies

6 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

7 Managed database objects can be of the following types: Stored Procedures Functions Triggers UDTs Creating Managed Database Objects

8 Managed stored procedure: Is implemented by creating a procedure that refers to an imported assembly Syntax: CREATE PROCEDURE AS EXTERNAL NAME.., Let’s see how… Creating Managed Database Objects (Contd.)

9 Managed function: Is implemented by creating a function that refers to an imported assembly Syntax: CREATE FUNCTION ( ) RETURNS AS EXTERNAL NAME.<Type Name>. Let’s see how… Creating Managed Database Objects (Contd.)

10 Managed trigger: Is implemented by creating a trigger that refers to an imported assembly Syntax: CREATE TRIGGER ON AS EXTERNAL NAME.. Let’s see how… Creating Managed Database Objects (Contd.)

11 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.)

12 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.

13 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: ; Spouse 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

14 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.)

15 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)

16 Flash presentation: Introduction to Web ServicesIntroduction 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

17 Just a minute Which of the following describes the Web services? 1.WSDL 2.SOAP 3.UDDI Answer: 1.WSDL

18 Just a minute Which of the following helps in finding a Web service? 1.WSDL 2.SOAP 3.UDDI Answer: 3.UDDI

19 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

20 Identifying the Role of HTTP Endpoints in Native Web Service Architecture (Contd.) HTTP Endpoint Architecture:

21 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

22 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

23 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.)

24 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

25 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

26 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.)

27 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

28 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.)

29 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.)

30 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.)

31 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.)


Download ppt "In this session, you will learn to: Understand managed code Create managed database objects Define the Hypertext Transfer Protocol endpoints Implement."

Similar presentations


Ads by Google