Freigeben über


How to make an easy ASP application to Benefit your team

In a capsule, ASP 3.0 or ASP.NET is a server scripting language that enables programmers to generate HTML or JavaScript code. Since it is server side, clients will not be able to view the server side script by simply using "View Source". As you probably can tell, I generally like to keep my explanations as simple and straightforward as possible. As a result, I won't dwell into too much details.

Why is it so powerful?

  1. It's easy to use (VBS) 
  2. It has Database read and write capabilities (ADO) 
  3. It has file read and write capabilities (FSO)

 How can it benefit your company?

  1. Create web applications with high customization 
  2. Displaying specific real-time data from a database onto your web page and securing protected data from being accessed
  3. Automatomatically generate dynamic websites based on new data
  4. Creating simple search engines (My Favorite)
  5. Parsing Text Files and displaying the results on the web

1. Setting up your computer for ASP development:

Generally, ASP development would be ideal within a server OS; but this is not the only place where it can be developed. Here are some simple steps to setup your system for ASP development.

1.1 Server OS: Windows 2003

  • Select the "Manage Your Server" wizard within "Administrative Tools"
  • Select "Add or Remove a Role" 
  • Select "Custom Configuration"
  • Select "Application Server Role"
  • Select "Enable ASP.NET", this will enable both ASP 3.0 and ASP.NET
  • Select "Manage This Application Server
  • Select "Internet Information Services IIS"
  • Ensure that Default Web Site is running
  • Within the "Web Service Extensions" folder, highlight "Active Server Pages" and click "Allow"

1.2 Client OS: Windows XP Professional

  • Within the "Control Panel", select "Add/Remove Programs"
  • Select "Add/Remove Windows Components"
  • Check "Internet Information Services" and then OK
  • Once the IIS is installed
    • "Inetpub" folder will be created on your C:\
    • "wwwroot" folder will be created within the "Inetpub" folder
    • Within the "wwwroot" folder, create a new folder for your project "MyProject"

 

2. Creating a REALLY Simple ASP program (For some motivation)

When creating your first ASP program, simply follow the proceeding instructions

  • Open NotePad
  • Type the following: <% Response.Write("Hello World") %>
  • Save the file within the "MyProject Folder" as "something.asp"
  • Open Internet Explorer and type the following within the URL: https://localhost/MyProject/something.asp

 

3. Creating a Simple ADO Database Connection

ADO (ActiveX Data Objects) is a common way to read and modify a database from within an ASP page. ADO is installed along with IIS; so no worries there. There are 4 Basic Types of Database Connections via ADO. These connections will enable you to access and manipulate database records. This will open doors to storing information, building mini search engines, and displaying a subset of database data on your web page.

3.1.1 Microsoft Access Database via ODBC (DSN-less)

Dim connection
connection= "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="& Server.Mappath("./myfirstdatabase.mdb") & ";"

3.1.2 Microsoft Access Database via OLE DB (DSN-less)

Dim connection 
connection = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.Mappath("myfirstdatabase.mdb") & ";"

3.1.3 SQL Server Database (DSN-less)

Dim connection 
connection = "Provider=SQLOLEDB;User Id=username;Password=password; Connect Timeout=15;"

3.1.4 DSN Connection using SQL Server

Dim connection 
connection = "DSN=DSNname; UID=username; PWD=password;DATABASE=databasename"

3.2 Generate a SQL query in order to specify which records you are interested in

Dim qryString 
qryString = "Select Col1, Col2 FROM table1;"

3.3 Create a RecordSet Object that will contain the records obtained from the SQL query and using one of the four discussed connection methods

Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open qryString, connection, adOpenKeyset, adLockPessimistic, adCmdText 'Please note: the last three parameters can be modified based on your needs

3.4 Database Manipulation using the Recordset Object

3.4.1 Database Read

A pointer is pointed at the first record retrieved from the SQL query. In order to display the record that is pointed by this recordset object's pointer, simply use the following syntax:

rs.Fields("Field Name").Value

Example: response.write(rs.Fields("Col1").Value) 'Will display the Col1 field value of the record current pointed by the pointer

3.4.2 Database Write

In order to add a record to the database table, simple add a new row, assign the value, and update the database.

rs.AddNew
rs.Fields("Field Name").Value = "Desired Value"
rs.Update

3.4.3 Moving to the next record in the RecordSet Object

rs.MoveNext

3.4.4 Closing the RecordSet Object

Each time a recordset object is no longer required, ensure that the recordset is closed and pointed to nothing.

rs.Close
Set rs = Nothing

 

And there you go. A simple 10 minute introduction to how you can create a simple ASP application to benefit your team. I will go into further detail in future entries.

Comments

  • Anonymous
    July 27, 2007
    Awesome tutorial/example! I'm a pretty feeble scripter who had never attempted a db read from a script before.  Your example plus about 20 minutes had me accessing the data I needed. Thanks much!

  • Anonymous
    October 04, 2007
    I'm glad I was able to help :)