1. Trang chủ
  2. » Công Nghệ Thông Tin

Microsoft SQL Server 2005 Developer’s Guide- P14 ppt

10 167 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Cấu trúc

  • Contents

  • Acknowledgments

  • Introduction

  • Chapter 1 The Development Environment

    • SQL Server Management Studio

      • The SQL Server Management Studio User Interface

      • SQL Server Management Studio User Interface Windows

      • SQL Server 2005 Administrative Tools

    • BI Development Studio

      • The Business Intelligence Development Studio User Interface

      • BI Development Studio User Interface Windows

    • Summary

  • Chapter 2 Developing with T-SQL

    • T-SQL Development Tools

      • SQL Server Management Studio

      • Visual Studio 2005

    • Creating Database Objects Using T-SQL DDL

      • Databases

      • Tables

      • Views

      • Synonyms

      • Stored Procedures

      • Functions

      • Triggers

      • Security

      • Storage for Searching

    • Querying and Updating with T-SQL DML

      • Select and Joins

      • Modifying Data

      • Error Handling

    • Summary

  • Chapter 3 Developing CLR Database Objects

    • Understanding CLR and SQL Server 2005 Database Engine

      • CLR Architecture

      • Enabling CLR Support

      • CLR Database Object Components

    • Creating CLR Database Objects

      • CLR Stored Procedures

      • User-Defined Functions

      • Triggers

      • User-Defined Types

      • Aggregates

    • Debugging CLR Database Objects

      • .NET Database Object Security

      • Managing CLR Database Objects

    • Summary

  • Chapter 4 SQL Server Service Broker

    • SQL Server Service Broker Architecture

      • Messages

      • Queues

      • Contracts

      • Services

      • Dialogs

    • Developing SQL Service Broker Applications

      • SQL Server Service Broker DDL and DML

      • T-SQL DDL

      • T-SQL DML

      • Enabling SQL Server Broker

      • Using Queues

      • Sample SQL Server Service Broker Application

    • SQL Server Service Broker Activation

    • Dialog Security

    • System Views

    • Summary

  • Chapter 5 Developing with Notification Services

    • Notification Services Overview

      • Events

      • Subscriptions

      • Notifications

    • Developing Notification Services Applications

      • Defining the Application

      • Compiling the Application

      • Building the Notification Subscription Management Application

      • Adding Custom Components

    • Notification Services Application Sample

      • Creating the ICF File

      • Defining the ADF File

      • Building the Notification Services Application

    • Updating Notification Services Applications

    • Building a .NET Subscription/Event Application

      • Listing Subscriptions

      • Adding Subscriptions

      • Deleting Subscriptions

      • Firing the Data Event Using .NET

      • Firing the Data Event Using T-SQL

    • Summary

  • Chapter 6 Developing Database Applications with ADO.NET

    • The ADO.NET Architecture

    • ADO.NET Namespaces

    • .NET Data Providers

      • Namespaces for the .NET Data Providers

      • Core Classes for the .NET Data Providers

    • Core Classes in the ADO.NET System.Data Namespace

      • DataSet

      • DataTable

      • DataColumn

      • DataRow

      • DataView

      • DataViewManager

      • DataRelation

      • Constraint

      • ForeignKeyConstraint

      • UniqueConstraint

      • DataException

    • Using the .NET Framework Data Provider for SQL Server

      • Adding the System.Data.SqlClient Namespace

    • Using the SqlConnection Object

      • The .NET Framework Data Provider for SQL Server Connection String Keywords

      • Opening a Trusted Connection

      • Using Connection Pooling

    • Using the SqlCommand Object

      • Executing Dynamic SQL Statements

      • Executing Parameterized SQL Statements

      • Executing Stored Procedures with Return Values

      • Executing Transactions

    • Using the SqlDependency Object

    • Using the SqlDataReader Object

      • Retrieving a Fast Forward–Only Result Set

      • Reading Schema-Only Information

      • Asynchronous Support

      • Multiple Active Result Sets (MARS)

      • Retrieving BLOB Data

    • Using the SqlDataAdapter Object

      • Populating the DataSet

      • Using the CommandBuilder Class

    • Summary

  • Chapter 7 Developing with XML

    • The XML Data Type

      • Data Validation Using an XSD Schema

    • XQuery Support

      • Querying Element Data

    • XML Data Type Methods

      • Exist(XQuery)

      • Modify(XML DML)

      • Query(XQuery)

      • Value(XQuery, [node ref])

    • XML Indexes

      • Primary XML Indexes

      • Secondary XML Indexes

    • Using the For XML Clause

      • For XML Raw

      • For XML Auto

      • For XML Explicit

      • Type Mode

      • FOR XML Path

      • Nested FOR XML Queries

      • Inline XSD Schema Generation

    • OPENXML

    • XML Bulk Load

    • Native HTTP SOAP Access

      • Creating SOAP Endpoints

      • Using SOAP Endpoints

    • Summary

  • Chapter 8 Developing Database Applications with ADO

    • An Overview of OLE DB

    • OLE DB Architecture Overview

    • ADO (ActiveX Data Objects)

    • OLE DB and ADO Files

    • ADO Architecture

      • An Overview of Using ADO

    • Adding the ADO Reference to Visual Basic

    • Using ADO Objects with Visual Basic

      • Connecting to SQL Server

      • Retrieving Data with the ADO Recordset

      • Executing Dynamic SQL with the ADO Connection Object

      • Modifying Data with ADO

      • Executing Stored Procedures with Command Objects

      • Error Handling

    • Advanced Database Functions Using ADO

      • Batch Updates

      • Using Transactions

    • Summary

  • Chapter 9 Reporting Services

    • Reporting Services Architecture

      • Reporting Services Components

      • Installing Reporting Services

    • Report Server

      • Report Server Processors

      • Report Server Extensions

    • Report Manager

    • Reporting Services Configuration and Management Tools

      • Reporting Services Configuration Tool

      • Report Server Command-Prompt Utilities

    • Report Authoring Tools

      • Report Designer

      • Report Model Designer

      • Report Builder

    • Programmability

      • Using URL Access in a Window Form

      • Integrating Reporting Services Using SOAP

      • Extensions

      • RDL

    • Accessing Reports

      • Using URL Access

      • URL Access Through a Form POST Method

    • Report Authoring

      • Development Stages

      • Creating a Reporting Services Report

      • Deploying a Reporting Services Report

      • Running a Reporting Services Report

    • Summary

  • Chapter 10 SQL Server Integration Services

    • An Overview of SQL Server Integration Services

      • Data Transformation Pipeline (DTP)

      • Data Transformation Runtime (DTR)

    • Creating Packages

      • Using the SSIS Import and Export Wizard

      • Using the SSIS Designer

      • Using Breakpoints

      • Using Checkpoints

      • Using Transactions

      • Package Security

    • Deploying Packages

      • Creating Configurations

      • Using the Package Deployment Utility

    • Programming with the SQL Server Integration Services APIs

    • Summary

  • Chapter 11 Developing BI Applications with ADOMD.NET

    • Analysis Services Overview

      • XML for Analysis

      • Analysis Management Objects (AMO) Overview

      • ADOMD.NET Overview

      • AMO Hierarchy

      • ADOMD.NET Object Model

    • Building a BI Application with ADOMD.NET

      • Adding a Reference for ADOMD.NET

      • Using the AdomdConnection Object

      • Using the AdomdCommand Object

      • Using the AdomdDataAdapter Object

      • Using the CubeDef Object

    • Summary

  • Chapter 12 Developing with SMO

    • Using SMO

      • Adding SMO Objects to Visual Studio

      • Creating the Server Object

      • Using SMO Properties

      • SMO Property Collections

    • SMO Hierarchy

    • Building the SMO Sample Application

      • Creating the Server Object

      • Listing the Registered SQL Systems

      • Connecting to the Selected SQL Server System

      • Listing Databases

      • Listing Tables

      • Listing Columns

      • Retrieving Column Attributes

      • Creating Databases

      • Transferring Tables

      • Showing T-SQL Script for Tables

      • SMO Error Handling

    • Summary

  • Chapter 13 Using sqlcmd

    • sqlcmd Components

      • Command Shell

      • Command-Line Parameters

      • sqlcmd Extended Commands

      • sqlcmd Variables

    • Developing sqlcmd Scripts

      • Developing sqlcmd Scripts with Query Editor

      • Using sqlcmd Variables

      • Using sqlcmd Script Nesting

      • Using sqlcmd Variables and T-SQL Statements

    • Summary

  • Appendix: SQL Profiler

    • Starting SQL Profiler

    • Starting, Pausing, and Stopping a Trace

    • Replaying a Trace

    • Showplan Events

  • Index

    • A

    • B

    • C

    • D

    • E

    • F

    • G

    • H

    • I

    • J

    • L

    • M

    • N

    • O

    • P

    • Q

    • R

    • S

    • T

    • U

    • V

    • W

    • X

Nội dung

Chapter 3: Developing CLR Database Objects 109 The Merge method is used when the aggregate is processed in parallel, which typically won’t be the case for most queries. If the Merge is called, its job is to import the current aggregation values from the parallel instance. You can see here that it does that using two helper methods that essentially export the values in the m_HighValue and m_LowValue variables. These values are compared to the existing values, and if they are higher or lower, they will replace the current values in m_HighValue and m_LowValue. The Terminate method is called once after all of the results have been processed. For this example, the Terminate method simply subtracts the lowest value found from the highest value found and returns the difference to the caller. Deploying the Aggregate After compiling the class into a DLL, you can import the DLL as a SQL Server assembly using either the Visual Studio 2005 Deploy option or manually using the CREATE ASSEMBLY statement and CREATE AGGREGATE statement as is shown in the following listing: create assembly MaxVariance from 'C:\temp\MaxVariance.dll' go CREATE AGGREGATE MaxVariance (@maXVar int) RETURNS Int EXTERNAL NAME MaxVariance.[MaxVariance.MaxVariance] go Like the earlier examples, this listing assumes that maxvariance.dll has been copied into the c:\temp directory on the local SQL Server system. In the CREATE AGGREGATE statement and the EXTERNAL NAME clause the first part of the name specifies the assembly that will be used, and the second part of the name identifies the namespace and class. Here all of these values are named MaxVariance. Using the Aggregate You can use the aggregate just like SQL Server’s built-in aggregate functions. One small difference is that the UDAGG needs to be prefixed with the schema name to allow the system to locate it. The following line illustrates using the MaxVariance Aggregate: SELECT dbo.MaxVariance(MinQty) FROM Sales.SpecialOffer 110 Microsoft SQL Server 2005 Developer’s Guide The result of this statement will show the difference between the high and low values found in the Sales.SpecialOffer column as is shown here: 61 (1 row(s) affected) Debugging CLR Database Objects One of the coolest features found in the integration of the .NET Framework, Visual Studio 2005, and SQL Server 2005 is the ability to debug the CLR database objects that you create. This tight level of integration sets SQL Server way ahead of competing database products like Oracle and DB2 that offer the ability to create stored procedures and functions using .NET code. While the other database products provide for the creation of these objects, they do not support the ability to provide integrated debugging. Visual Studio 2005 enables you to set breakpoints in your CLR database objects and then seamlessly step through your code and perform all of the debugging tasks that you would expects for a standard Windows or Web application, including the ability to set breakpoints, single-step through the code, inspect and change variables, and create watches—even between T-SQL and CLR code. Visual Studio 2005 automatically generates test scripts that are added to your projects. You can customize and use these test scripts to execute the CLR database objects that you create. NOTE You must compile and deploy the CLR database object before you can debug it. To debug a SQL Server project using Visual Studio 2005, first open the project that you want to debug and then go to the Servers window and right-click the database connection. From the pop-up menu select the option Allow SQL/CLR Debugging as is shown in Figure 3-13. Next, set up the script that you want to use to run the database object. Using the Solution window, open the Test Scripts folder and then the Test.sql file. You can set up multiple test scripts, but the Test.sql script is provided by default. If you want to change the script that Visual Studio 2005 uses to run the CLR database object, you simply right-click the desired script listed under the Test Scripts folder and select the Set As Default Debug Script option as is shown in Figure 3-14. Chapter 3: Developing CLR Database Objects 111 To use the default Test.sql script, open the file using the Visual Studio editor. Here you can see T-SQL boilerplate code for testing each of the different CLR database object types. Go to the section that you want and edit the code to execute the database object. You can see the test code for the usp_ImportFile stored procedure in the following listing: Examples for queries that exercise different SQL objects implemented by this assembly Stored procedure declare @MyColumn varchar(30) exec usp_ImportFile 'c:\temp\testfile.txt',@MyColumn Select @MyColumn Figure 3-13 Setting the Allow SQL/CLR Debugging option 112 Microsoft SQL Server 2005 Developer’s Guide When the test script is ready to go, use Visual Studio’s Debug | Start option or simply press F5 to launch the Test.sql that will execute your CLR database object. You can see an example of using the Visual Studio 2005 debugger to step through a SQL Server project in Figure 3-15. At this point you can step through the code, set new breakpoints, and change and inspect variables. NOTE Debugging should be performed on a development system, not on a production system. Using the SQLCRL debugger from Visual Studio causes all SQLCLR threads to stop, which prevents other CLR objects from running. .NET Database Object Security No discussion of the new CLR features would be complete without a description of the security issues associated with using .NET assemblies and the SQL Server CLR. Figure 3-14 Setting the default debug script Chapter 3: Developing CLR Database Objects 113 Unlike T-SQL, which doesn’t have any native facilities for referencing resources outside the database, .NET assemblies are fully capable of accessing both system and network resources. Therefore, securing them is an important aspect of their development. With SQL Server 2005, Microsoft has integrated the user-based SQL Server security model with the permissions-based CLR security model. Following the SQL Server security model, users are able to access only database objects— including those created from .NET assemblies—to which they have user rights. The CLR security model extends this by providing control over the types of system resources that can be accessed by .NET code running on the server. CLR security permissions are specified at the time the assembly is created by using the WITH PERMISSION_SET clause of the CREATE ASSEMBLY statement. Table 3-4 summarizes the options for CLR database security permissions that can be applied to SQL Server database objects. Figure 3-15 Debugging Visual Studio 2005 SQL Server projects 114 Microsoft SQL Server 2005 Developer’s Guide Using the SAFE permission restricts all external access. The EXTERNAL_ ACCESS permission enables some external access of resources using managed APIs. SQL Server impersonates the caller in order to access external resources. You must have the new EXTERNAL_ACCESS permission in order to create objects with this permission set. The UNSAFE permission is basically an anything-goes type of permission. All system resources can be accessed, and calls to both managed and unmanaged code are allowed. Only system administrators can create objects with UNSAFE permissions. In addition to using the CREATE ASSEMBLY statement, you can also set the CLR database object permission using the project properties as is shown in Figure 3-16. CRL Security External Access Allowed Calls to Unmanaged Code SAFE No external access No calls to unmanaged code EXTERNAL_ACCESS External access permitted via management APIs No calls to unmanaged code UNSAFE External access allowed Calls to unmanaged code allowed Table 3-4 CLR Database Object Security Options Figure 3-16 Setting the CLR permission Chapter 3: Developing CLR Database Objects 115 To interactively set the CLR permission level, open the project properties by selecting the Project | Properties option from the Visual Studio 2005 menu. Then open the Database tab and click the Permission Level drop-down. The project must be redeployed before the changes will take place. Managing CLR Database Objects As shown in Table 3-5, SQL Server 2005 provides system views that enable you to see the different CLR objects that are being used in the database. Summary Database objects created using the CLR are best suited for objects that replace extended stored procedures, require complex logic, or are potentially transportable between the database and the data tier of an application. They are not as well suited to raw data access and update functions as T-SQL. By taking advantage of CLR database objects, you can add a lot of power and flexibility to your database applications. System View Description sys.objects Contains all database objects. CLR database objects are identified in the typ_desc column. sys.assemblies Contains all of the assemblies in a database. sys.assembly_files Contains all of the filenames that were used to create the assemblies in a database. sys.assembly_types Contains all of the user-defined types that were added to a database. sys.assembly_references Contains all of the assembly references in a database. Table 3-5 System Views to Manage CLR Database Objects This page intentionally left blank 117 CHAPTER 4 SQL Server Service Broker IN THIS CHAPTER SQL Server Service Broker Architecture Developing SQL Service Broker Applications SQL Server Service Broker Activation Dialog Security System Views Copyright © 2006 by The McGraw-Hill Companies. Click here for terms of use. 118 Microsoft SQL Server 2005 Developer’s Guide T he SQL Server Service Broker is a new subsystem that provides a framework for building asynchronous applications using SQL Server 2005. The ability to support asynchronous queuing expands the scalability of SQL Server 2005 applications. Asynchronous queuing is an important factor for scalability because it allows an application to respond to more requests than the platform may be able to physically handle. Asynchronous queuing is found in many other highly scalable applications, such as the operating system’s I/O subsystems, Web servers, and even the internal operations of the SQL Server database engine itself. For instance, in the case of a Web server, if ten thousand users simultaneously requested resources from the server, without asynchronous queuing the Web server would be overwhelmed as it attempted to synchronously handle all of the incoming requests one at a time. Asynchronous queuing enables all of the requests to be captured in a queue. Then instead of being overwhelmed, the Web server can process entries from the queue at its maximum levels of efficiency. The addition of the SQL Server Service Broker to SQL Server 2005 enables you to build this same type of scalability into your database applications. In this chapter you’ll learn how to develop asynchronous applications using the new SQL Server Service Broker. First you’ll get an overview of the new subsystem and learn about its core components. Next, you’ll learn about the new T-SQL Data Definition Language (DDL) and Data Manipulation Language (DML) commands that Microsoft has added to SQL Server 2005 that enable you to create and use SQL Server Service Broker. Then you’ll see how to you create a basic SQL Server Service Broker application. First, you’ll see how to activate the SQL Service Broker subsystem and create all of the objects required by a SQL Server Service Broker application. Then you’ll see how to use the new T-SQL commands to send and receive data using those SQL Server Service Broker objects. SQL Server Service Broker Architecture It’s important to keep in mind that the SQL Server Service Broker is an application framework. Its goal is to take on the hard work of building asynchronous applications, and it does that by handling all of the heavy lifting for the asynchronous application. SQL Server Service Broker takes care of all of the hard-to-code details like guaranteed-in-order message routing and delivery. In other words, SQL Server Service Broker provides the plumbing for an asynchronous application but doesn’t provide the application itself. It is still up to you to build the application that uses the framework supplied by the SQL Server Service broker subsystem. Microsoft has made use of . permissions that can be applied to SQL Server database objects. Figure 3-15 Debugging Visual Studio 2005 SQL Server projects 114 Microsoft SQL Server 2005 Developer’s Guide Using the SAFE permission. use. 118 Microsoft SQL Server 2005 Developer’s Guide T he SQL Server Service Broker is a new subsystem that provides a framework for building asynchronous applications using SQL Server 2005. The. their development. With SQL Server 2005, Microsoft has integrated the user-based SQL Server security model with the permissions-based CLR security model. Following the SQL Server security model,

Ngày đăng: 05/07/2014, 05:20

TỪ KHÓA LIÊN QUAN