Docsity

Connection Object - E-Commerce - Lecture Slides, Slides of Fundamentals of E-Commerce

Toggle sidebar
bg1
The ADO Connection Object
• Provides a facility to
– send SQL action queries back to the server and see how
many records were affected
– create fire hose queries
– execute stored procedures
• Created via the usual mechanism
Set CN=Server.CreateObject("ADODB.Connection")
• As usual what is created should be
destroyed
Set CN = Nothing
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Connection Object - E-Commerce - Lecture Slides and more Slides Fundamentals of E-Commerce in PDF only on Docsity!

The ADO Connection Object • Provides a facility to – send SQL action queries back to the server and see howmany records were affected– create fire hose queries– execute stored procedures • Created via the usual mechanism Set CN=Server.CreateObject("ADODB.Connection") • As usual what is created should bedestroyed^ Set CN = Nothing

The connection object needs theDSN as before. • For example this is the DSN for this class: const^ cDSN^ =^ "Driver=SQLServer;Server=130.86.76.169;Database=pubs;UID=student;PWD=student;" • To open a connection object is very simple Set^ CN^ =^ Server.CreateObject("ADODB.Connection")CN.Open^ cDSN • Again, if an object has an OPEN closeshould be applied CN.Close

The select statement for the actions^ AUID = trim(Request.QueryString("AUID"))if len(AUID) = 0 then'Redirect method must be used before element'unless buffer property used firstResponse.Redirect("AspADO1.Asp")end ifACTION = ucase(trim(Request.QueryString("ACTION")))'...Select case ACTIONcase "DELETE"'Delete Recordcase "NEW"'Add Recordcase "SAVENEW"'Save Newly Added Recordcase "SAVE"'Save Edited Recordcase else'Show Record To Be EditedEnd Select

Editing a record • The code on the next slide demos how totake a recordset open one specific recordand fill a form with the existing values.• Note use of the 'name' and 'value' attributes.• The code on the page after that, shows howonce the user hits the [UPDATE] buttonwhat code is behind updating the databaseusing the form fields.

The "SAVE" code 'Create and open a connection objectSet CN = Server.CreateObject("ADODB.Connection")CN.Open cDSNmySQL = "Update Authors Set AU_FNAME = '" &Request.Form("FIRST") & "', AU_LNAME = '" &Request.Form("LAST") & "' where (AU_ID = '" & AUID & "')"CN.Execute mySQL,RAif RA = 1 thenResponse.Write("

Record Saved. Author ID: " & AUID & "

")elseResponse.Write("

Record NOT Saved, Contact support! Author ID: " &AUID & "

")end ifCN.CloseSet CN = Nothing This is an example for how the SAVE mechanism works.Notice, proper disposal of objects when done with them.

Summary • Since each time the page is visited the connectionis re-created the form is stateless with respect tothe server.• Statelessness is the most scale-able solution.• Combined with paging, the overall load on theserver is minimal.• This example uses two forms, it could all beimplemented in one form, but it would be a verycomplex one.• Ideally, the first form should be a paged search.

Collisions, what are the choices • When you get the error your choices are:^ – Discard the changes your user made, warn themand make the user reapply them after your re-acquire the conflicted record (so you have thenew time stamp) or you can make yourprogram do it.– Don’t update at all.