Tiger Computer Services Ltd Using Interfaces in.NET Simplifying access to multiple DB providers in.NET Liam

Slides:



Advertisements
Similar presentations
Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Advertisements

Database Connections with ASP.Net
ADO vs ADO.NET ADOADO.NET Client/server coupledDisconnected collection of data from data server Uses RECORDSET object (contains one table) Uses DATASET.
Visual Basic.NET A look into the.NET Programming Model Bryan Jenks Integrated Ideas ©2005.
Windows Programming 1 Part 1 dbg --- Getting Acquainted with Visual Studio.NET and C#
.NET Framework Overview Pingping Ma Nov 16 th, 2006.
Introduction to Database Processing with ADO.NET.
.Net Overview Data Driven Desktop and Web Applications using VB.Net and ASP.Net, C#.Net or J#.Net.
C#/.NET Jacob Lewallen. C# vs.NET.NET is a platform. Many languages compile to.NET: –VB.NET –Python.NET –Managed C++ –C#
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
ASP.NET Programming with C# and SQL Server First Edition
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Chapter 14: Advanced Topics: DBMS, SQL, and ASP.NET
Objective In this session we will discuss about : What is ADO. NET ?
Creating and Running Your First C# Program Svetlin Nakov Telerik Corporation
Using Microsoft SharePoint to Develop Workflow and Business Process Automation Ted Perrotte National Practice Manager, Quilogy, Microsoft Office SharePoint.
Visual Basic.NET A look into the.NET Programming Model Bryan Jenks Integrated Ideas ©2005.
A Free sample background from © 2001 By Default!Slide 1.NET Overview BY: Pinkesh Desai.
Overview of Microsoft.Net and Vb.Net ITSE 2349 Spring 2002 Material from Microsoft.Net an Overview for ACC faculty by Stuart Laughton and Introduction.
Ihr Logo Data Explorer - A data profiling tool. Your Logo Agenda  Introduction  Existing System  Limitations of Existing System  Proposed Solution.
Introduction to .Net Framework
Programming with Visual Basic.NET An Object-Oriented Approach  Chapter 8 Introduction to Database Processing.
VS.NET Syllabus By Peter Huang.
Native Support for Web Services  Native Web services access  Enables cross platform interoperability  Reduces middle-tier dependency (no IIS)  Simplifies.
Creating and Running Your First C# Program Svetlin Nakov Telerik Corporation
Visual Studio ®.NET Data with XML Carlotta Eaton ( Associate Professor of IST New River Community College Slides by Microsoft Modified.
Enticy GROUP THE A Framework for Web and WinForms (Client-Server) Applications “Enterprise Software Architecture”
DB Libraries: An Alternative to DBMS By Matt Stegman November 22, 2005.
Navigating database with windows forms.. Tiered applications  Provide a means to develop many presentations of the same app  Makes changes to the back.
© Minder Chen, ASP.NET 2.0: Introduction - 1 ASP.NET 2.0 Minder Chen, Ph.D. Framework Base Class Library ADO.NET: Data & XML.
Needs for Accessing Database To make your web site more dynamic and maintainable, you can display information on your web pages that are retrieved from.
Databases and Data Access  Introduction to ADO.NET  ADO.NET objects  ADP.NET namespaces  Differences between ADO and ADO.NET.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
Architectures Classic Client/Server Architecture Classic Web Architecture N-tier (multi-tier) Architecture FEN Databaser og Modellering.
SQL Server User Group Meeting Reporting Services Tips & Tricks Presented by Jason Buck of Custom Business Solutions.
Searching Business Data with MOSS 2007 Enterprise Search Presenter: Corey Roth Enterprise Consultant Stonebridge Blog:
Chapter 10: The Data Tier We discuss back-end data storage for Web applications, relational data, and using the MySQL database server for back-end storage.
Sample Application Multi Layered Architecture (n-tier): –Graphical User Interface (GUI): Forms, components, controls The Visual Designer in Visual Studio.
Windows Forms Navigating database with windows forms.
ADO.NET Objects – Data Providers Dr. Ron Eaglin. Requirements Visual Studio 2005 Microsoft SQL Server 2000 or 2005 –Adventure Works Database Installed.
ADO.NET connections1 Connecting to SQL Server and Oracle.
6c – Function Procedures Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
VB Classes ISYS 512/812. Object-Oriented Concepts Abstraction: –To create a model of an object, for the purpose of determining the characteristics (properties)
DAT430 Extending Microsoft ® ADO.NET Building a Custom Data Factory API DAT430 Extending Microsoft ® ADO.NET Building a Custom Data Factory API Gert E.R.
HNDIT Rapid Application Development
Database Connectivity with ASP.NET. 2 Introduction Web pages commonly used to: –Gather information stored on a Web server database Most server-side scripting.
ADO.NET FUNDAMENTALS BEGINNING ASP.NET 3.5 IN C#.
ADO.NET Architecture MIS3502: Application Integration and Evaluation David Schuff Adapted from material by Arnold Kurtz, David.
Architecture Multi Layered Architecture (n-tier): Application: Model Controllers Database Access Graphical User Interface (GUI): Forms, components, controls.
INTRODUCTION CHAPTER #1 Visual Basic.NET. VB.Net General features It is an object oriented language  In the past VB had objects but focus was not placed.
Introduction Because database applications today reside in a complicated environment, various standards have been developed for accessing database servers.
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College Lecture 4: Intro to GUIs and the.
The Holmes Platform and Applications
.NET MCQs MULTIPLE CHOICE QUESTION
ASP.NET Programming with C# and SQL Server First Edition
Introduction to Database Processing with ADO.NET
Introduction to Database Processing with ADO.NET
Overview of Data Access
Overview of Data Access
VB.NET Using Database.
ADO.NEXT Advances in Data Access for 2008
Опит в използването на ODP.NET с Oracle 9i
Chapter 10 ADO.
Web Development Using ASP .NET
Database Management Systems
Chapter 10 Accessing Database Files
A look into the .NET Programming Model
Presentation transcript:

Tiger Computer Services Ltd Using Interfaces in.NET Simplifying access to multiple DB providers in.NET Liam DeveloperDeveloperDeveloper! - 14 th May 2005

Contents Quick overview of interfaces –What is an interface? –When and how to use an interface? Using interfaces for generic access to different DB Providers –Abstracting the differences –Creating and implementing the interface –MP3 library code walkthrough for SQL Server 2000 and mySQL 4.1

Interfaces vs Inheritance? Inheritance –inheritance defines an ‘is a’ relationship –.NET only supports single inheritance –if a class does not override a member, the base class implementation is used Interfaces –interfaces define an ‘act as’ relationship –a class can implement multiple interfaces Note: Visual Basic 6.0 supported Interfaces with the Implements keyword but it involved ‘casting’ of objects to the required interface

What is an Interface? Defines a set of properties, indexers, events and methods Contains no implementation code Other classes, which implement the interface, provide the implementation of the interface members Every member has to be implemented The interface does not define how the members should be implemented

When to use an Interface? For an ‘acts as’ relationship To enforce a set of rules for a class –application plug-ins –to create a ‘lowest common denominator’ To support multi-‘platform’ solutions –client program uses the interface to access majority of functionality –each ‘platform’ has a class which implements the interface –Platforms include Windows App, ASP.NET,.NET Compact Framework, or different DB providers

Creating an interface – VB.NET Public Interface IHelloWorld Function HelloWorld(ByVal myName As String) As String End Interface Public Class English Implements IHelloWorld Public Function HelloWorld(ByVal myName As String) _ As String Implements IHelloWorld.HelloWorld HelloWorld = "Hello " + myName + "!" End Function End Class Interface (IHelloWorld.vb) Implementation (English.vb) Public Class Francais Implements IHelloWorld Public Function HelloWorld(ByVal myName As String) _ As String Implements IHelloWorld.HelloWorld HelloWorld = “Bonjour " + myName + "!" End Function End Class Implementation (Francais.vb)

Using that interface – VB.NET Private Sub btnSayHello_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles btnSayHello.Click Dim hw As IHelloWorld If (rbtnEnglish.Checked) Then hw = New English Else hw = New Francais End If MsgBox(hw.HelloWorld(txtName.Text)) End Sub Windows Form application

Creating an interface – C# public interface IHelloWorld { string HelloWorld(string myName); } public class English : IHelloWorld { public string HelloWorld(string myName) { return "Hello " + myName + "!"; } Interface (IHelloWorld.cs) Implementation (English.cs) public class Francais : IHelloWorld { public string HelloWorld(string myName) { return “Bonjour " + myName + "!"; } Implementation (Francais.cs)

Using that interface – C# private void btnSayHello_Click(object sender, System.EventArgs e) { IHelloWorld hw; if (rbtnEnglish.Checked) { hw = new English(); } else { hw = new Francais(); } MessageBox.Show(hw.HelloWorld(txtName.Text)); } Windows Form application

Real World – Generic DB Providers First some facts ? –ADO ‘classic’ or ADOc provided a generic data access model –ADO.NET is not generic –we have namespaces for each DB provider  i.e. SQLConnection, OracleConnection etc.. Not true !! –Microsoft provided generic database access out of the box –Look in the MSDN Library carefully, i.e. IDBConnection, IDBCommand etc..

How do we use these interfaces? Examine the interfaces within the System.Data namespace, –IDBConnection, IDBCommand, IDataReader, IDBTransaction etc.. Ensure the business layer members only utilise interface references public void GetItem(IDBConnection openDB) Create DB provider specific variables within the client, and pass these as interfaces to the business layer

actually, this is not a real generic solution Interfaces are not enough, there are SQL syntax issues as well What does ‘generic’ really mean –Safely format data used in SQL statements –‘Format’ field and table names to allow reserved names (or spaces – urgh!) –Map.NET data types to different DB provider data types –Prevent provider specific properties being used (HasRows property)

Quiz time SQL 2000 vs MySql 4.1

… and.NET data connectors differ too Can only use methods and properties from System.Data interfaces –HasRows property not in base interfaces (absent in SQL Server for CE 2.0) –ExecuteXmlReader is only in SqlClient Some methods are not supported –MySql.NET connector doesn’t support the Cancel method on a IDBCommand –Auto incrementing identity fields are not always returned as System.Int32

What do we lose ? For code to work with all databases we have to give up some stuff –Stored procedures are not available in MySql 4.1 (or MS Access, or SQL CE) –Generic data types, no UDTs –All commands must be raw SQL statements designed to work with all databases –Code can become less readable Not for everyone – losing SQL Server 2000 features may not be appropriate

What could we gain ? Single code logic handling database operations in the business layer Multi platform deployment –Intranet might could use SQL Server, but a public web site implementation could use MySql Higher performance with native data connectors, rather than OLEDB connector Robust SQL, if you are methodical –LIKE handles quotes and wildcards –No UK/US Date format issues ever again –NULL replacement handled elegantly –Prevent SQL injection attacks

MP3Library – ASP.NET application

Only a starting point View this as a base –more reliable code –more secure code –target multiple platforms; SQL Server 2000, MySql 4.1 Oracle, IBM DB2, SQL Server CE, Microsoft Access Next step –create generic database schemas –automated code creation for business logic, and even web services

Bengal RapidDB Origins –concept of database compatibility between SQL 2000, SQL CE and Microsoft Access –mobile data connectivity via web services, not via standard replication –automated generation of code libraries and web services Key features –lowest common denominator data types –code suitable for.NET CF

Bengal RapidDB

Thank you Any questions?