ASP Error 컬렉션

ASP Error 컬렉션


@ . 속성
. Count : 컬랙션에 저장된 에러 개체들의 개수를 나타낸다 .
. Item : 이름이나 인덱스를 사용해서 특정 에러 개체를 접근하게 한다.
@ . 메소드
. Clear : 컬렉션 내의 모든 에러 개체들을 지운다.
. Refresh : 에러 내역을 갱신한다

  • 에러 개체의 정리
    . Description : 에러의 내용 설명
    .HelpContext : 에러의 관련 도움말 파일의 ContextID값
    . HelpFile : 도움말 파일의 이름
    . NativeError : 발생한 에러에 대한 특정 Provider의 에러코드
    . Number : 각 에러의 식별값, 에러넘버
    . Source : 에러를 발생시킨 개체나 어플리케이션의 이름
    . SQLState : 발생한 여러 개체에 대한 SQL 문장

ex 1 )

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<%
Option Explicit
Dim Con
Dim objError
Dim strConnect, sql, i
Response.Buffer = false
strConnect = "Provider=SQLOLEDB.1;Data Source=TAEYO;User ID=sa;Password="
On Error Resume Next
'에러가 나면 일단 무시하고 에러의 처리를 밑에서 한다
set Con = Server.CreateObject("ADODB.Connection")
Con.Open strConnect
Con.DefaultDatabase = "pubs"
sql = "Update titles Set prices = origin_price * 1.2"
Con.Execute sql
if Err.number<>0 then ' 에러넘버가 0이 아닐때
Response.Write "<b>에러 발생 건수 : "&Con.Errors.Count&" 회</b><p>"
'에러의 카운터를 한다
For i =0 to Con.Errors.Count - 1
'컬렉션 타입이라 루프문을 For문의 값으로 돌릴수 있다
Set objError = Con.Errors.item(i)
'에러의 내용을 담는다
Response.Write "각 에러의 세부내역이다.<br>"
Response.Write "에러 번호 : "&objError.number&"<br>"
Response.Write "에러 출처 : "&objError.Source&"<br>"
Response.Write "OLEDB 에러번호 : "&objError.NativeError&"<br>"
Response.Write "에러 메시지 : "&objError.description&"<p>"
next
End if
Con.Close
Set objError = nothing
Set Con = nothing
%>

ex 2)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<%
Option Explicit
Dim Con
Dim objError
Dim strConnect, sql, i
Response.Buffer = false
strConnect = "Provider=SQLOLEDB.1;Data Source=TAEYO;User ID=sa;Password="
On Error Resume Next
set Con = Server.CreateObject("ADODB.Connection")
Con.Open strConnect
Con.DefaultDatabase = "pubs"
sql = "Update titles Set prices = origin_price * 1.2"
Con.Execute sql
if Err.number<>0 then
Response.Write "에러 발생 건수 : "&Con.Errors.Count&" 회<p>"
For i =0 to Con.Errors.Count - 1
Set objError = Con.Errors.item(i)
Response.Write "에러메시지 : "&objError.description&"<br>"
next
End if
Con.Close
Set objError = nothing
Set Con = nothing
%>
Share