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

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

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

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

◆참고
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]


비밀번호

댓글 작성자
 




... 46  47  48  49  50  51  52  [53]  54  55  56  57  58  59  60  ...
NoWriterDateCnt.TitleFile(s)
1339이소정10/28/201413626        답변글 [답변]: [답변]: filestream seek에 대해 질문있습니다. [2]파일 다운로드2
1335황지혜10/24/201414133psexec 관련 질문드립니다. [1]
1334dell10/24/201410488여기가 있는줄 모르고 방명록에 남겼네요 ㅠㅠ 방명록 한번만 봐주시면 안될지요? [1]
1333왕초보10/24/201411107Bitmap 질문 [5]
1332김동진10/16/201417224clickonce 와 smartscreen filter 기능에 대해서 [2]
1331궁굼합니다10/8/201411112loopback adapter 자동 설치가 가능 한가요? [2]
1330이현중10/8/201413530파일 다운로드 방법 문의 [2]파일 다운로드1
1329popo10/2/201411197싱글톤과 싱글톤 소멸자에 대해 궁금점이 있습니다. [1]
1328달쏭9/25/201411944WCF Service측에서 parameter 값이 null이 오는 이유를 알고 싶어요. [2]
1326궁굼합니다9/19/201411417VB의 Shell 기능과 완벽히 똑같은 기능의 함수 [4]
1325지현태9/18/201411110WPF 의존속성과 바인딩에 대한 질문입니다.. [1]파일 다운로드1
1324popo9/17/201410330wcf 질문 드립니다. [1]
1323Anon...9/17/201412537인스턴스와 객체의 차이 [1]
1322김영대9/16/201412248죄송하지만 .NET 관련 질문게시판이지만 혹시 ASP.NET MVC에 대해서 질문 드려도 됩니까 (__);; [2]
1321부탁드립...9/15/201413821윈도우 어플리케이션 개발 방법(?) 에대해(직접적인 코드라기보단 프로젝트 방향??) [14]
1320소켓서버...9/13/201413946서로다른 포트번호로 로컬 Socket 서버를 개설시 Close 문제 입니다. [2]
1319ㅇㅇ9/12/201414890134쪽 예제 오타 [3]
1318블루투쓰9/12/201410781page 184 질문드립니다. [1]
1316서동원8/21/201416961ActiveX 개체가 이 속성 또는 메서드를 지원하지 않습니다. [1]
1313양해진8/20/201410129메시지창에 대해서요 [1]
1312김영대8/18/201411763안녕하십니까 정성태님 죄송하지만 C#.NET의 FileInfo 클래스의 CopyTo 메서드 질문드립니다. [3]
1311김솔8/18/201412605nsis파일 수정중에요! [2]
1310조정용8/17/201413525WCF 프로그램에서 Task를 이용한 백그라운드 작업 시 클라이언트에 대한 병목현상. [4]파일 다운로드1
1309서동원8/12/201411680안녕하세요. embeded dll과 관련하여 질문드립니다. [4]
1308김솔8/11/201416235리스트뷰에서 중복파일체크를 하고싶습니다. [3]
1306이상현8/7/20149967Entity 프레임웍에서 테이블만 추가로 등록하는 방법
... 46  47  48  49  50  51  52  [53]  54  55  56  57  58  59  60  ...