강성재 Developer Evangelist Microsoft Korea D&PE 개발자 관점에서 바라본 SQL Server 2005 (2)

Slides:



Advertisements
Similar presentations
Intro to Sql Server Yukon for Developers Wallace B. McClure Scalable Development, Inc. Building systems today that perform tomorrow.
Advertisements

17. Data Access ADO.Net Architecture New Features of ADO.NET
Optimizing database access and diving into .Net SqlClient
강성재 Developer Evangelist Microsoft Korea D&PE 개발자 관점에서 바라본 SQL Server 2005 (1)
Introduction to Database Processing with ADO.NET.
ADO. NET. What is “ADO.Net”? ADO.Net is a new object model for dealing with databases in.Net. Although some of the concepts are similar to the classical.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Objective In this session we will discuss about : What is ADO. NET ?
In C# program Before you can start using the ODBC class definitions, you will need to include the right module. using System.Data.Odbc; // ODBC definitions.
C# programming with database Basic guideline. First step Install SQL Server 2008/2010 (Professional edition if possible) Install Visual Studio 2008/2010.
ADO.NET Tips and Tricks How to get the most out of your data access…
Programming the CLR in SQL Server 2005 Mark Blomsma Develop-One Session Code: DB.08.
ADO.NET – part II August 2004 [ Marmagna Desai]. CONTENTS ADO vs ADO.NET ADO.NET – Managed providers Connecting to Database SqlConnection Selecting Database.
An Introduction To CLR Integration in SQL Server 2005 (Yukon) Dr Greg Low.
SQL Server 2005 The Common Language Runtime (CLR) Integration Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP Web Development.
CNUG Day of.NET: October 30th SQL Server 2005: A Developers Introduction Shawn Wildermuth Magenic Technologies, Inc.
Native Support for Web Services  Native Web services access  Enables cross platform interoperability  Reduces middle-tier dependency (no IIS)  Simplifies.
SOAP 실전예제 Internet Computing KUT Youn-Hee Han.
ADO.NET A2 Teacher Up skilling LECTURE 3. What’s to come today? ADO.NET What is ADO.NET? ADO.NET Objects SqlConnection SqlCommand SqlDataReader DataSet.
1 UCN Technology: Computer Science: Autumn 2012 ADO.NET 2.0 Architecture DataReader DataSet Connection factory Config file.
Intro to C#.net and EF Ilan Shimshoni. The Three Faces of ADO.NET The connected layer – Directly connecting to the DB The disconnected layer – Using datasets.
J2EE Overview.
FEN Data connection DataReader DataSet Bonus info: Concurrency and Database Transactions Embedded SQL.
CIS 451: Using ASP.NET Objects with SQL Dr. Ralph D. Westfall February, 2009.
Chapter 06 데이터베이스 연동 지원 작성자 : 장은호 소속팀 : 네이버메인개발 작성년월일 :
SQL Server 에디션 비교 한국마이크로소프트 한국마이크로소프트
ADO.Net CS795. What is ADO.Net? Database language spoken by managed applications ADO.net database accesses go through modules: data providers –SQL Server.Net.
.NET Data Access and Manipulation ADO.NET. Overview What is ADO.NET? Disconnected vs. connected data access models ADO.NET Architecture ADO.NET Core Objects.
.Net and Web Services Security CS795. Web Services A web application Does not have a user interface (as a traditional web application); instead, it exposes.
Lập trình SQL Server với.Net Vu Tuyet Trinh Hanoi University of Technology 1.
SQL Server 2005: The CLR Integration What Developers and DBAs need to know.
11 Using ADO.NET II Textbook Chapter Getting Started Last class we started a simple example of using ADO.NET operations to access the Addresses.
Copyright ©2004 Virtusa Corporation | CONFIDENTIAL ADO.Net Basics Ruwan Wijesinghe Trainer.
TOP10 DEV SKILLS TO MAKE YOUR DBA HAPPY Kevin Kline Director of Engineering Services, SQL Sentry SQL Server MVP since 2004 Twitter, FB, LI: KEKline Blog:
Module 7: Accessing Data by Using ADO.NET
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Introduction to ADO.NET ADO.NET - Lesson 01  Training time: 10 minutes  Author:
An Introduction to ADO.Net Marmagna Desai.NET Seminar, Fall-2003.
ADO.NET Tips and Tricks How to get the most out of your data access…
1 Relational Database Implementation of a Multi- dimensional database 컴퓨터언어연구실 석사 3 학기 김혜진 U.S. Patent Number: 5,926,818 Date of Patent: Jul.20,1999 inventor:
Module 3: Performing Connected Database Operations.
ADO.NET Objects – Data Providers Dr. Ron Eaglin. Requirements Visual Studio 2005 Microsoft SQL Server 2000 or 2005 –Adventure Works Database Installed.
1.NET Language Integrated Query Yishai Zaltzberg.
1 11/10/05CS360 Windows Programming ADO.NET. 2 11/10/05CS360 Windows Programming ADO.NET  Behind every great application is a database manager o Amazon.
Why ADO.NET Not your father’s Data Access.
1 Avoiding Hacker Attacks. 2 Objectives You will be able to Avoid certain hacker attacks and crashes due to bad inputs from users.
Building Data-Centric Smart Client Applications Rajiv Sodhi Microsoft India.
Why ADO.NET Not your father’s Data Access.
ADO.Net CS795. What is ADO.Net? Database language spoken by managed applications ADO.net database accesses go through modules: data providers –SQL Server.Net.
HNDIT Rapid Application Development
Learningcomputer.com SQL Server 2008 –Views, Functions and Stored Procedures.
C# .NET Software Development
방명록 제작. 목차  기본 레이아웃  DB 구조  방명록 구조  코드 설명  화면 설명.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 The SqlCommand Object ADO.NET - Lesson 03  Training time: 15 minutes  Author:
SQL Server 2005:.NET Framework Programming in the Database Tim Sneath Architectural Engineer, Microsoft
.NET Data Access and Manipulation
ELASTIC DATABASE CAPABILITIES WITH AZURE SQL DB Silvia Doomra Azure SQL DB Program Management.
 ADO.NET is an object-oriented set of libraries that allows you to interact with data sources  Commonly, the data source is a database, but it could.
ASP.NET Programming with C# and SQL Server First Edition
Data Access with ADO.NET
Introduction to ADO.NET
Introduction to Database Processing with ADO.NET
Introduction to Database Processing with ADO.NET
How to Create Login Form using vb.net and SqlServer Database
SQL commands from C# and ASP.net
An Introduction to Entity Framework
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Module 10: Implementing Managed Code in the Database
M S COLLEGE OF ART’S, COMM., SCI. & BMS Advance Web Programming
Introduction to Database Programming through ADO. NET
Presentation transcript:

강성재 Developer Evangelist Microsoft Korea D&PE 개발자 관점에서 바라본 SQL Server 2005 (2)

목차 SQL CLR 클라이언트 새로운 기능 SQL 관리 객체 (SMO : SQL Management Objects)

1. SQL CLR Managed Code vs. Transact-SQL 기존 어셈블리 가져오기 Managed Code 를 사용해서 데이터베이스 객체 생성 Managed Code 구현

Managed Code vs. Transact-SQL managed code 사용 : – 복잡한 기능의 프로시저 –.NET Framework 클래스 라이브러리 접근 –CPU 집중적 기능 Transact-SQL 은 기본적인 프로시저의 데이터 접근에 사용

기존 어셈블리 가져오기 어셈블리에 데이터베이스 객체 이름 결정 1 1 어셈블리 참조 2 2 보안 권한 결정 3 3 CREATE ASSEMBLY HelperLibrary FROM '\\Server1\Private\AProject\bin\HelperLibrary.dll' WITH PERMISSION_SET SAFE -- default value CREATE ASSEMBLY Contacts FROM 'C:\AProject\bin\Contacts.dll' WITH PERMISSION_SET EXTERNAL_ACCESS CREATE ASSEMBLY HelperLibrary FROM '\\Server1\Private\AProject\bin\HelperLibrary.dll' WITH PERMISSION_SET SAFE -- default value CREATE ASSEMBLY Contacts FROM 'C:\AProject\bin\Contacts.dll' WITH PERMISSION_SET EXTERNAL_ACCESS

Managed Code 를 사용해서 데이터베이스 객체 생성 적절한 CREATE 문 사용 1 1 어셈블리와 연결 2 2 데이터 베이스 객체 사용 3 3 CREATE PROCEDURE Person.UpdatePhoneList AS EXTERNAL NAME Contacts. PhoneList.SaveList GO EXEC Person.UpdatePhoneList CREATE PROCEDURE Person.UpdatePhoneList AS EXTERNAL NAME Contacts. PhoneList.SaveList GO EXEC Person.UpdatePhoneList

기존 어셈블리 가져오기 데모 데모

Managed Code 구현 Visual Studio 2005 내에 SQL Server Projects System.Data.SqlServer 네임스페이스 Managed 저장 프로시저 Managed 트리거 Managed 사용자 정의 함수 Managed Aggregates Managed 사용자 정의 데이터 타입

managed 데이터베이스 객체 생성 프로젝트 필요한 참조 포함 –sqlaccess.dll –System.Data.dll 각 객체 타입에 대한 템플릿 포함 배포와 디버깅 직접 지원 Visual Studio 2005 내에 SQL Server Projects

System.Data.SqlServer 네임스페이스 ClassDescription SqlContextProvides access to other objects, like a connection SqlConnectionAn open connection to a SQL Server database SqlCommandUsed to send a command to the database server SqlParameterSupplies a parameter for a SqlCommand object SqlPipeUsed to send results or information to the client SqlDataReaderReads the data one row at a time, forward only SqlResultSetFor working with flexible server-side cursors SqlTransactionFor providing transactional behavior SqlTriggerContextProvides information about the trigger action

Managed 저장 프로시저 클래스에 public static method 생성 1 1 배포를 위해 SqlProcedure attribute 추가 2 2 managed 저장 프로시저 로직추가 3 3 public class ContactCode { [SqlProcedure(Name="GetContactNames")] public static void GetContactNames() { SqlCommand cmd = SqlContext.GetCommand(); cmd.CommandText = "SELECT FirstName + ' ' + LastName" + " AS [Name] FROM Person.Contact"; SqlDataReader rdr = cmd.ExecuteReader(); SqlPipe sp = SqlContext.GetPipe(); sp.Send(rdr); }

Managed 트리거 클래스에 public static method 생성 1 1 배포를 위해 SqlTrigger attribute 추가 2 2 managed trigger 로직 추가 3 3 public class ContactCode { [SqlTrigger(Name="ContactUpdTrg", Target="Person.Contact", Event="FOR UPDATE")] public static void Change () { SqlTriggerContext trg = SqlContext.GetTriggerContext(); if (trg.TriggerAction == TriggerAction.Update) { if (trg.ColumnsUpdated[7] == true) //send to each new contact }

Managed 사용자 정의 함수 클래스에 public static method 생성 1 1 SqlFunction attribute 추가 2 2 managed function 구현 3 3 public class MyFunctions { [SqlFunction(Name="GetLongDate" )] public static SqlString GetLongDate(SqlDateTime DateVal) { // Return the date as a long string return DateVal.Value.ToLongDateString(); } public class MyFunctions { [SqlFunction(Name="GetLongDate" )] public static SqlString GetLongDate(SqlDateTime DateVal) { // Return the date as a long string return DateVal.Value.ToLongDateString(); }

Managed Aggregates public class 생성 1 1 Serializable 과 SqlUserDefinedAggregate attributes 추가 2 2 Init, Accumulate, Merge, and Terminate methods 생성 3 3 [Serializable, SqlUserDefinedAggregate(…)] public class CommaDelimit { public void Init() {…} public void Accumulate(SqlString Value) {…} public void Merge(CommaDelimit Group) {…} public SqlString Terminate() {…} } [Serializable, SqlUserDefinedAggregate(…)] public class CommaDelimit { public void Init() {…} public void Accumulate(SqlString Value) {…} public void Merge(CommaDelimit Group) {…} public SqlString Terminate() {…} }

Managed 사용자 정의 데이터 타입 public class 또는 struct 생성 1 1 Serializable 과 SqlUserDefinedType attributes 추가 2 2 Handle NULLability 3 3 문자열 변환 지원 4 4 Provide public properties 에서 private data 접근 지원 5 5

Visual Studio 2005 데이터베이스 객체 배포 managed code 생성 시 attributes 사용 1 1 Deploy 옵션 사용 2 2 [SqlProcedure(Name="ProcName")] public static void Proc ( )

Implementing Managed Code (VS.NET 2005) 데모 데모

2. 클라이언트 새로운 기능 Multiple Active Result sets (MARS) System.Transactions

MARS SQL Server 2005 이전 버전 까지, SQL Server 는 다중 연결을 지원하지 않았다 – 커낵션은 단일 DataReader 지원 – 다중 서버 커서와 함께 작업 가능 Multiple Active Result Sets 는 다중 연결 지원 – 다중 스트림과 다중 트랜잭션

MARS

기존 방식 SqlConnection conn = new SqlConnection( "server=.;integrated security=sspi;database=pubs"); SqlCommand cmd = new SqlCommand( "select * from authors",conn); conn.Open(); SqlDataReader rdr = cmd.ExecuteReader(); Console.WriteLine("got first reader"); // second reader, same connection – This will not work cmd.CommandText = "select * from jobs"; SqlDataReader rdr2 = cmd.ExecuteReader(); // attempt to use both readers, but never get to here rdr.Read(); rdr2.Read(); Console.WriteLine(rdr2[0]);

MARS 방식 // MARS is the default with SQL Server 2005 DB SqlConnection conn = new SqlConnection( "server=zmv43;integrated security=sspi;database=pubs"); SqlCommand cmd = new SqlCommand("select * from authors",conn); // must use a separate SqlCommand instance SqlCommand cmd2 = new SqlCommand("select * from jobs",conn); conn.Open(); SqlDataReader rdr = cmd.ExecuteReader(); // second reader, same connection - THIS DOES WORK SqlDataReader rdr2 = cmd2.ExecuteReader(); rdr2.Read(); rdr.Read(); // both readers on same connection Console.WriteLine(rdr[0]); Console.WriteLine(rdr2[0]);

System.Transactions System.Transactions 는 가벼운 DTC 엑세스 지원 API – 단순한 분산 트랜잭션 기능 지원 – 엔터프라이즈 서비스와 유사하지만, 카탈로그를 필요로 하지 않는다 transaction 범위 – 하나의 DBMS 와 인스턴스 사용 시 로컬 트랜잭션 – 하나 이상의 데이터베이스 사용 시 분산 트랜잭션 –transaction 승격 가능 Local 에서 시작 분산 트랜잭션으로만 가능 SQL Server 2005 만 가능

TransactionScope 사용 using (TransactionScope ts = new TransactionScope()) { SqlConnection conn1 = new SqlConnection( "server=.;integrated security=sspi;database=pubs")) // start local tx if SQL 2005, distributed tx if not conn1.Open(); SqlCommand cmd1 = new SqlCommand( "INSERT jobs 'job1', 10, 10", conn1); cmd1.ExecuteNonQuery(); SqlConnection conn2 = new SqlConnection( "server=other;integrated security=sspi;database=pubs")) // promote to distributed tx if SQL 2005 conn2.Open(); SqlCommand cmd2 = new SqlCommand( "INSERT jobs 'job2', 10, 10", conn2); cmd2.ExecuteNonQuery(); ts.Consistent = true; // commit transaction // dispose SqlCommands and SqlConnections here }

3. SQL 관리 객체 (SMO : SQL Management Objects) SQL Server 7, 2000, 과 2005 에 대해 프로그램에 입각한 관리 제공.NET 어셈블리 내부 클래스로 구현 가능 Distributed Management Objects (DMO) 대체 기능 : – 초기화 최적화 – 캡춰 실행 –WMI 기능 – 스크립팅 – 서버 옵션 구성

클래스 구조도 SQL 관리 객체 모델 Server Database Tables Table Columns Column … Schemas StoredProced ures Views … … Databases 유틸리티 클래스 –Backup, Restore, Scripter, Transfer

SQL 관리 객체 참조.NET 클라이언트 애플리케이션 생성 1 1 SQL SMO 어셈블리 참조 2 2 Imports 또는 using 문 사용 3 3 Imports Microsoft.SqlServer.Management.Smo Imports Microsoft.SqlServer.Management.Common Imports Microsoft.SqlServer.Management.Smo Imports Microsoft.SqlServer.Management.Common

SMO 를 사용해서 객체 생성 객체 변수 생성 및 초기화 1 1 적합한 properties 셋 2 2 Create method 호출로 server 업데이트 3 3 Dim AWDBase As Database = Svr.Databases("AdventureWorks") Dim DiscountsTable As New Table(AWDBase, "Sales.Discounts") Dim DiscountID As New Column(DiscountsTable, _ "DiscountID", DataType.Int) Dim DiscountName As New Column(DiscountsTable, _ "DiscountName", DataType.NVarChar(40)) DiscountID.Identity = True DiscountsTable.Columns.Add(DiscountID) DiscountsTable.Columns.Add(DiscountName) DiscountsTable.Create() Dim AWDBase As Database = Svr.Databases("AdventureWorks") Dim DiscountsTable As New Table(AWDBase, "Sales.Discounts") Dim DiscountID As New Column(DiscountsTable, _ "DiscountID", DataType.Int) Dim DiscountName As New Column(DiscountsTable, _ "DiscountName", DataType.NVarChar(40)) DiscountID.Identity = True DiscountsTable.Columns.Add(DiscountID) DiscountsTable.Columns.Add(DiscountName) DiscountsTable.Create()

추천서적 : Microsoft Press IT 전문가를 위한 고급 정보 최신 기술서적에 대한 정보는 여기서 참조하세요.

이 서적은 국내 대형서점에서 판매되며, 온라인 서점에서도 판매 됩니다. 추천서적 : IT 전문가를 위한 참고서적