ASP beginners MUST SEE: Dynamic Web page should pay attention to some problems

Source: Internet
Author: User
Tags date format character set commit odbc sql injection table name oracle database
Learning | news | web | issues

For the beginners with ASP technology programming, it is the first feeling, I have had such a experience. After a "ordeal", you'll find inspiration. Now I have accumulated some experience in programming, to the cost of the text, dedicated to the reader.

1 First learn some example programs.

When you receive a task, do not blindly rush to write code, but first look at the success of others, and then modify or imitate debugging, which will speed up your familiarity. For example, the textbook on ASP programming often has such an example, that is, the statement showing the current time of the system: <%=now ()%>, don't look at such a simple statement, inside but contains the ASP's programming ideas and format, will give you the work behind the great help. For example, to test whether the IIS (Internet Information Server) WEB server is working properly, it is sufficient to test with one of the above statements. After the

2 installs ODBC on Windows NT, to test and the background database is actually connected, start the programming test.
You may not be able to read the meaning of the topic, and I am here to explain: for example, the background database is Oracle, then first install sql*net (or NET 8) on the NT Sever, then configure ODBC to identify and connect to Oracle databases, You can use the Sql*plus test and choose the same character set as the Oracle database, which is done in the registry. Finally, after the ODBC inside test and Oracle database connectivity, the Web SERVER to the back of the database end of the work is completed, and then start programming work. Conversely, if you first program, and then do ODBC work, then you can not debug the program is correct, may greatly reduce the efficiency of programming. To select Microsoft ODBC for Oracle in the ODBC configuration, do not select Oracle ODBC DRIVER, or you cannot establish a connection with the database.

in an ASP program, the statements that are connected to the database are relatively fixed, for example:
Set Conn = Server.CreateObject ("ADODB. Connection ")
Conn.Open" Odbclink "," O7people "," PEOPLEPD "
Here, Odbclink is the name of the data source, which can be said to be the definition of ODBC and database connections, O7people is a user name for Oracle, PEOPLEPD is the password of the user o7people.

3 Record the error message, look for error correction law.

In the programming, debugging process, is an error, error correction of the cycle, but a long time, will find some rules, the efficiency of the elimination of errors will be greatly improved.

3. 1 Error message:

Microsoft OLE DB Provider for ODBC Drivers error ' 80040e14 '
[Microsoft] [ODBC driver for Oracle] [Oracle] Ora-00933:sql command not properly ended
/default.asp, line 781
This error typically occurs when you perform a conn.execute ("SQL statement") operation, the defined "SQL statement" has a problem, check this statement to find the problem, such as the date format is not correct, and so on.
Zhezhong

3. 2 Error message:

ADODB. Field error ' 800A0BCD '
One of the BOF or EOF is "true", or the current record has been deleted, but the application requires that the current record be manipulated.
/lzjsblr.asp, line 123
This error generally occurs during the execution of the following statement:
Set RS = Conn.execute ("SQL statement")
Varnum1=rs (0)
Rs. Close
The value RS (0) is meaningless or meaningless, and the correctness of the "SQL statement" is checked.

3. 3 Error message:

Microsoft VBScript Compiler error ' 800a0409 '
String constants that are not ended
/people/default.asp, line 86
Insert_sql = insert_sql & DWDM & ", ' & D1 &" ', ' "& T1 &" ', ' "& T2 &",
--------------------------------------------------------------------------^
The minor error is also defined on the SQL statement, checking the pairing of quotes, single quotes, and so on.

4 Below is a browser-based online user registration process, the author in the use of some skills, dedicated to interested readers.

......
<
<% ' and database connection
Set Conn = Server.CreateObject ("ADODB. Connection ")
Conn.Open "Odbclink", "O7people", "PEOPLEPD"
' Put the selected data into the selection box
Set RS = Conn.execute ("Select DWMC from Tab_dw to DWDM")
%>
<% do, not RS. EOF%> <option><% = RS (0)%></option>
<%
Rs. MoveNext
Loop
Rs. Close
%>
<%
' Define variables
Dim D1,D2,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,CSRQ,SQRQ
' Event Trigger button
B1= "Commit"
B2= "Return"
%>
<%
' Initialize the information
Sub Reset ()
D1 = ""
......
T9 = Date ()
T10 = ""
End Sub
%>
<%
Call Reset ()
%>
<%
' Information submission condition (trigger condition)
If Request ("B1") = "commit" Then ' Save button
D1 = Request ("D1")
Set dwdm_rs = Conn.execute ("SELECT DWDM from Table_dw where dwmc= '" &D1& ")
Dwdm=dwdm_rs (0)
Dwdm_rs. Close
D2 = Request ("D2")
......
' Date data converted to Oracle-recognized format
CSRQ = Day (T6) & "-" & Month_array (Month (T6)) & "-" & Year (T6)
SQRQ = Day (T9) & "-" & Month_array (Month (T9)) & "-" & Year (T9)
' Define SQL statements
Sql_insert = "INSERT into Peopleuser (DWDM,DWMC,SJKS,TELE,ADDRESS,ZIPCODE,XM,XB,CSRQ,PEOPLENAME,PEOPLEPD,SQSJ,BZ) VALUES (' "
Sql_insert = Sql_insert & DWDM & "', '" & D1 & "', '" & T1 & "', '" & T2 & "', '" & T3 &am P "', '" & T4 & "', '"
Sql_insert = Sql_insert &T5& ', ' & D2 & ', ' & Csrq & ', ' & T7 & ', ' & T8 & ' ', ' & Sqrq & ', ' '
Sql_insert = Sql_insert & T10 & "')"
' Storing the information
Set LFMC_R4 = Conn.execute (Sql_insert)
' After the information is submitted, initialize the screen information
Call Reset ()
End If
%>

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

1, design planning

Now is the modular design of the world, the application to achieve the goal is the pyramid point, the meaning of programming planning is to constitute the pyramid of the basic modules to partition, planning more detailed, modular division of the more clear, the easier to understand what to do next, this is like building blocks of the game, You can combine your building blocks into a variety of shapes, but first familiarize yourself with the functionality of each block.

2. Be prepared for a precaution

Before actual combat, first find a few sample program research, at least understand how to start, how to end, don't fight unprepared battle.

3, Sunflower Treasure

Make a concise list of program languages, including basic data types, descriptions of various operators, basic statement structures, commonly used keywords (reserved words), descriptions of commonly used functions (controls), and more.

4. Free and Independent

Create a separate directory for your application that facilitates the management of application files, and if you want to move "home" to the program, roll up your blanket and you can leave.

5, see the name of the idea

The program is small, use the variable is not less, the variable name should be known as the old topic, the benefits are obvious. It is recommended that programmers use the Hungarian nomenclature, which makes your name work easier and more professional.

6. The beauty of symmetry

Chinese people pay attention to the beauty of symmetry, used in programming is also very appropriate, if the program used in a loop nested B judge, B judge and contains the C-cycle structure, remember to use indentation, let A:enddo align A:do,b:endif alignment b:if ... And so on, indent in turn, in short, symmetry equals beauty plus readability.

7, More Notes

A functional annotation of a custom variable, function, subroutine in a program, don't bother. If after March May, even write their own things can not understand, it is a big trouble.

8. Environmental protection

If your application needs to modify system settings, remember to save the settings before the application starts, and then restore the settings after the application is finished, and never pollute the environment.

9, copycat

A person's power is limited, everyone's strength is unlimited, usually more to see other people's procedures, if happen to have good experience, skillful method, use of the jokes, may wish to bring.

10, Ninja Invincible

When you think that the program code written "Hundred percent" correct, and the program compiles the implementation hundred cent has the flaw, you basically belong to the dizzy vegetable time, must endure, rests the breath, afresh, do not give up! Believe that the final victory belongs to you!

。。。。。。。。。。。。。。。。。。。。。

1. Open the Recordset again before closing:
------------------------------------
Sql= "SELECT * FROM Test"
Rs.Open sql,conn,1,1
If not rs.eof then
Dim myname
Myname=rs ("name")
End If
Sql= "SELECT * from MyBook"
Rs.Open sql,conn,1,1
-------------------------------------
Resolve: Close Rs.close before rs.open the second time
Or
Set Rs1=server.createobject
Rs1.open sql,conn,1,1

2, use SQL keyword to do table name or field name
-------------------------------------
Sql= "SELECT * from User"
Rs.Open sql,conn,1,1
-------------------------------------
User is the SQL keyword
Resolution: Change to
Sql= "SELECT * from [user]"


3, with the lock way to update
-------------------------------------
Sql= "SELECT * from [user]"
Rs.Open sql,conn,1,1
Rs.addnew
Or
RS ("userName") = "AA"
Rs.update
-------------------------------------
The current recordset is open in read-only mode
Solve:
To
Rs.Open sql,conn,1,3

4, the Contrast field value used in the query statement does not match the field type
-----------------------------------------
Sql= "SELECT * from [user] where id= '" & MyID & "'"
Rs.Open sql,conn,1,1
-----------------------------------------
Suppose that the design ID in the table is a numeric type, then an error occurs.
Solve:
Sql= "SELECT * from [user] where id=" & MyID

5, error not checking variable value
-----------------------------------------
Sql= "SELECT * from [user] where id=" & MyID
Rs.Open sql,conn,1,1
-----------------------------------------
Assuming the myID variable is null at this time, then SQL becomes
Sql= "SELECT * from [user] where id="
Solve:
Add in front
If IsNull (MyID) then error prompt

6, error not checking variable value type
-----------------------------------------
Sql= "SELECT * from [user] where id=" & MyID
Rs.Open sql,conn,1,1
-----------------------------------------
Assuming the ID is numeric, the myID variable is not NULL at this time, but is a character, such as myID at this time as "AA"
Then SQL will become
Sql= "SELECT * from [user] where Id=aa"
Solve:
Add in front
If IsNumeric (MyID) =false then error prompt

This can also be an effective way to prevent SQL injection vulnerabilities.

7, due to NTFS permissions on the directory where the database files are located, ' cannot be updated. Database or object is read-only error.
Description
The Win2K system extends NTFS permissions on the WINNT system.
There are default security settings for folders in the system.
The system default user for WWW access through HTTP is the IUSR_ computer name user, which belongs to the guest group.
When accessed over HTTP, you can modify the data either by ASP or JSP, or by PHP or. NET programs:
Like what:
When opening an article, the program set, the article read the number of times = original reading +1
Perform
Conn.execute ("Update arts set clicks=clicks+1 where Id=n")
Statement, an error occurs if the IUSR_ computer name user does not have write access to the database.
Workaround:
Locate the directory where the database resides
Right Key Properties Security tab set the Write permission for the IUSR_ computer name (or everyone, of course)



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.