Santosh's profileSantosh KumarPhotosBlogListsMore Tools Help

Blog


    ASP.NET, Handling all Oracle DML with a generalized method

    When it needs to insert, update or delete records from oracle table, the best practice is to use precompiled store procedures. But to call these store procedure programmers are writing a bunch of codes. The following code in ASP.NET using VB.NET will solve your maximum issues
     
    Public Shared Function ExecuteOraSP(ByVal myOraSP As String, ByVal myOraPrmIP As String, ByVal myOraValIP As String, ByVal myOraTypIP As String) As Integer
     
        '''''common'procedure'for'insert'delete'and'upadte'using'oracle'procedure'''''
        'Returns Err(-1), Success(>=0)
     
        '''''Sample oracle procedure looks like this...
        'CREATE OR REPLACE PROCEDURE SP_EMP_U(
        '    vID Number:=0,
        '    vNAME Varchar2:=null,
        '    OraReturn out Number) AS
        'BEGIN
        '    OraReturn:=-1;
        '    update emp set ename=vNAME where empno=vID;
        '    OraReturn:= SQL%ROWCOUNT ;
        'END;
        '/
     
        '''''how to call
        'Dim myOraSP As String = "SP_EMP_U"
        'Dim myOraPrmIP As String = "vID" & getPipe() & "vNAME"
        'Dim myOraValIP As String = "7369" & getPipe() & "RPS"
        'Dim myOraTypIP As String = "N" & getPipe() & "VC"
     
        Dim myOraPrmOP As String = "OraReturn"
     
        Dim myExecuteFeedback As Integer = 0
     
        Dim myOracleConnection As OracleConnection = Nothing
        Dim myOracleDataReader As OracleDataReader = Nothing
        Dim myOracleCommand As OracleCommand = Nothing
     
        Dim myOracleParameterIP As OracleParameter
        Dim myOracleParameterOP As OracleParameter
     
        Dim myArrPrm() As String = Split(myOraPrmIP, getPipe())
        Dim myArrVal() As String = Split(myOraValIP, getPipe())
        Dim myArrTyp() As String = Split(myOraTypIP, getPipe())
     
        If myArrPrm.Length <> myArrVal.Length _
        And myArrPrm.Length <> myArrTyp.Length _
        Then Return myExecuteFeedback
     
        Dim vCnt As Integer = myArrPrm.Length - 1
        Dim vCtr As Integer = 0
        Dim myOracleType As OracleType = 0
     
        Try
            myOracleConnection = New OracleConnection(getOracleConnectionString())
            myOracleCommand = myOracleConnection.CreateCommand
            myOracleCommand.CommandText = myOraSP
            myOracleCommand.CommandType = CommandType.StoredProcedure
            myOracleConnection.Open()
     
            'adding ipput parameter
            For vCtr = 0 To vCnt
                If myArrTyp(vCtr) = "VC" Then myOracleType = OracleType.VarChar
                If myArrTyp(vCtr) = "DT" Then myOracleType = OracleType.DateTime
                If myArrTyp(vCtr) = "CH" Then myOracleType = OracleType.Char
                If myArrTyp(vCtr) = "N" Then myOracleType = OracleType.Number
                If myArrTyp(vCtr) = "B" Then myOracleType = OracleType.Byte
                If myArrTyp(vCtr) = "D" Then myOracleType = OracleType.Double
                If myArrTyp(vCtr) = "F" Then myOracleType = OracleType.Float
                myOracleParameterIP = myOracleCommand.Parameters.Add(myArrPrm(vCtr), myOracleType)
                myOracleParameterIP.Direction = ParameterDirection.Input
                myOracleParameterIP.Value = myArrVal(vCtr)
            Next
     
            'adding output parameter
            myOracleParameterOP = myOracleCommand.Parameters.Add(myOraPrmOP, OracleType.Number)
            myOracleParameterOP.Direction = ParameterDirection.Output
     
            'executing
            myOracleDataReader = myOracleCommand.ExecuteReader
     
            'getting feedback
            myExecuteFeedback = myOracleParameterOP.Value
     
     
        Catch ex As Exception
            myExecuteFeedback = -1
     
        Finally
            If Not myOracleDataReader Is Nothing Then myOracleDataReader.Close()
            If Not myOracleCommand Is Nothing Then myOracleCommand.Dispose()
            If Not myOracleConnection Is Nothing Then myOracleConnection.Dispose()
        End Try
     
        Return myExecuteFeedback
     
    End Function
     
    Public Shared Function getPipe() As String
        Return Chr(1) & Chr(2) & Chr(3)
    End Function
     
    »»»»»»»   by Santosh Kumar
     ?
    Original @ http://santu4you.spaces.live.com

    ASP.NET, Page validation techniques

    Role based application, generally go for thousand lines of coding in each page. This is for validation of the menus and links. And also for the validation of access to those pages, which are directly specified on the address bar having been logged in. Doing a lot of database access for each page just for validation is not a good practice, specially when there exit hundreds of hits per minute.
     
    Following code illustrates how just calling a function called “doAuthentication” can validate a page. The menu system can be arranged by xml based coding. Each of the clicks to the link must maintain dynamic coding that will store the URL of the page in a session variable before it redirects to that page.
     
    Public Shared Sub doAuthentication(ByVal IsPostbackFlag As Boolean)
        ''''check for login
        If HttpContext.Current.Session("objUser") Is Nothing Then
            HttpContext.Current.Response.Redirect("login.aspx")
        End If
        ''''check for authorised pages
        If Not IsPostbackFlag Then
            Dim thisUrl As String = HttpContext.Current.Request.FilePath.ToString()
            Dim vArrURL() As String = Split(thisUrl, "/")
            Dim thisPage As String = LCase(vArrURL(vArrURL.Length - 1))
            Dim objUser As clsUser = HttpContext.Current.Session("objUser")
            If LCase(objUser.UserURL) <> LCase(thisPage) Then
                HttpContext.Current.Response.Redirect("app__access_denied.aspx")
            End If
        End If
    End Sub
     
    »»»»»»»   by Santosh Kumar
     ?
    Original @ http://santu4you.spaces.live.com

    Short Story ... The easier way may actually be the tougher way

     
    Once there was a lark singing in the forest. The lark stopped him and asked, "What do you have in the box and where are you going?" The farmer replied that he had worms and that he was going to the market to trade them for some feathers. The lark said, "I have many feathers. I will pluck one and give it to you and that will save me looking for worms." The farmer gave the worms to the lark and the lark plucked a feather and gave it in return. The next day the same thing happened and the day after and on and on until a day came that the lark had no more feathers. Now it couldn't fly and hunt for worms. It started looking ugly and stopped singing and very soon it died.
     
    The moral is quite clear what the lark thought was an easy way to get food turned out to be the tougher way after all. Isn't the same thing true in our lives? Many times we look for the easier way, which really ends up being the tougher way.
     
    by Shiv Khera { You Can Win }
     

    Short Story ... B'Coz we see things not the way they are but the way we are

     
    There is a legend about a wise man who was sitting outside his village. A traveler came up and asked him, "What kind of people live in this village, because I am looking to move from my present one?" The wise man asked, "What kind of people live where you wa nt to move from?" The man said, "They are mean, cruel, rude."
     
    The wise man replied, "The same kind of people live in this village too." After some time another traveler came by and asked the same question and the wise man asked him, "What kind of people live where you want to move from?" And the traveler replied, "The people are very kind, courteous, polite and good." The wise man said, "You will find the same kind of people here too."
     
    What is the moral of the story?
     
    Generally we see the world not the way it is but the way we are. Most of the time, other people's behavior is a reaction to our own.
     
    by Shiv Khera { You Can Win }
     

    Oracle, PL/SQL execution feedbacks

    Execution in PL/SQL script must give certain feedback so that it can reduce 100s of checks on the executed output. The variables like SQL%ROWCOUNT, SQL%FOUND and SQL%NOTFOUND can give much more interactive feedbacks. Find the following codes
     
    DECLARE
        RCNT NUMBER;
        UCNT NUMBER;
        FCNT NUMBER;
    BEGIN
        RCNT:=0;
        UCNT:=0;
        FCNT:=0;
        FOR RS IN (SELECT ROWNUM RN, E.* FROM EMP E) LOOP
            UPDATE EMP SET EMPNO=EMPNO WHERE TO_CHAR(HIREDATE,'MM')=TRIM(TO_CHAR(RS.RN,'00'));
            RCNT:=RCNT+1;
            IF SQL%ROWCOUNT>0 THEN
                FCNT:=FCNT+1;
                UCNT:=UCNT+SQL%ROWCOUNT;
            END IF;
        END LOOP;
        DBMS_OUTPUT.PUT_LINE('In '||RCNT||' attempts, a total of '||UCNT||' records are updated by '
        ||FCNT||' successful executions.');
    END;
     
    »»»»»»»   by Santosh Kumar
     ?
    Original @ http://santu4you.spaces.live.com

    ASP.NET, Quickly web deployment in 2005

    There exists many methods for deploying ASP.NET 2.0 projects. And I prefer doing it through ASPNET_COMPILER. Let us assume your project is  created at D:\MYPRJ\MYWEB and the virtual directory refering it is MYURL. Now use the following batch file for getting the output at D:\DEPLOY. That's all
     
     
    @ECHO OFF
    ECHO.
     
    ECHO ASP 2.0 COMPILATION PROGRAM
    ECHO AUTHORED BY SANTOSH KUMAR
    ECHO ====================================
    ECHO.
    ECHO Started...!!!
    ECHO.
     
    ECHO Changing drive to windows drive
    %SYSTEMDRIVE%
    ECHO Done...!!!
    ECHO.
     
    ECHO Changing directory to ASP 2.0 framework directory
    CD  %WINDIR%\MICROSOFT.NET\FRAMEWORK\V2.0.50727
    ECHO Done...!!!
    ECHO.
     
    ECHO Removing existing folders and files
    RD /S /Q D:\DEPLOY
    ECHO Done...!!!
    ECHO.
     
    ECHO Creating D:\DEPLOY
    MD D:\DEPLOY
    ECHO Done...!!!
    ECHO.
     
    ECHO Stating compilation
    ASPNET_COMPILER -v /"MYURL" -p "D:\MYPRJ\MYWEB" -u "D:\DEPLOY"
    ECHO Done...!!!
    ECHO.
     
    PAUSE
     
     
    Oh yes! you must have necessary prerequisites on your target server and you can follow the following order to install them
    2.0 _step1 Microsoft .NET Framework Version 2.0 Redistributable Package {dotnetfx}
    2.0 _step2 Microsoft .NET Framework SDK Version 2.0 {setup.exe}
    2.0 _step3 Security Update for Windows 2000 {Windows2000-KB835732-x86-ENU}
    2.0 _step4 Update Rollup 1 for SP4 {Windows2000-KB891861-v2-x86-ENU}
    2.0 _step5 Microsoft .NET Framework 2.0 Service Pack 1 {NetFx20SP1_x86}
    2.0 _step6 Microsoft ASP.NET 2.0 AJAX Extensions 1.0 {ASPAJAXExtSetup}

    »»»»»»»   by Santosh Kumar ? Original @ http://santu4you.spaces.live.com