microsoft.net framework data access ramesh theivendran john powell borland software corporation

56
Microsoft .NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Upload: marion-stephens

Post on 28-Dec-2015

224 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Microsoft .NET Framework Data Access

Ramesh Theivendran

John Powell

Borland Software Corporation

Page 2: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Agenda

Database Connectivity in .NET

Borland Data Provider (BDP)

Resolving .NET DataSet

Data Remoting in .NET

Message Queues

Page 3: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Database Connectivity .NET

Data Access - BDP, SQLClient, OLEDB, ODBC, ODP.NET

Data Manipulation - .NET DataSet

Data Remoting - .NET Remoting- ASP.NET Web Services (Stateless)- Message Queues (Asynchronous)

Page 4: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Data Access

Relational data access• ADO.NET (.NET) • ODBC, OLEDB, ADO, BDE, dbExpress (Win32)• JDBC (Java)

Object data access• ECO, ObjectSpaces (.NET)• BOLD, MTS (Win32)• JDO, EJB (Java)

OLAP, Data Mining• MDX (MultiDimensional Expressions)• DSO (Decision Support Objects)• PivotTable Services• XML/A

Page 5: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

ADO.NET

Disconnected, n-tier data access model with good XML and XSD support.

Core Components:

– .NET DataSet – .NET Data Provider

Page 6: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

DataSnap vs ADO.NET

dbExpress .NET Data Provider

SQLConnection

SQLCommand

SQLCursor

IDbConnection

IDbCommand

IDataReader

Page 7: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

DataSnap vs ADO.NET

DataSnap .NET DataSet

ClientDataset

DataProvider

DataSet

IDbDataAdapter

Better representation of relational dataTighter XML and XSD supportResolving to be handled by the developer XML for data remoting

Page 8: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

DataSet methods

Update()/AcceptChanges()

GetChanges()

RejectChanges()

ReadXml()

ReadXmlSchema()

WriteXml()

WriteXmlSchema()

GetXml()

GetXmlSchema()

Clear()

ApplyUpdates()Delta

CancelUpdates()LoadFromFile()

SaveToFile()Data

XMLDataSetEmptyDataSet()

Page 9: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

.NET Data Provider Architecture

OLEDBManaged

.NET Client

SQL ServerManaged

COM Interop layer

OleDbProvider

RDBMS

DB client

OleDbProvider

BDPManaged

TDS GDS32

MSSQL IB

DOTNET

COM

ORACLE

OCI

Page 10: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

ISQLConnectionISQLCommand

ISQLCursorISQLMetaDataISQLResolver

ISQLSchemaCreateISQLDataSource

DB client wrapper

bdpDatasources.xml

DB

BDP Designers

BDP Components

Data Explorer

bdpConnections.xml

Page 11: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

BDP for .NET

Namespace Borland.Data.Provider– BdpConnection– BdpTransaction– BdpCommand– BdpParameter, BdpParameterCollection– BdpDataReader– BdpDataAdapter– BdpException– BdpError, BdpErrorCollection– BdpCommandBuilder

Page 12: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

BDP for .NET

Namespace Borland.Data.Common– ISQLConnection– ISQLCommand– ISQLCusor– BdpType

Namespace Borland.Data.Schema– ISQLDataSource– ISQLMetaData – ISQLResolver– ISQLSchemaCreate

Namespace Borland.Data.Design

Page 13: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

BdpConnection

Implements IDbConnectionDelegates to ISQLConnection implementationProperties:

ConnectionStringConnectionOptionsState

Methods:Open(),Close()CreateCommand()BeginTransaction()ChangeDatabase()GetMetaData(), GetResolver()

Page 14: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

BdpCommand

Implements IDbCommandDelegates to ISQLCommand implementationProperties:

ConnectionCommandTypeCommandTextParameters, ParameterCountTransactionCommandOptions

Methods:Prepare(), ExecuteNonQuery(), ExecuteReader(), ExecuteScalar(), Close()

Page 15: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

BdpDataReaderImplements IDataReader, IDataRecordDelegates to ISQLCursor ImplementationProperties:

IsClosedRecordsAffectedFieldCountDepth

Methods:Read(), NextResult()

GetShemaTable(),GetName(), GetFieldType(), GetDataTypeName(), GetOrdinal(), GetDataType(), GetDataSubType()IsDBNull(), GetValues(), GetInt16(), GetInt32()….Close()

Page 16: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

BdpTransaction

Implements IDbTransaction

Delegates to ISQLConnection implementation

Properties:

Connection

IsolationLevel

Methods:

Commit()

Rollback()

Page 17: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Sample code

// Create a new Connection

BdpConnection Conn = new BdpConnection();

String ConnStr = " provider=Interbase; assembly=Borland.Data.Interbase, Version=2.0.0.0, Culture=neutral, PublicKeyToken=91d62ebb5b0d1b1b; database=c:\\IB71\\examples\\database\\employee.gdb; username=sysdba;password=masterkey";

Conn.ConnectionString = ConnStr;

//Establish connection to the database

Conn.Open();

BdpTransaction Trans = Conn.BeginTransaction();

BdpCommand Comm = Conn.CreateCommand();

Comm.Connection = Conn;

Comm.Transaction = Trans;

Comm.CommandText = " SELECT * FROM ADDRESSBOOK";

BdpDataReader Reader = Comm.ExecuteReader();

Page 18: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Sample code

if ( Reader != null ) { for (Int32 index = 0; index < Reader.FieldCount; index++) Console.WriteLine("Column Name = " + Reader.GetName(index)); while (Reader.Read()) { for (Int32 index = 0; index < Reader.FieldCount; index++) { //Assuming CHAR or VARCHAR columns Console.WriteLine(Reader.GetString(index)); } } Reader.Close(); } Trans.Commit(); Command.Close(); Conn.Close();

Page 19: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

BdpParameterBdpParameter: Implements IDbDataParameter,

IDataParameter

Properties:

ParameterName

DbType

BdpType

BdpSubType

Direction

Value

Precision, Scale, MaxPrecision

Page 20: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Demos

1. Retrieving data using BdpDataReader

2. Inserting records using runtime Parameter binding

Page 21: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

BdpDataAdapter

Extends DbDataAdapter and Implements IDbDataAdapterProperties:

SelectCommand, DeleteCommand, InsertCommand, UpdateCommandDataSetActiveStartRecordMaxRecordsTableMappings

Methods:Fill(), FillSchema()Update(), AutoUpdate()GetFillParameters()

Page 22: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

BdpCommandBuilder

Properties:

DataAdapter

QuotePrefix

QuoteSuffix

ReadOnly

ExcludeFilter

Methods:

GetInsertCommand()

GetDeleteCommand()

GetUpdateCommand()

RefreshSchema()

Page 23: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Demos

3. Provide and resolve data using BdpDataAdapter

4. SQL Generation using the BdpCommandBuilder

5. Calling Stored Procedures

6. Blob access

7. BDP and dbWeb

Page 24: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

MetaData Services

MetaData retrieval

Schema CreationCreate Table,View,Indices

Alter Table

Drop Table, View, Indices

Data MigrationBdpCopyTable component

SourceCommand

Destination

DestinationTable

Page 25: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Why BDP.NET

Open Architecture: Lets you add support to more DB’s easily

Portable code : Write ones and connect to all DB’s

Logical Data types mapped to .NET Native types

Consistent data type mapping across DB’s

Unlike OLEDB .NET Provider need not go through a COM interop layer.

Support for Database specific features

Supports metadata, schema creation and data migration services

Cross platform availability (may be)

Page 26: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

BDP supported RDBMS

INTERBASE 7, 7.5ORACLE 9i,10gDB2 V 7.2, 8.xMSSQL 2000 / MSDE MSAccess Sybase 12.5.NET DataStore (EBU)and more to follow…

Page 27: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Demos

8. Metadata retrieval

9. Schema Creation

10. Data Migration - BdpCopyTable

Page 28: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

.NET DataSet Resolving

DataHub and DataSyncProvide and resolve data from multiple data source, master-detailGenerates optimal SQL for resolving to BDP data sources Supports Live Data at design-time from any .NET data provider

DataHubProperties:

ActiveDataSet, DataPort

Methods:ApplyChanges()Refresh()

DataSyncCommitBehavior

Page 29: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

.NET DataSet Resolving

DataHub

DataSet

DataSync

BDP

BDP

SQLClient

ODP.NET

Interbase

Oracle

MSSQL

DataTables

Page 30: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Demos

11. 2-tier DataHub and DataSync

12. Master-Detail resolving

Page 31: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

.NET Remoting

Interprocess communication between application domains

To Remote:1. A remotable object

2. A host app domain to host the remote object and listen for requests

3. A client app domain that makes request for the object

Page 32: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

.NET Remoting

Remotable Objects

Marshal-By-Value

ISerializable

SerializableAttribute

MarshalByValueComponent

State of the object copied

Marshal-By-Ref

MarshalByRefObject

State of the object stays in the app domain it was created

Page 33: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

.NET Remoting

Proxy

Formatter

Client ChannelSinkServer ChannelSink

Formatter

Remote Object

Client Process Server Process

TransportSink TransportSink

Page 34: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

.NET Remoting

MBR Activation modelServer activated Objects (SAO)

Server object created only on the first method callOnly a proxy is created when the client requests to createDefault constructor only allowedSingleton

One object servers all clientsLifetime controlled by leaseMaintain state between clients

SingleCall Separate object for each requestDoes not participate in lifetime leaseNo state maintained, best choice for load

balancing

Page 35: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

.NET Remoting

MBR Activation model

Client activated Objects (CAO)

Created on the server upon request to create a new object

Non Default constructors can be used

ObjRef is returned and a proxy is created on the client

Can maintain state between client method calls

Lifetime controlled by lease

Published Objects

Publish an already created object on the server

Behaves as a Singleton SAO afterwards

Page 36: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

.NET Remoting

MBR Lifetime

Lease manager and Sponsors keep MBR alive

Every app domain has a lease managerLease manager periodically checks for lease expiry

Infinite lifetime By overriding MarshalByRefObject.InitializeLifetimeService

public override object InitializeLifetimeService()

{ return null; }

Page 37: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Demos

13. Simple DataSet remoting

Page 38: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

DataSet Remoting

RemoteServer, RemoteConnection public interface IDataService { String[] GetProviderList(); IDataProvider GetDataProvider(String ProviderName); } public interface IDataProvider { DataSet GetData(); Int32 SaveData(DataSet ds); DataProviderCollection Providers { get; set;} }

RemoteTracker: ITrackingHandlerRemoteClientSponsor

Page 39: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

DataSet Remoting

DataHub

DataSet

Interbase

Oracle

MSSQL

RemoteConnection

RemoteServer (SAO)

DataSync (CAO)

DataSync (CAO)

Page 40: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Demos

13. Multi-tier using RemoteConnection and RemoteServer

Page 41: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Remoting vs Web Services

Stateless objects Yes Yes

Singleton objects Yes No

Statefull objects Yes No

TCP sockets for communication Yes No

HTTP for communication Yes Yes

Hosting in IIS Yes Yes

Custom Hosting Yes No

SOAP serialization Yes Yes

Binary serialization Yes No

Interoperability No Yes

Page 42: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Message Queues

MOM: Asynchronous distributed applications

Reliable, offline access

Robust, guaranteed delivery

Priority messaging

Transactional messages

Secure

Page 43: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Message Queues

Client2Message

Queue

Client3

Client1

Server2

Ack.Queue

Server

1

Page 44: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Message Queues

System.Messaging NamespaceMessageQueueMessageMessageQueueEnumeratorMessageEnumerator

System.Messaging.MessageQueueCreate(),Delete(),Purge()Exists()PathSend()Receive(), BeginReceive(), EndReceive()Peek(), BeginPeek(), EndPeek()

Page 45: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

MessageQueue

Identifying a Queue:

Path

- Uniquely identified by Computer and Queue name

- Online queues

FormatName

- Unique identifier generated by MSMQ - Online and Offline queues

Label

- Name given by the queue administrator

- Useful when Message Queue are moved

Page 46: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

MessageQueue

Queue types:Private Queue – Local to the machine

MachineName\Private$\QueueNameFORMATNAME:PRIVATE=MachineGUID\Queue#

Label:QueueName

Public Queue – Local or any computer you have rights

MachineName\QueueName

FORMATNAME:PUBLIC=QueueGUID

Journal Queue - Save copies

MachineName\QueueName\Journal$

FORMATNAME:PUBLIC=QueueGUID;JOURNAL  

Dead-letter Queue, Transactional dead-letter Queue

Page 47: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Demo

14. Send and Receive simple message

15. Priority messages

Page 48: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Message Acknowledgement

Two types of acknowledgements:a. Message reached destination Queueb. Message retrieved from the destination Queue

Positive or Negative acknowledgement

Requesting for an Acknowledgement:AdministrationQueue PropertyAcknowledgeType Property

None FullReachQueueFullReceiveQueueNegativeReceivePostiveArrive, PostiveReceive

Ack. Messages have no Body, only a header with Correlation ID

Page 49: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Journal QueuesSystem Queue - Allow saving copies of messages Read-only for applicationsMessages are not removed as they are receivedHave Maximum quota and don’t report errors

One Journal Queue per message QueueMessageQueue.UseJournalQueue Property

Enable storage for any message received by the Queue

One System Journal Queue per machineMessage.UseJournalQueue Property

This message, when sent will be recorded on the system journal

MessageQueue.MaximumJournalSize

Page 50: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Demo

16. Message with Acknowledgement

17. Journal messages

18. Purge Journal messages

Page 51: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Receiving MessagesFormatter Property

IMessageFormatter

XMLMessageFormatter

BinaryMessageFormatterActiveXMessageFormatter

DenySharedReceive PropertyClose() will free it for others

MessageReadPropertyFilter PropertyEnables or disable what property you want to receive

Peek(), Receive()

Page 52: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Retrieving Messages

Static and Dynamic retrieval Messages:MessageQueue.GetAllMessage()

MessageQueue.GetEnumerator()

Static and Dynamic retrieval Message Queues:MessageQueue.GetPrivateQueuesByMachine()

MessageQueue.GetMessgeQueueEnumerator()

Page 53: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Transactional QueueAll messages are delivered once and in order.

Two types:

Internal Transactions

Between one or more Message queues

External TransactionsMessage Queues and other resources through DTC

MessageQueueTransaction

Begin()

Commit()

Rollback()

Page 54: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Demo

19. MessageQueue and Message Retrieval

20. Transactional Queues

Page 55: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Reliable MOM

MSMQ

Supports Acknowledgements,Journaling, Recovery, Transactions, Asynchronous Receive/Peek, Priority

“Every DAD needs MOM”

“Real DAD needs no MOM”

“A DAD needs MOM”

Page 56: Microsoft.NET Framework Data Access Ramesh Theivendran John Powell Borland Software Corporation

Questions?

[email protected]