Web/Database Connectivity: David Henson
Web/Database Connectivity: David Henson
Web/Database Connectivity: David Henson
NET
David Henson dhenson@certifiednetworks.com
Class Logistics
Class Hours Classroom Setup Class Format https://www.certifiednetworks.com
Course Outline
Module 1 - Web Overview Module 2 - ASP.NET Overview Module 3 - ASP.NET Webform Module 4 Debugging/Tracing Module 5 - .NET Controls Module 6 ADO.NET
Definitions
ASP ASP.NET HTTP IIS Virtual Directory Browser MSIL CLR HTML
HTTP Protocol
Header Body
HTML Protocol
End result of any dynamic server side productdictates rendering of page Tags:
<html> <body> <table><tr><td> <form> <a href=> <br> <input type=>
.NET Framework
What is ASP.NET
Not a programming language but a delivery mechanism Can leverage any .NET programming language, like built-in VB.NET, C#, and third party like Delphi
.NET Features
Multiple Language Support Increased Performance
Compiled code Cache
Server Controls Web Services Improved Security Greater Scalability Cookie-less Sessions Easy Configuration and Deployment
Demonstration Spy++
What to look for:
Event Driven Model of Windows
ASP.NET Example
Solution Files
Solution contains 1 or more projects .sln file created in:
My documents\Visual Studio Projects\*.*
To Change Defaults:
Tools/Options/Environment/Projects & Solutions
Project Files
Project maps to web application Web Application Created in:
c:\inetpub\wwwroot\projectname
New Virtual Directory Created W/ Project Each Application can have its own web.config
Other Files
Webforms: .aspx Web Services: .asmx Styles.css IIS Prevents Execution of PreDefined Extensions Code Behind Files: .vb & .cs Discovery Files: .disco, .vsdisco ASP.NET Application File: Global.asax Resource Files: .resx Web.Config
Webforms Defined
aspx extension @Page Directive
<%@ Page Language="vb" %> <%@ Page Language="vb" %>
Contain Client-side and Server-side Code Contain HTML and .NET Server Controls
Events
User requests dbdemo.aspx Page_Load event detected Sub Page_Load() executed All event handlers are called in a single flow of motion, before the user ever gets to see the page.
You may also double-click the control in design view to get into the default event handler for that control with a pre-defined event handler name.
Webform Validation
Page.IsValid will be false if any control has failed validation Asp:ValidationSummary Control
Set Display property of any validation control to None ValidationSummary Control will display msg from all controls
Manual Validation
Add form submit button with CausesValidation set to False, then call Page.Validate yourself. Take action based upon page.IsValid property
Module 4 Debugging/Tracing
Debugging Tracing Error/Exception Handling
Logging Exceptions
Try some code Catch err AS Exception Dim log as New EventLog() Log.Source = MyPage Log.WriteEntry(err.Message, EventLogEntryType.Error) End Try
Viewing Eventlogs
Display of Errors
Error Modes:
RemoteOnly Default, hides details if not local client Off Shows all details and sourcegood for development, not production On Displays custom error page if any, or generic error message
</system.web> </configuration>
User Controls
.ascx file Replaces the #include file from ASP Provides re-usuable code within your application Contained within a Webform
HTML Controls
Best for Converting from ASP to ASP.NET Add the runat=server attribute to existing controls
ASP.NET Controls
Mirror HTML Controls More Consistent Properties/Naming Across Control Types
Control Validation
Templated Controls
You supply the HTML
Module 6 ADO.NET
Components of ADO.NET
SqlDataAdapter SqlDataSet SqlDataTable SqlDataReader SqlCommand
Required Namespaces
Namespace Defined Two In Use This Class:
System.Data Provider Independent Like DataSet System.Data.SqlClient Provider Dependent Like
SqlConnection
ASP.NET Syntax:
<%@ Import Namespace=System.Data %>
Providers
Providers Available:
SQL Server .NET Provider OleDB .NET Provider
Example-AllRecordsBasicOleDB.aspx
Connections
Connection Defined Where to Store the Connection String Connection Syntax Examples Connection Pooling Security Close Your Connections! Monitoring Connections
Connection Pooling
Defined Controlling Min/MaxExample6ShowConnectionStatePoolControl.aspx
Importance of Exact String Match Pooling for SqlClient vs. OleDBClient Effects of pooling on SQL security Close Your Connections!
Performance Issues
Choose Providers Wisely DataReader vs. DataAdapter Repeater Control vs. DataGrid Control Connection Pooling Embedding SQL vs. Stored Procedures Controlling The HTML Typed Accessor MethodsExample7AdapterVsReaderUsingTypedAccessorMethods.asp
DataAdapter
More Overhead More Flexible
DataGrid
Default HTML Behaviour Higher Overhead, Most Functionality
Final Recommendations
Use DataGrids Only When Updates Are Needed Embed Connection In Code Behind File Only Select What You Need Call StoredProcs For Ultimate Performance When Paging
References
Book: Programming Data-Driven Web Applications with ASP.NET Web:
http://www.asp.net http://msdn.microsoft .com/library/default.asp?url =/library/en-us/dnbda/html/daag.asp Http://www.certifiednetworks.com
Comparing ADO/ADO.NET
Paging
Methods for paging:
Data Grid Manual Stored Procedures
Inserts
INSERT table1 VALUES(Smith,Joe,)
Updates
UPDATE Table1 SET Unitprice = Unitprice * 1.1
Deletes
DELETE Table1 WHERE CustomerID = 10
Module 8 Security
Authentication/Encryption
Setup of SSL
SMTP Protocol
Sending Email
SMTP is now built into .NET
System.Web.Mail.SmtpMail.Send( from, to, subject, body )
Reading/Writing Files
Dim w As IO.StreamWriter w = IO.File.CreateText("C:\somefile.txt") w.WriteLine(Request("textbox1")) w.Close()
Module 10 XML
What is XML?
XML Document
Well formed if:
Doc has a root element Every tag has an end(case sensitive) No special characters are used
Valid if:
Doc format agrees with specification
Formatting Issues
Use .css to separate data from the formatting
<?xml:stylesheet href="test.css" type="text/css" ?>
Web Services
.asmx file Inherits from System.Web.Services.WebService Web Service method marked with the WebMethodAttribute Allows client to discover its methods Interacts w/ client through SOAP
Implementation
Plumbing is built into the classesyou focus on the business needs Web Service consumer adds the web reference, then uses the class like any other