Diễn Đàn » Hướng Dẫn Lập trình

Tham khảo nhanh ASP

22 trả lời, 1.627 lượt xem — Trang 1 / 1
ASP là một ngôn ngữ lập trình web động, hiện nay - đang cùng với PHP - là một ngôn ngữ lập trình web phổ biến và mạnh.
Mời các bạn cùng tham khảo một tài liệu mình tìm được trên mạng (đây chỉ là tài liệu tham khảo thôi, muốn học cho đến nơi đến chốn thì cần phải nghiên cứu rất nhiều nữa)

1. Đặc điểm:
Tên file: .asp
Phải cài thêm Microsoft Active Server Page để bổ trợ cho Web Server, chuyên xử lý các script viết trong file .asp. Cho phép viết ứng dụng theo kiểu Server Side => các trang web sẽ sẽ được xử lý tại Server trước khi gửi xuống Client.
Các mã lệnh được chèn vào trong khắp trang web và được xử lý tuần tự. Mã lệnh là các Script, hiện ASP cho phép dùng 2 srcript là VBScript hoặc JavaScript. Lựa chọn Script được đặt ngay tại dòng đầu file:
<%@LANGUAGE = “VBSCRIPT”%>
<%@LANGUAGE = “JSCRIPT”%>
Ngầm định là VBScript.
Các đoạn mã không phân biệt dài ngắn được đặt trong dấu hiệu: <% %>
Các biến không cần khai báo mà tự khi gán giá trị cho nó sẽ xác định biến.
Để in ra các biến trong trang web sử dụng như mã sau:
<% =s %>
Để làm việc với hệ thống file, thao tác với Database... => cần phải sử dụng các đối tượng kiểu Active X của ASP hay cài đặt thêm vào.
Để lấy các giá trị truyền từ client lên dùng phương thức request.
Ex: s = request(“Company”)
=> Lấy giá trị của biến Company.

Chán đời đi lang thang !
Đăng nhập để trả lời
0
2. Sử dụng các đối tượng:

ASP cho phép sử dụng các đối tượng kiểu Active X. Để khai báo ta dùng phương thức CreateObject của đối tượng Server có sẵn.
Ex: Set f = Server.CreateObject(“Scripting.FileSystemObject”);
Tổng quan: Set param = Server.CreateObject(“PacketName.ClassName”)

ProgID
Sau đó có thể sử dụng các hàm của đối tượng đó.
Để giải phóng dùng Set f = nothing
Chán đời đi lang thang !
Đăng nhập để trả lời
0
3. Truy nhập hệ thống file:
<%
Dim objFile
Dim objStream
Set objFile = Server.CreateObject(“Scripting.FileSystemObject”);
Set objStream = objFile.OpenTextFile(Server.Mapath(“/ASP”) &_
“\Chapter05\Listing 5-9\tips.txt”)
Randomize Timer
IntLine = Int(Rnd*19)
For i=0 to intLine
ObjStream.SkipLine
Next
StrTxt = objStream.ReadLine
ObjStream.Close
Set objFile= Nothing
Set objStream= Nothing
%>
=> Để tạo file mới dùng phương thức CrateTextFile của objFile.
Để ghi một dòng văn bản dùng objStream.WriteLine s.

Chán đời đi lang thang !
Đăng nhập để trả lời
0
4. Truy nhập cơ sở dữ liệu:

<%
Dim objConnection
Set objConnection = Server.CreateObject(“ADODB.Connection”)
ObjConnection.Open “Publication”, ”sa”, “”
Dim objRecordSet
Set objRecordSet = Server.CreateObject(“ADODB.RecordSet”)
ObjRecordSet.Open “Select pub_name From Publishers”, objConnection
%>

Đối tượng kiểu Connection: tạo kết nối ADO tới Database.

Đối tượng kiểu RecordSet: cho phép thao tác trên table (select,update ...) của Connection đã thiết lập.
<% Do While Not objRecordSet.EOF %>
<% = objRecordSet(“pub_name”)%>
<% objRecordSet.MoveNext
Loop
ObjRecordSet.close
ObjConnection.close
Set objRecordSet = nothing
Set objConnection = nothing %>
Chú ý: khi thêm, cập nhật dữ liệu ngoài việc dùng SQL, có thể thêm theo cách :
With objRecordSet do
.AddNew
.Field(”Authors”) = “Homes”
. Field(”Title”) = “Iliad”
.Update
End With

Có thể kết nối trực tiếp không qua DSN của ODBC như sau :

<%
Set objConnection = Server.CreateObject(“ADODB.Connection”)
StrCnn = “driver = {SQL Server}; Server = smas; uid = sa; pwd= ; database= pubs”
objConnection.Open strCnn
%>

Chán đời đi lang thang !
Đăng nhập để trả lời
0
5. Phân trang RecordSet
Khi select => cho kết quả 1 bảng gồm nhiều hàng. Tuy nhiên mỗi lần chỉ muốn sử dụng một vài hàng, ví dụ: bảng 50 hàng, mỗi lần hiển thị 10 hàng => sử dụng kỹ thuật paging. ADO cung cấp các thuộc tính của Recordset như: PageSize, PageCount, AbsolutePage.
PageCount: số trang, PageSize: số hàng.
ở đây ta dùng biến session CurrentPage để ghi nhận trang hiện hành.
<% Select Case Request.QueryString(“Direction”)
Case “” ‘Null
Session(“CurrentPage”) = 1
Case “Next”
Session(“CurrentPage”) = Session(“CurrentPage”) + 1 Case “Previous”
Session(“CurrentPage”) = Session(“CurrentPage”) - 1
End Select %>
ü Chú ý: Request.QueryString(“Direction”) <=> QueryString(“Direction”)
Tiến hành kết nối truy vấn dữ liệu.
<%
const adOpenKeySet = 1
dim objConnection không cần khai báo cũng được
dim objRexordset
Set objConnection = Server.CreateObject(“ADODB.Connection”)
Set ObjConnection.Open “Biblio”, “”, “”
Dim strSQL
StrSQL = “Select * from Authors”
Set objRecordSet = Server.CreateObject(“ADODB.RecordSet”)
ObjRecordSet.PageSize = 10
ObjRecordSet.Open strSQL, objConnection, adOpenKeyset
ObjRecordSet.AbsolutePage = CLng(Session(“CurrentPage”))
%>
<P> Page = <%=Session(“CurrentPage”) %> of <%=ObjRecordSet.PageCount>
<% Dim i
For i = 1 to ObjRecordSet.PageSize %>
<% = ObjRecordSet(“Authors”) %>
...
<% ObjRecordSet.MoveNext
Next %>
<% if CLng(Session(“CurrentPage”)) < ObjRecordSet.PageCount Then %>
<P> <A HREF = “paging.asp?Direction=Next”>Next Page</A></P>
<%Enf if%>
<% If CLng(Session(“CurrentPage”)) > 1 then %>
<P><A Href = “paging.asp?Direction=Previous”>Previous Page</A></P>
<%Enf if%>
<% ObjRecordSet.close
ObjConnection.close
Set objRecordSet = nothing
Set objConnection = nothing %>

Chán đời đi lang thang !
Đăng nhập để trả lời
0
6. Đối tượng Application:
Đối tượng này cho phép tạo các biến ứng dụng. Đó là các biến cho tất cả các user của một ứng dụng web. Tất cả các user mà yêu cầu các trang web từ một thư mục web có thể chia xẻ với nhau các biến định nghĩa trong các trang đó.
<% Application.Lock
Application(“Company”) = “VASC”
Application.Unlock %>
ở đây định nghĩa 1 biến là Company, có giá trị là VASC. Vì rằng biến có thể bị tranh chấp nên phải đặt giữa Lock và Unlock.
<% Application.Lock
Application(“Time”) = Now
Application.Unlock %>

Chán đời đi lang thang !
Đăng nhập để trả lời
0
7. Đối tượng Session:
Cho phép tạo ra các biến ứng với từng người dùng. Chẳng hạn biến có tên là UserName, ứng với mỗi user có một giá trị cụ thể khác nhau, phân biệt. Nhưng khi sử dụng thì tổng quát cho các user. Thực ra mỗi biến sẽ được server phát sinh và gán cho nó một giá trị định danh GUID (Globally Unique Identifier, 128 bit) và gửi tới Browser. Browser sẽ lưu trữ GUID đó và sử dụng để yêu cầu dữ liệu từ biến có GUID tương ứng trên Server.
<% Session(“Company”) = “NewTech”
Session(“Email”) = “leha@hotmail.com” %>
My Company : <% Session(“Company”) %>
Email : <% Session(“Email”) %>
Các biến Session này sẽ bị huỷ bỏ sau một khoảng thời gian (khoảng 20’) người dùng thôi truy xuất các trang web trong thư mục web.
Chú ý là trong file global.asa => cho pháp đặt các biến, code vào các thủ tục Session_OuStart và Session OuEnd. Ví dụ:
<SCRIPT LANGUAGE = VBScript RUNAT = Server>
Sub Session_OuStart
Session(“Company”) = “VASC”
Session(“Email”) = “thanhha@vasc.vnn.vn”
End sub
</SCRIPT>

Chán đời đi lang thang !
Đăng nhập để trả lời
0
8. Đối tượng Request:
Để gửi dữ liệu lên Server, ta sử dụng Form trong trang Web. Tên của các đồi tượng web như Text, Button nằm trong form sẽ được dùng như tên biến khi phân tích, lấy dữ liệu trên Server. Trong form có button kiểu Submit để người dùng đẩy dữ liệu lên Server.
Form có hai thuộc tính là Action và Method. Action quy định file (.asp) mà sẽ đón nhận và xử lý dữ liệu đẩy lên. method quy định cách thức gửi dữ liệu; nếu là POST thì tất cả dữ liệu trong form sẽ đóng gói và đẩy lên Server; Nếu là GET thì dữ liệu được gửi đi như một phần của URL, thường là sau dấu “?”.
<Form Method = “POST” Action = “http://www.vnn.vn/data.asp”>
Kiểu gửi dữ liệu GET cũng có thể lợi dụng để gửi đi dưới dạng một link.
< A href =
“ http://www.vnn.vn/data.asp?name=ha&company=VASC” >Test</a>
Gửi theo GET thì độ lớn bị hạn chế và không che dấu dữ liệu.
Để lấy dữ liệu ta dùng phương thức của đối tượng Request.
S = Request.Form(“Name”)
<=> S = Request(“Name”)
Trong trường hợp dữ liệu được đưa lên từ 1 hyperlink, có thể dùng:
S = Request.QueryString(“Name”)
<=> S = Request(“Name”)
Đối tượng Request cũng cho phép lấy giá trị các biến môi trường như LOGON_USER, HTTP_USER_AGENT, ví dụ:
Request.ServerVariables(“LOGON_USER”)
Request.ServerVariables(“HTTP_USER_AGENT”)

Chán đời đi lang thang !
Đăng nhập để trả lời
0
9. Đối tượng Reponse:
Đối tượng này quản lý tất cả dữ liệu, nội dung sẽ được gởi cho Browser từ ASP.
<% = Company%>
<=> <% Reponse.Write Company %>
Reponse cung cấp 1 thuộc tính là Expires, quy định thời gian (phút) mà trang Web chứa trong cache của IE. Vậy, nếu đặt dòng <% Response.Epires = 0 %> thì trang Web sẽ không chứa trong cache của IE.
Chán đời đi lang thang !
Đăng nhập để trả lời
0
10. Đối tượng Server:
Đối tượng Server cung cấp hàm CreateObject, để tạo ra các đối tượng (instance) của Active X. Tham số truyền vào là ProgID (Program Identifier) của Component cần tạo instance.
Set MyObject = Server.CreateObject(“Mail.Connector”)
Đoạn mã sau in ra các biến Server :

< % For each name in Request.ServerVariables %>
<% = name %> <% = Request. ServerVariables(name) %>
<% Next %>

Chán đời đi lang thang !
Đăng nhập để trả lời
0
11. File Global.asa:
ứng dụng web = tập các trang Web, asp trong một thư mục web và các thư mục con.
File Global.asa xác định khởi đầu và kết thúc của một ứng dụng web cũng như của các session của từng user đơn thể đối với ứng dụng.
File này cho phép đặt 4 thủ tục vào: Session_OnStart, Session_OnEnd,
Application_OnStart, Application _OnEnd.
Session_OnStart: thực hiện lần đầu tiên khi có một user yêu cầu trang web trong ứng dụng. (ứng với user đó)
Session_OnEnd: thực hiện khi user thoát khỏi ứng dụng hoặc timeout.
Application_OnStart: thực hiện 1 lần khi trang web đầu tiên của ứng dụng được chạy lần đầu tiên bởi bất kỳ user nào.
Application _OnEnd: thực hiện một lần khi web server shutdown hoặc khi tất cả các session đã đóng.

Chán đời đi lang thang !
Đăng nhập để trả lời
0
12. Các phương thức và thuộc tíinh của một số đối tượng:
Reponse:
· Collection: Cookies, form, ChentCertificates, QueryString, ServerVariables
· Properties: Buffer, Charset, ContentType, Expires, ExpiresAbsolute, IsClientConnectied, Status, Pics, TotalByte.
· Method: AddHeadder, AppendToLog, BinaryWrite, Clear, End, Flush, Redirect, Write, BinaryRead.
Server
· Properties: ScriptTimeout
· Method: CreateObject, HTMLEncode, MapPath, URLEncode.
Application
· Collection: Contents, StaticObject.
· Method: Lock, Unlock
· Events: Application_OnStart, Application _OnEnd.
Session
· Collection: Contents, StaticObject.
· Method: Abandon
· Properties: SessionID, TimeOut, CodePage, LCID
· Events: Session_OnStart, Session_OnEnd

Chán đời đi lang thang !
Đăng nhập để trả lời
0
13. Sử dụng Cookies:
Dùng đối tượng Request để nhận giá trị Cookies.
Dùng đối tượng Reponse để đặt giá trị Cookies.
Cookie có thể chỉ một giá trị, nếu nhiều giá trị thì phải dùng nhiều key.
Ex:
<% Reponse.Buffer = True %>
<% Dim dLastVisited
dLastVisited = Request.Cookies(“LastVisit”)
If dLastVisited = Empty Then
Reponse.Write “Welcome! This is your first visit”
Else
Reponse.Write “Welcome Back! <BR>”
Reponse.Write “Your last visited on” & dLastVisited
End If
Reponse.Cookies(“LastVisit”) = Now()
Reponse.Cookies(“LastVisit”).Expires = “December 31,2000”
Session.Abandon %>
Session.Abandon thoát khỏi session, không còn lại biến session nào.

Chán đời đi lang thang !
Đăng nhập để trả lời
0
14. Gọi Stored Procedure trong ASP
<% Set Cnn1 = Server.CreateObject(“ADODB.Connection”)
StrCnn = “driver = {SQL Server}; Server = smas; uid = sa; pwd= ; database= pubs”
Cnn1.Open strCnn
Et sp = CreateObject(“ADODB.Command”)
Set sp.ActiveConnection = Cnn1
Sp.CommandType = adCmdStoredProc
Sp.CommandText = “sp_Help”
Set pm = sp.CrateParameter(“objname” = 200, 1, 92, “authors”)
Sp.parameters.Append pm
Set rs = sp.Excute()
Do Until rs is Nothing
Reponse.Write “<Table border = 1 bgColor = White><TR>”
Call PrintHeadings
Call PrintAllRecordsInRS
Reponse.Write “</Table><BR><BR>”
Set rs=rs.NextRecordSet
Loop
Call CleanUp %>
<% Sub PrintHeadings()
For each hdFld in rs.Fields
Reponse.Write “<TH>” & hdFld.Name & “</TH>”
Next
Reponse.Write “<TR>”
End sub
Sub printAllRecordsInRS()
Do until rs.EOF
For each fld in rs.Fields
Reponse.Write “<TD>” & fld
Next
Reponse.Write “<TR>”
Rs.MoveNext
Loop
End Sub
Sub CleanUp()
Set rs = nothing
Cnn1.Close
Set Cnn1 = nothing
End sub %>

Tóm lại các bước thực hiện:
- Tạo một kế nối Connection, active nó.
- Tạo đối tượng kiểu Command, gán nó với một Connection đã kích hoạt (thuộc tính ActiveConnection), CommandText: tên thủ tục;
- Tạo ta đối tượng tham số, bằng phương thức CreateParameter để truyền tham số cho thủ tục.
- Thực thi và sử dụng kết quả.

Chán đời đi lang thang !
Đăng nhập để trả lời
0
15. Các hàm VBScript (1.0)

Abs Asc Atn Cbool
Cbyte Ccur Cdate CDbl
Chr Clnt Cos Csng
Cstr Date DateSerial DateValue
Day Exp Fix Hex
Hour InputBox InStr Int
IsArray IsDate IsEmpty IsNull
IsNumeric IsObject LBound Lcase
Left Len Log LTrim
Mid Minute Month MsgBox
Now Oct Right Rnd
Rtim Second Sgn Sin
Space Sqr StrComp Tan
Time TimeSerial TimeValue Trim
Ubound Ucase VarType Weekday
Year

Chán đời đi lang thang !
Đăng nhập để trả lời
0
16. Gửi mail
Gửi mail theo giao thức SMTP
Dim objNewMail
Set objNewMail = Server.CreateObject(“CDONTS.NewMail”)
ObjNewMail.send sFromName, sToName, sSubject, sMsg
Set objNewMail = nothing

17.Các lệnh ASP và VBScript (1.0)

Call Dim Do... loop Empty
Erase Exit False For... next
If... then... Else Nothing Null On Error
Option Explicit Randomize Redim Rem
Select case Set Sub True
While...wend

Chán đời đi lang thang !
Đăng nhập để trả lời
0
18. Các hằng (2.0)

Color Comparion Date and Time
Date format File Input/Output Miscellaneous
Msgbox String Var type

19. Các hàm:

Array Create Object DateAdd
DateDiff DateParl Filter
FormatCurrency FormatDatetime FormatNumber
FormatPercent GetObject InstrRev
Join LoadPicture MonthName
Replace RGB Round
ScriptEngineMajorVersion ScriptEngineBuilVersion ScriptEngine
ScriptEngineMinorVersion Split StrReverse
TypeName WeekDayName

Chán đời đi lang thang !
Đăng nhập để trả lời
0
20. Các đối tượng và hàm: (version 2.0)
Object: Dictionary; FileSystemObject; TextStream
Method:
Add Close CreateTextFile
FileExists Items Key
OpenTextFile Read ReadAll
ReadLine Remove RemoveAll
Skip SkipLine Write
WriteBlankLines WriteLine

Các properties:
AtEndOfLine AtEndOfStream Column
CompareMode Count HelpContext
HelpFile Item Key
Line

Các lệnh:
Const Private
For each... Next Public

Chán đời đi lang thang !
Đăng nhập để trả lời
0
21. Đối tượng Error: (1.0)
Properties: Decription, Number, Source
Method: Clear, Raise

22. VBScript 3.0
ü Collection: Drives, Files, Folders
ü Constant: DriveType, SpecialFolder, File Attribute
ü Properties:
Attributes FileSystem ShareName
AvailableSpace FileSpace ShortName
DateCreated IsReady ShortPath
DateLastAccessed IsRootFolder Size
DateLastModified Name SubFolder
Drive ParentFolder TotalSize
DriveLetter Path Type
Drives RootFolder VolumeName
DriveType SerialNumber
Files

ü Method:
AddFolder BuildPath Copy
CopyFile CopyFolder CreateFolder
Delete DeleteFile DeleteFolder
DriveExists FileExists FolderExist
GetAbsolutePathName GetBaseName GetDrive
GetDriveName GetExtensionName GetFile
GetFileName GetFolder GetParentFolderName
GetSpecialFolder GetTempName Move
MoveFile MoveFolder OpenAsTextStream

Chán đời đi lang thang !
Đăng nhập để trả lời
0
23. Sử dụng Transaction:
Các yêu cầu:
· Dòng đầu tiên phải là: <% @TRANSACTION = REQUIRED%>
· Có thể điều chỉnh chấp nhận hoặc huỷe bỏ giao dịch bằng cách dùng SetComplete anh SetAbort từ đối tượng ObjectContext.
· Nếu giao dịch thành công (commited), hàm sự kiện OnTransacton_Commit() được thực thi.
· Nếu giao dịch thất bại (Aborted), sự kiện OnTransacton_Abort được thực thi.
· Yêu cầu MSDTC (Distributed Transaction Coordinator)

Ví dụ 1:
<% @TRANSACTION = REQUIRED language = “VBSCRIPT”%>
<HTML><HEAD><TITLE> Transaction Demo</TITLE> </HEAD><BODY>
This is Demostration of using transaction with HTML. <BR> For this example to work, MSDTC must be running on the web Server. <BR>
This next line will genegate an error.
<% set x = boo.boo %>
<BR> Does this line print ? </BODY> </HTML>
<%
Sub OnTransacton_Abort()
Reponse.Write “<BR><B> Error detected. Attemting to Recover</B>”
‘Place Error handling code here
End Sub

Sub OnTransacton_Commit()
Reponse.Write “<BR><B>Congratulations! The transaction was commited </B>”
End sub %>

Ví dụ 2:
<% @TRANSACTION = REQUIRED%>
<% Reponse.Buffer = True
Set oCustomer = Server.CreateObject(“ExplorationAir.Customer”)
Mites = 6000
Session(“CustomerID”) = oCustomer.Create(cStr(Session(“Lastname”)),
cStr(Session(“Firstname”)), cStr(Session(“Password”)),
cStr(Session(“Street”)), cStr(Session(“City”)),
cStr(Session(“State”)), cStr(Session(“Zip”)),
cStr(Session(“Email”)), Miles)
On error Resume next
FFComponent = Application(“FrequentFlyerComponent”) + “.FrequentFlyer”
Set oFrequentFlyer = Server.CreateObject(“FFComponent”)
‘This prevents an eror if the FrequentFlyer component isn’t installed
If NOT oFrequentFlyer is Nothing Then
‘Add registration bonus points
oFrequentFlyer.Create clng(Session(“CustomerID”)),
clng(Session(“CustomerID”)),
“Registration”, “None”, clng(Miles)
End if
Function OnTransactionCommit()
Response.Clear
Response.Redirect(“RegisterSuccess.asp”)
Response.Flush()
End Function

Function OnTransactionAbort()
Response.Write “Error!” + “Error Code =” + cStr(err.Number)
Response.Write “Error Source: “ + cStr(err.Source)
End Function
%>

Chán đời đi lang thang !
Đăng nhập để trả lời
0
24. Sử dụng biến Application:
Dùng đối tượng Application để tạo ra các biến kiểu Application. Những biến kiểu này là toàn cục đối với 1 ứng dụng Web cho tất cả các user, được duy trì kể cả khi stop web server.
Giả sử file a.asp có đoạn mã:
<%
If IsObject(Application(“TestConn”)) Then
Set oConn = Application(“TestConn”)
sSQL = “Select * from Products where ProductID < 5”
Else
Set oConn = Server.CreateObject(“ADODB.Connection”)
OConn.Open “TestODBC”, “”, “”
Set Application(“TestConn”) = oConn
sSQL = “Select * from Products where ProductID > 20”
End if
Set RS = Server.CreateObject(“ADODB.RecordSet”)
RS.open sSQL, oConn, 3, 3
%>
Khi trang này (a.asp) được truy xuất lần đầu tiên thì biến Application là TrstConn được tạo ra. Kể từ giờ tất cả các file .asp của ứng dụng này có thể sử dụng biến TestConn.
ð Đoạn mã sau của b.asp hoạt động:
<% Set oConn = Application(“TestConn”)
...
RS.Open sSQL, oConn, 3, 3
%>

*/ Để huỷ một biến Application: set Application(“TestConn”) = nothing

Chán đời đi lang thang !
Đăng nhập để trả lời
0
25. Sử dụng biến Session:
Giống như các biến Application, nhưng chỉ có phạm vi trong 1 session. Chú ý: 1 session chỉ trong một phiên làm việc giữa browser với web server. Nếu đóng browser lại thì các biến session mất đi. Biến session cũng có giá trị toàn cục trong 1 ứng dụng web ứng với mỗi user.
<%

If IsObject(Session(“TestConn”)) Then
Set oConn = Session (“TestConn”)
Else
Set oConn = Server.CreateObject(“ADODB.Connection”)
OConn.Open “TestODBC”, “”, “”
Set Session(“TestConn”) = oConn
End if
%>

26. Chèn file (Include)
Để include file sử dụng cú pháp:
<!--#include file = “a.asp”>

Chán đời đi lang thang !
Đăng nhập để trả lời
0
27. Khai báo biến trong global.asa
Các biến cũng phải ở dạng biến Application hoặc biến Session. Có thể đặt vào một đoạn bất kỳ hoặc trong các thủ tục Application_OnStart, Session_OnStart, giải phóng biến ở Application_OnEnd hoặc Session_OnEnd
Ex: đoạn mã sau đặt trong thủ tục Application_OnStart
Sub Application_OnStart
Set oConn = Server.CreateObject(“ADODB.Connection”)
OConn.Open “MyTest”, “”, “”
Set Application(“oConnection”) = oConn
End sub

Và trong thụ tục Application_OnEnd
Sub Application_OnEnd
OConn.Close
Set oConn = nothing
Set Application(“oConnection”) = nothing
End sub
Trong 1 file asp khác, ta có thể sử dụng lại
Set RS = Server.CreateObject(“ADODB.RecordSet”)
RS.Open sSQL, Application(“oConnection”), 3, 3



Chán đời đi lang thang !
Đăng nhập để trả lời
0