Microsoft MVP성태의 닷넷 이야기
[답변]: [답변]: [답변]: [답변]: ASP 의 ByVal 과 ByRef 특성 [링크 복사], [링크+제목 복사],
조회: 10568
글쓴 사람
장윤태
홈페이지
첨부 파일
 
부모글 보이기/감추기

저기 질문 올린사람인데요 ^^; 좀 의문가는 점이 있어서요

아래 함수들은 제가 디버깅 할때 쓰는건데요. 다른거와 섰여있습니다.

두가지 상황에 따라서 결과가 틀려서요? 초보라서 잘모릅니다. 위에글 읽기도 힘들어요;; ㅠㅜ

◆참고
asp 에서 사용되는 db 핸들입니다

◆소스

 - ▲함수 1
     '필드명과 값만확인할대 :: 개발용
    Function RunSQLReturnGR_fieldName(strSQL,maxLength)
        On Error Resume Next

        Dim Rs , Cmd
        Set Rs = Server.CreateObject("ADODB.Recordset")
        Set Cmd = Server.CreateObject("ADODB.Command")

        Cmd.ActiveConnection = Conn
        Cmd.CommandText = strSQL
        Cmd.CommandType = adCmdText
        Cmd.Prepared = True

         Rs.CursorType = adOpenForwardOnly
         Rs.CursorLocation = adUseClient
         Rs.LockType = adLockReadOnly
         Rs.Open Cmd

        Call ViewParam(Cmd,maxLength)

        Set Cmd = Nothing

        If Err.Number <> 0 Then
            Call errorLog_write("RunSQLReturnGR_fieldName",strSQL)
        End if
    End function

 - ▲함수 2
    '레코드셋 필드명과 내용함께 출력하기(아웃풋용) :: 개발용
    Sub ViewParam(byref objCmd,maxLength)
        'On Error Resume Next

        Redim strOutputParamName(objCmd.Parameters.Count) , execStr(objCmd.Parameters.Count)
        Dim param , i , j
        i = 0 : j = 0

        If maxLength = true Or maxLength = false Then
            If objCmd.CommandType = adCmdStoredProc Then
                Response.Write "<table border=1><tr><td><b>속성</b></td><td><b>값</b></td><td><b>사이즈</b></td><td><b>입력타입</b></td><td><b>변수타입</b></td><td><b>정밀도</b></td></tr>"
                For Each Param In objCmd.Parameters
                    If Param.Name <> "@RETURN_VALUE" Then
                        If (GetParameterDirectionEnum(Param.Direction) = adParamOutput) OR (GetParameterDirectionEnum(Param.Direction) = adParamInputOutput) Then
                            strOutputParamName(j) = Param.Name
                            execStr(i) = "''"
                            j = j + 1
                        Else
                            execStr(i) = "'"& Param.Value &"'"
                            Response.Write "<tr><td><font color=orange>"& i &"번째 "& Param.Name &"</font></td><td>"& Param.Value &"</td><td>"& Param.Size &"</td><td>"& GetParameterDirectionEnum(Param.Direction) &"</td><td>"& GetDataTypeEnum(Param.Type) &"</td><td>"& Param.Precision &"</td></tr>"
                        End if
                        i = i + 1
                    End if
                Next

                Response.Write "<tr><td colspan=6><font color=red><b>아웃풋</b></font></td>"
                For j = 0 To j - 1
                    Response.Write "<tr><td><font color=orange>"& j &"번째 "& strOutputParamName(j) &"</font></td><td>"& objCmd.Parameters(strOutputParamName(j)).Value &"</td><td>"& objCmd.Parameters(strOutputParamName(j)).Size &"</td><td>"& GetParameterDirectionEnum(objCmd.Parameters(strOutputParamName(j)).Direction) &"</td><td>"& GetDataTypeEnum(objCmd.Parameters(strOutputParamName(j)).Type) &"</td><td>"& objCmd.Parameters(strOutputParamName(j)).Precision &"</td></tr>"
                Next
                Response.Write "<tr><td colspan=6><font color=red><b>프로시저 실행문</b></font></td></tr>"
                Response.Write "<tr><td colspan=6><font color=orange>Exec "& Mid(objCmd.CommandText, Instr(objCmd.CommandText,"call ")+5 , Instr(objCmd.CommandText,"(") - (Instr(objCmd.CommandText,"call ")+5) ) &"</font> "& arrFormat(execStr,","," ") &"</td></tr>"
                Response.Write "</table><br>"
            End if
        End if

        Dim Rs
        Set Rs = Server.CreateObject("ADODB.RecordSet")

        Rs.CursorType = adOpenForwardOnly
        Rs.CursorLocation = adUseClient
        Rs.LockType = adLockReadOnly
        Rs.Open objCmd

        Response.Write Rs_fieldName(Rs,maxLength)

        If objState(Rs.State) = "adStateOpen" Then <=================== 이 부분
            Rs.Close
            Set Rs = Nothing
        End if

        If Err.Number <> 0 Then
            Call errorLog_write("ViewParam",Mid(objCmd.CommandText, Instr(objCmd.CommandText,"call ")+5 , Instr(objCmd.CommandText,"(") - (Instr(objCmd.CommandText,"call ")+5) ))
            Set objCmd = Nothing
        Else
            Set objCmd = Nothing
        End if
    End Sub

 - ▲함수 3
    '레코드셋 필드명과 내용함께 출력하기 :: 개발용
    Function Rs_fieldName(objRecordSet , maxLength)
        Dim Field , tempStr , i , j , k
        If maxLength = false Then
            Exit function
        End if
        tempStr = ""

        Dim objRecordSet_temp
        Set objRecordSet_temp = objRecordSet

        Do Until objRecordSet_temp Is nothing
            i = 0 : j = 0 : k = 0
            tempStr = tempStr &"<table border=1><tr>"
            For Each Field in objRecordSet_temp.Fields
                tempStr = tempStr &"<td><b>"& Field.name &" <br><font color=red>"& i &"열</font></b></td>"
                i = i + 1
            Next
            tempStr = tempStr &"</tr>"

            If objState(objRecordSet_temp.State) = "adStateClosed" Then
                tempStr = tempStr &"</table>"
                Rs_fieldName = tempStr
                Exit function
            End if

            If objRecordSet_temp.Eof OR objRecordSet_temp.Bof Then
                tempStr = tempStr &"<tr><td colspan="& i &"><b>결과없음</b></td></tr>"
            Else
                Do Until objRecordSet_temp.Eof
                    tempStr = tempStr &"<tr>"
                    For Each Field in objRecordSet_temp.Fields
                        tempStr = tempStr &"<td valign=top><font color=orange>"& j &"행 "& k &"열</font><br><br>"& Field &"</td>"
                        k = k + 1
                    next
                    tempStr = tempStr &"</tr>"
                    objRecordSet_temp.MoveNext
                    j = j + 1
                    k = 0
                    If isNumeric(maxLength) Then
                        If Cint(j) = Cint(maxLength) Then Exit do
                    End if
                Loop
                objRecordSet_temp.MoveFirst
            End if
            tempStr = tempStr &"</table><br><br>"

            Set objRecordSet_temp = objRecordSet_temp.NextRecordset
        Loop
        Rs_fieldName = tempStr
    End function


 - ▲함수 4

'레코드셋 필드명과 내용함께 출력하기 :: 개발용
Function Rs_fieldName(byVal objRecordSet , maxLength)
    Dim Field , tempStr , i , j , k
    If maxLength = false Then
        Exit function
    End if

    tempStr = "<table cellpadding=0 cellspacing=0 border=1><tr>"
    i = 0 : j = 0 : k = 0
    For Each Field in objRecordSet.Fields
        tempStr = tempStr &"<td><b>"& Field.name &"</b><br><font color=red>"& i &"열</font></td>"
        i = i + 1
    Next
    tempStr = tempStr &"</tr>"

    If objRecordSet.State = 0 Then
        tempStr = tempStr &"</table>"
        Rs_fieldName = tempStr
        Exit function
    End if

    If objRecordSet.Eof Then
        tempStr = tempStr &"<tr><td colspan=100>자료가 없습니다</td></tr>"
    Else
        Do Until objRecordSet.Eof
            tempStr = tempStr &"<tr>"
            For Each Field in objRecordSet.Fields
                tempStr = tempStr &"<td valign=top><font color=orange>"& j &"행 "& k &"열</font><br><br>"& Field &"</td>"
                k = k + 1
            next
            tempStr = tempStr &"</tr>"
            objRecordSet.MoveNext
            j = j + 1
            k = 0
            If isNumeric(maxLength) Then
                If Cint(j) = Cint(maxLength) Then Exit do
            End if
        Loop
        objRecordSet.MoveFirst
    End if
    tempStr = tempStr &"</table>"

    Rs_fieldName = tempStr
End function



◆요약
rs 를 제가 원하는 식으로 출력후 rs 를 원상 복귀 시키는거조 그래서야 정상적인 값이 나올테니까요


◆질문 1
함수 1을 사용해서 결과를 출력하면 잘됩니다;;

그런데 함수 3을 사용하면
ADODB.Recordset error '800a0e78'
개체가 닫혀있으면 작업이 허용되지 않습니다.
ㅌㅌㅌㅌ.asp, line 591

그래서
함수 3대신 함수 4를 쓰면
잘됩니다;; 왜 그런걸까요?


sql = sql & "ORDER BY IDX DESC "

Function rs_open(sql)
Set rs = Server.CreateObject("Adodb.Recordset")
rs.open sql, db, 1
End Function

Call rs_open(sql)

'print dbs.RunSQLReturnGR_fieldName(sql,true) <--------------- 정상 ( 이건 새로운 rs 를 생성하니 그럴수도 있다 생각은 됩니다.)
'print Rs_fieldName(rs,true) <--------------- 정상(이건 왜 그럴까요?)
response.write dbs.rs_fieldName(rs,true) <--------------- 비정상

rs.pagesize = pSize
IntArecord = rs.recordcount <------ 이부분에서 요류가 나내요
IntApage = rs.pagecount

◆질문 2
더 이상한건 함수 3의 상화에 따라서 함수 2의 개체 처리 부분이 이상합니다. 아직 개념이 안서서 ^^

        If objState(Rs.State) = "adStateOpen" Then <=================== 이 부분
            Rs.Close
            Set Rs = Nothing
        End if


'        If Not(Rs is nothing) Then
'            Rs.Close
'            Set Rs = Nothing
'        End if

두개의 처리 구문이 서로 다른 결과를 나타 냅니다.













[최초 등록일: ]
[최종 수정일: 5/16/2007]


비밀번호

댓글 작성자
 




1  2  3  4  5  6  7  8  [9]  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
5730김재환10/7/20224739WPF에서 디스플레이 배율이 100%가 아닌 경우, Window의 포지션 정보가 부정확해지는 문제 [2]
5729김기헌10/2/20224404안녕하세요 선생님 뮤텍스 관련 질문 드립니다 [2]
5728김경환9/29/20224472그리드뷰관련마지막질문하나드리겠습니다선생님 [5]파일 다운로드1
5727김경환9/26/20224383c# 윈폼 tcp/ip 기반 데이터그리드뷰질문하나드리겟습니다 [3]
5726양승조 donator9/22/20225097C# dll 과 C++ 간 배열 전달. SafeArray [10]파일 다운로드1
5725김기헌9/21/20223975안녕하세요 선생님 윈폼 컨트롤 Dispose 관련 질문드립니다 [2]
5724감사합니...9/19/20224006스레드와 스레드 안전한 객체 사용관련 문의드립니다. [5]
5723드리렁9/13/20223935Pinned Object에 대해서 질문이 있습니다. [2]
5722김인태9/8/20224099대화상자에서 alt + tab 후킹 작업 [1]
5721우종9/7/20224267C++ DLL 과 C# 연동 문의 [2]
5720한예지 donator9/6/20223961학습 방법 질문 있습니다. [7]
5719김경한9/6/20224293안녕하세요 질문하나만드리겠습니다...! [10]
5718김민아9/2/20224357안녕하세요 생성자 호출 시 초기화 순서 질문드립니다 [2]
5716iili...8/26/20224518WinDbg 커널 디버깅에서의 thread freeze [2]
5715에릭8/19/20224939WMI 쿼리 결과값이 Windows Service와 Console 출력에서 상이한 이유가 있을까요? [9]파일 다운로드1
5714허니빠8/18/20224971.net6 hint path 를 프로젝트 단위로 지정할 수 있는 방법을 알고싶습니다 [8]
5713김기헌8/17/20224922안녕하세요 rgb 계산 오차가 있는데 원인을 모르겠습니다.. [3]
5712하태8/17/20224405안녕하세요 background service에서 user32dll 접근 질문 드리겠습니다.! [2]
5711하태8/16/20223913안녕하세요! 윈도우즈 해상도 관련 질문 드립니다. [1]
5710장성욱8/12/20224132c# 시리얼 통신 관련 질문 [3]
5709초보8/12/20223940WPF 커맨드 관련 질문 [2]
5708민성8/11/20224216안녕하세요 c#에서 화면의 배율 및 레이아웃을 변경할려면 어떻게 해야 할까요? [2]파일 다운로드1
5707민성8/10/20223852WPF 엣지 컨트롤에서 화면이 안보이는 현상 [2]파일 다운로드1
5706종규8/7/20226313WPF 에서 SVG 아이콘 사용 방법 문의 [2]
5705김기헌8/6/20224979안녕하세요 선생님 싱글톤 패턴 간단 질문 [2]
5704따봉이8/4/20224871EventHandler 관련 [1]
1  2  3  4  5  6  7  8  [9]  10  11  12  13  14  15  ...