ADO Object Model
In making a web page has not been complete if we can not dynamically
interact with the web that we visit, one of the added value of an ASP
is that we can create a script that we created integrated with a
database, such as Microsoft Access.Visual FoxPro, or Microsoft SQL
Server. ActiveX Data Object (ADO) is a component that enables client
applications to access and manipulate data on the web server. Identity
ADO program is ADODB. Such objects laiinya ADO also has a collection,
properties and methods, including the ADO object model, Command Object,
Object Connection, Object Error, Field Object, Object Parameter, Object
Properties, Object Recordset AddNew method, append, delete methods,
methods execute, Property AbsolutePage, AbsolutePosition, etc.
ODBC
To gain access to the resources of OLE DB, the first step that must be done
ADO is telling the database where the source file is placed.
Conection string used varies depending on the data source Database that we make.• Microsoft Access data sources using OLE Db = Provider = Microsoft.Jet.OLEDB.4.4; Data Source = layout file.mdb
• Microsoft SQL Server = Provider = SQLOLEDB.1; Data Source = location of the database server
• Oracle = Provider = MSDAORA.1; Data Source = location of the database on the server
• Microsoft Indexing Service = Provider = MSIDXS.1; Data Source = layout file
for example;
<%
Set cnn = Server.CreateObject ("ADODB.Connection")
Cnn.open "Provider = Microsoft.Jet.OLEDB.4.0; Data
Source = C: \ Documents \ data.mdb
%>
By using ODBC we will be able to get a lot more database drivers
but
the connection will be more complicated than the way the OLE DB. On any
version of Windows ODBC can be accessed in the Control Panel.
Notice at the top there are several tabs, including;
User DSN: if used, then only the computer user who can to access
System DSN: all computers have the same network then able to access
data sources,
File DSN: will provide multi-user access to data sources, and can be transferred from one server to another server.
System DSN is an example script;
<%
set object name = Server.CreateObject ("ADODB.Connection")
Objek.open name "the name of the data source"
%>
While the script File DSN is;
<%
Set object name = Server.CreateObject ("ADODB.Connection")
Namaobjek.open "FILTERDSN = namafile.dsn
%>
Without a connection DSN
There
yng very easy trick that we do not need to connect the script that we
created with the database, thus will facilitate the future will upload
to the Internet. Indeed, Microsoft never that by using DSN then the
process will be faster. But lately many on the mailing lists of the ASP
programmers who say that the bugs 'Too Many Tasks Client' one of them
happen because of the connection to the database using the DSN which
occurs when the user concurrent connections. Most systems use DSN less
advisable to connect with Access.
The main difference
between the System DSN with the DSN less is the mention of the name of
the database directly on the DSN-less are used along with the driver,
while the DSN connection, the name of the database has been represented
by the name of the DSN is created in ODBC menu.
Example script difference;
Connection string
StrKoneksi = "DRIVER = {Microsoft Access Driver (*. Mdb};"
StrKoneksi = StrKoneksi & "DBQ =" & Server.MapPath
("namadatabase.mdb")
DSN-less connection string
<%
Set DbConnection = Server.CreateObject ("ADODB.Connection")
StrKoneksi = "DRIVER = {Microsoft Access Driver (*. Mdb};"
StrKoneksi = StrKoneksi & "DBQ =" DB Connection.Open
StrKoneksi
%>
Guest Book
<HTML> <HEAD>
<TITLE> Welcome </ TITLE>
</ HEAD>
<BODY>
<CENTER>
<font face="Impact" size="7" color="#0000FF"> Welcome in
Deris Stiawan <br> Official Sites </ font> <BR> <CENTER>
<p align="center"> <font face="Trebuchet <i> MS" size="4">
Please ... give me some opinion about my critics or sites <A
HREF = "guest.asp"> <b> click here </ b> <br>
<A HREF="List.asp"> Click here to see another
visitors </ font> </ i> </ p>
<p align="center"> </ p>
</ BODY> </ HTML>
Next we create a script and save it with the name 'guest.asp'
<HTML>
<HEAD>
<TITLE> Guest Book </ TITLE> <SCRIPT LANGUAGE=VBScript>
<! -
sub btnSubmit_OnClick
Dim ojbForm
Set objForm = Document.frmGuest
If objForm.txtNama.value = "" or objForm.txtEmail.value = "" Then
MsgBox "You have to fill in your name" &
chr (13) & "or your email address"
else
objForm.submit
end If
end Sub
->
</ SCRIPT>
</ HEAD>
<BODY>
<CENTER>
<FONT FACE="Impact" Size=7 COLOR=#0000FF>
Guest Book </ FONT>
</ CENTER>
<FORM NAME = "frmGuest" ACTION = "terimakasih.asp"
METHOD = "post">
<TABLE ALIGN=Center width="380">
<TR> <TD>
<PRE>
Name: <INPUT TYPE=Text NAME=txtNama> <BR>
Email: <INPUT TYPE=Text NAME=txtEmail> <BR>
</ TD> </ TR>
<TR> <TD>
<PRE>
comment:
<textarea NAME=txtarComent ROWS=9 COLS=43> </ TEXTAREA>
</ TD> </ TR>
<TR> <TD>
<INPUT Type=button VALUE=Submit NAME=btnSubmit>
<INPUT TYPE=Reset>
</ TD> </ TR>
</ TABLE>
</ FORM> </ BODY> </ HTML>
Result :