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

SQL Server - Bài 8

56 473 0
Tài liệu đã được kiểm tra trùng lặp

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

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 56
Dung lượng 899 KB

Nội dung

SQL Server - Bài

Lập trình SQL Server với .NetVu Tuyet Trinhtrinhvt-fit@mail.hut.edu.vnHanoi University of Technology1 MicrosoftMicrosoftWhat is .NET?An application development platform from MicrosoftRapidly develop secure and robust softwareWeb and WindowsFull support for object-oriented programming MicrosoftMicrosoftAdvantages of .Net FrameworkCLR – Common Language RuntimeGarbage collector, type safety, JIT, …Language integrationC#, VB.net, …Built-in support for open standardsSOAP, …Simple development, simple deploymentSupporting entity data model (ADO.net & entity framework) MicrosoftMicrosoftOutline√.Net Framework ADO.net CLR IntegrationEnabling CLR IntegrationCLT Integration: Pros & Cons MicrosoftMicrosoft.Net FrameworkWebFormsWebServicesADO.NET and XMLBase Framework ClassesCommon Language RuntimeWinForms… MicrosoftMicrosoftDataReaderDataSetDataAdapterADO.NET ArchitectureCommandTransactionConnectionCommandBuilderDisconnectedLayerConnectedLayerDataLayer MicrosoftMicrosoftADO.NET Managed ProviderSystem.data.dll+{System.data}….IDbConnectionIDbCommandIDataReaderIDbTransactionIDbDataAdapter….System.data.dll+{System.data.SqlClient}….SqlConnectionSqlCommandSqlDataReaderSqlTransactionSqlDataAdapterSqlCommandBuilderWarning: There is no IDbCommandBuilder MicrosoftMicrosoftDataReaderFast Forward-Only/Read-Only streams of dataReturned by IDbCommand.ExecuteReader( .)Data is not cached on the client-sideMust be closed explicitlyNot serializableCannot be inherited (sealed class) MicrosoftMicrosoftDataSetIn-memory cache of dataRelational view of dataData source agnosticKeeps track of changesContains an XSD schemaMarshalByValue objectDataSetSchemaRelationTableColumnConstraintRow MicrosoftMicrosoftTypedDataSetWithout TypedDataSetWithout TypedDataSetWith TypedDataSetWith TypedDataSetCode is more readableIntroduces compile-time checkingIntellisense under Visual Studiodataset.Tables[0].Rows[0][1] = 1023;dataset.Tables[“Orders”].Rows[0][“CustomerID"] = 1023;dataset.Orders[0].CustomerID = 1023; [...]... Server, a new Provider    Very similar to SqlClient Provider Follows Managed Provider Model Supports     Microsoft IDbConnection IDbCommand IDbDataReader Etc InProc Managed Provider (2)  Dude, where’s my Connection?  In Out-of-proc ADO.NET: using (SqlConnection conn = new SqlConnection(" ")) using (SqlCommand cmd = conn.CreateCommand()) { try { cmd.CommandText = " "; conn.Open(); using (SqlDataReader... to VS about how to deploy       Microsoft [SqlProcedure] [SqlFunction] [SqlUserDefinedType] [SqlUserDefinedAggregate] … Also used at runtime for behaviors of objects Managed Stored Procedures  To expose a Stored Procedure:    The containing class must be public The exposed method must be public The exposed method must be static public class SqlClr { public static void MyProc() { // Put your... Name>. CREATE FUNCTION Addition ( @x int, @y int ) RETURNS int AS EXTERNAL NAME ExampleYukon.SqlClr.Addition Microsoft Managed Functions (2)  Code is similar to Stored Procedures [SqlFunction] public static int Addition(int x, int y) { return x + y; }  [SqlFunction] Parameters  Helps SQL Server know what the function does     Microsoft IsDeterministic IsPrecise DataAccess SystemDataAccess... Custom Average Example [Serializable] [SqlUserDefinedAggregate(Format.UserDefined, MaxByteSize = 80 00)] public class CustomAverage : IBinarySerialize { SqlDouble _total = 0; ulong _totalCount = 0; public void Init() { } public void Accumulate(SqlDouble Value) { ++_totalCount; if (_total.IsNull) _total = 0; _total += Value; } public void Merge(StdDev grp) {/* */ } public SqlDouble Terminate() { return _total/_totalCount;... Microsoft SqlDataAdapter XML File DB Outline √ √    Net Framework ADO.net CLR Integration Enabling CLR Integration CLT Integration: Pros & Cons Microsoft CLR Integration  Brand new since SQL Server 2005 (Standard and Express)  Write database queries using NET  Supporting Any NET language (C#, VB, C++)  Creating and debugging using VS 2005 IDE Microsoft What can we do with CLR code?  Common T -SQL. .. EXTERNAL NAME AssemlyExample.SqlClr.InputProcedure CREATE PROCEDURE OutputProcedure @number int OUTPUT AS EXTERNAL NAME AssemlyExample.SqlClr.OutputProcedure CREATE PROCEDURE InOutProcedure @number int OUTPUT AS EXTERNAL NAME AssemlyExample.SqlClr.InOutProcedure NOTE: You don’t specify ReturnParameters CREATE PROCEDURE ReturnProcedure AS EXTERNAL NAME AssemlyExample.SqlClr.ReturnProcedure Microsoft... AssemlyExample.SqlClr.AddContact  DDL Triggers CREATE TRIGGER ON AS EXTERNAL NAME .. CREATE TRIGGER AddUser ON DATABASE FOR CreateUser AS EXTERNAL NAME AssemlyExample.SqlClr.AddUser Microsoft TriggerContext ColumnsUpdates to see what columns changed  public static void AddAuthor() { SqlTriggerContext... Type that does the aggregation Use DML command to register CREATE AGGREGATE ( @param ) RETURNS EXTERNAL NAME . CREATE AGGREGATE CustomAverage ( @value float ) RETURNS float EXTERNAL NAME AssemlyExample.CustomAverage Microsoft Custom Aggregates - CLR Class     called during the aggregation Not just passed a set of values, but one at a time... is disposed } finally { conn.Close() } } // using statements ensure Disposed is called Microsoft InProc Managed Provider (3) InProc you can assume the connection  using (SqlCommand cmd = new SqlCommand()) { cmd.CommandText = " "; SqlContext.Pipe.ExecuteAndSend(cmd); } Microsoft ... and the data Scale up/out possibilities of different tiers Abstraction of the database technology Security requirements Set-based versus procedural code Possibilities for using shared code libraries in multiple tiers Microsoft Enabling CLR Integration  Enabled on an instance  SQL Script    Execute sp_configure ‘clr enabled’, ‘1’ Sp_reconfigure Surface Area Configuration (features) Microsoft Assembly . ProviderSystem.data.dll+{System.data}….IDbConnectionIDbCommandIDataReaderIDbTransactionIDbDataAdapter….System.data.dll+{System.data.SqlClient}….SqlConnectionSqlCommandSqlDataReaderSqlTransactionSqlDataAdapterSqlCommandBuilderWarning: There is no. Lập trình SQL Server với .NetVu Tuyet Trinhtrinhvt-fit@mail.hut.edu.vnHanoi University of Technology1 MicrosoftMicrosoftWhat

Ngày đăng: 15/11/2012, 10:59

TỪ KHÓA LIÊN QUAN

w