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

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

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

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

◆참고
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)
5781List맨1/5/20234079List.Add("newobj") 속도는 빠른 편인지요? [11]
5780임세1/3/20234657C# 프로그래밍 10 책 구매한 사람입니다. 3부 자료는 어디서 다운 받을 수 있나요? [4]
5779이건우1/2/20233548안녕하십니까 루프안에서 메세지처리에 관하여 질문드립니다! [2]
5778이건우12/30/20224857안녕하세요 c#에서 dll참조 관련 질문드립니다. [4]
5777감사합니...12/29/20223830UI Thread에 Invoke 처리관련 궁금합니다. [3]
5776pdf맨12/28/20223617C# MouseUp Event + pdf [10]
5775민성12/28/20223392안녕하세요 Class 관련해서 예외처리를 하나로 받아낼수 있는 방법 [1]
5774중급12/27/20224214중급개발자란 어느 수준인지요? [4]
5773김영식12/26/20223700c# 압축파일 읽어 올 때 BinaryRead 한글 처리 문제 [1]
5772눈송이12/26/20223825Excel VSTO 는 왜 Net Core, Net 5, 6 버전을 사용하지 않나요? [2]
5771김훈12/26/20223919c# .net client application 망분리(내부망,외부망) 환경에서 의문의 외부사이트 호출 대기 [2]
5770lsh12/26/20223521클라우디움안에 있는 파일을 File.Copy 하고싶은데 코드로는 접근을 못하나요? [1]
5769울타리12/20/20223545Active Directory 2012R2 2016 또는 2019 마이그렝션 문의 드립니다. [1]
5768c++12/14/20224383Thread를 사용한 C++ DLL에 관련된 질문입니다. [6]파일 다운로드2
5767민성12/9/20223707안녕하세요 ashx로 화일을 저장하고 화일명을 리턴하는데요 [1]
5766김명훈12/9/20223840웹브라우저에서 묻지 않고 바로 다운로드 [2]
5765hong12/1/20224084Winform(.Net6) 클라이언트에서 SignalR Core 웹서버에 접속시 인증서 문제 [3]파일 다운로드1
5764요한11/30/20224230c++ 동일한 객체인지 비교 방법문의 [2]
5763고필석11/30/20223736시작하자마자 비정상 종료하는 프로세스에 대한 문제 해결 조언 요청 드립니다. [3]
5762흰털너부리11/30/20223745wpf mvvm ui update 로딩중 표시 [1]
5761민성11/29/20223676죄송하지만 한가지만 더 여쭈어 보겠습니다 [1]
5760민성11/29/20223606안녕하세요 [2]
5759문정환11/28/20223914c# socket 통신할때 빅엔디언으로 바꿔줘야 하나요? [1]
5758라떼11/28/20225193Linux 에서 winform UI 어플리케이션 실행하기 [3]
5757흰털너부리11/25/20224080asp.net core EF AddDbContext,AddDbContextFactory 차이점 알려주세요 [1]
5756흰털너부리11/25/20223703asp.net core web api에서 json 특정 property 무시하는 방법 문의 드립니다. System.Text.Json 사용중입니다. [1]
1  2  3  4  5  6  [7]  8  9  10  11  12  13  14  15  ...