Monday, May 26, 2014

oracle stored procedure select template return cursor with optional Parameters

Description :
i need to create Stored Procedure select from table with optional parameters to filter and return cursor.
then receive cursor using vb.net function and mapping data to data table to check data existence.

Stored Procedure Template
Stored Specification (with Package Declaration)

PACKAGE     USER_COMPANY IS
 TYPE GET_CO_INFO_CUR IS REF CURSOR ;
PROCEDURE   GET_COMPANY_DATE  -------------                            
                       (VGENERAL_ON    IN    NUMBER  DEFAULT 0       ,
                        VSEGIL_NO      IN    VARCHAR2 DEFAULT NULL    ,                                            
                        VGET_DATE      OUT   GET_DATE,
                        VEXCEPTION  OUT NUMBER);
END;  -- end Package Declaration
---------------------------------------------------------
Stored Body(with Package Body)

PACKAGE BODY   USER_COMPANY IS
PROCEDURE   GET_COMPANY_DATE  --------------                                            
                       (VGENERAL_ON    IN    NUMBER  DEFAULT 0       ,
                        VSEGIL_NO      IN    VARCHAR2 DEFAULT NULL    ,                     
                        VGET_DATE      OUT   GET_DATE,
                        VEXCEPTION  OUT NUMBER)  IS
BEGIN
     OPEN VGET_DATE  FOR          
      SELECT  GENERAL_ON, SEGIL_NO, EMAIL, PASS_WORD, MOBIL_NO, PHONE_NO, MNG_MOBIL_NO,USER_TYPE
      FROM    TND.TND_COMPANY_REGISTER 
      WHERE  (VGENERAL_ON = 0 OR GENERAL_ON = VGENERAL_ON)
      AND    (VSEGIL_NO   IS NULL OR  SEGIL_NO   = VSEGIL_NO );
EXCEPTION WHEN OTHERS  THEN
          VEXCEPTION := SQLCODE;      
    
END  GET_COMPANY_DATE;
END; --end Package Body
--------------------------------------------------------------------------------
Notes : if you passed two optional parameters so the stored procedure query will filter using two values
else if the number value is 0 or varchar2 value is null or empty string the query execution will ignore it in filter so you can use this template for search optionally for your input parameters
the other benefit is if you pass one parameter only for the procedure the execution will succeed because of default value binding option.

-----------------------------------------------------------------------
vb.net function to get cursor data

note : the template code using Oracle.DataAccess.Client library.

 Public Function Get_Company_Data(ByVal general_No As String, ByVal sejelno As String) As DataTable
        Dim mydt As New DataTable()
        Try
            Dim OConn As New OracleConnection
            OConn.ConnectionString = connect.Tender
            Dim cmd As New OracleCommand
            cmd.CommandType = Data.CommandType.StoredProcedure
            cmd.CommandText = "SchemaName.PackageName.ProcedureName"
            cmd.Connection = OConn
            cmd.BindByName = True
            Dim O_par_1, O_par_2, O_par_3, O_par_4 As OracleParameter
            O_par_1 = cmd.Parameters.Add("VGENERAL_ON", OracleDbType.Double, 22)
            O_par_2 = cmd.Parameters.Add("VSEGIL_NO", OracleDbType.Varchar2, 20)
            O_par_3 = cmd.Parameters.Add("VGET_DATE", OracleDbType.RefCursor)
            O_par_4 = cmd.Parameters.Add("VEXCEPTION", OracleDbType.Double, 20)
            O_par_1.Direction = Data.ParameterDirection.Input
            O_par_2.Direction = Data.ParameterDirection.Input
            O_par_3.Direction = Data.ParameterDirection.Output
            O_par_4.Direction = Data.ParameterDirection.Output

            O_par_1.Value = general_No
            O_par_2.Value = sejelno


            If OConn.State = ConnectionState.Closed Then
                OConn.Open()
            End If
            Dim adp As New OracleDataAdapter(cmd)

            adp.Fill(mydt)

            cmd.Connection.Close()
            OConn.Close()
            If mydt.Rows.Count > 0 Then
                Return mydt
            Else
                Return Nothing
            End If

        Catch ex As Exception
            Return mydt
        End Try
    End Function



Thursday, May 8, 2014

jquery update panel ajax problem solve , updatepanel may need to register scripts outside body also solve the update panel script not working problem

if you fire jquery event in document.ready function and you use update panel you will face problem
after postback inside update panel the jquery function not loaded

to Solve this Problem follow this scenario :

<script type="text/javascript">

        $(document).ready(function () {
         //put you code here to fire on the first.
        });
        function pageLoad(sender, args) {
            if (args.get_isPartialLoad()) {

            //put your code here to fire after postback event .
            }
        }
 
    </script>


-------------------------------------------------------------------------------------------------------------------
i face problem with bootstrap scirpts with update panel to be run.
first time page visited the script exists on head tag working but after any asynchronous request inside update panel stop running scripts.
so i solve this problem by set master content outside form tag and register the script inside , this solve the problem>


   

Sunday, April 27, 2014

Toad how to test Stored Procedure with return values (how to see result)

if you have stored procedure return single or multiple values separately not in cursor you can't see the stored Procedure Result

follow the following steps
1- right click on you stored procedure that returns single values as output parameters
2-Click Execute Procedure
3-Copy Code Generated in execute window and paste it to new Editor
4-Right Click On Script Output panel and check DBMS output

5-after Execute Line write the flowing
 DBMS_OUTPUT.PUT_LINE('DESCRIPTION TEXT ' || TO_CHAR(YOUR_OUTPUT_VAR));
EXAMPLE:
DECLARE   P_SEGELNO VARCHAR2(200);  P_ORDERNO VARCHAR2(200);  P_ORDDATEH VARCHAR2(200);  P_BEGDATEH VARCHAR2(200);  P_PERIOD NUMBER;  P_ENDDATEH VARCHAR2(200);  P_EMP_NAME VARCHAR2(200);  P_MESSAGE_TEXT VARCHAR2(200);
BEGIN   P_SEGELNO := '1073286849';  P_ORDERNO := NULL;  P_ORDDATEH := NULL;  P_BEGDATEH := NULL;  P_PERIOD := NULL;  P_ENDDATEH := NULL;  P_EMP_NAME := NULL;  P_MESSAGE_TEXT := NULL;
  SHR.NET_EMP_MULTI.NOT_ALLOW_EXTEND ( P_SEGELNO, P_ORDERNO, P_ORDDATEH, P_BEGDATEH, P_PERIOD, P_ENDDATEH, P_EMP_NAME, P_MESSAGE_TEXT );    DBMS_OUTPUT.PUT_LINE('ORDER NUMBER = ' || TO_CHAR(P_ORDERNO));     DBMS_OUTPUT.PUT_LINE('ORDER DATE = ' || TO_CHAR(P_ORDDATEH));    DBMS_OUTPUT.PUT_LINE('ORDER PERIOD = ' || TO_CHAR(P_PERIOD));    DBMS_OUTPUT.PUT_LINE('ORDER ENDDATEH = ' || TO_CHAR(P_ENDDATEH));    DBMS_OUTPUT.PUT_LINE('EMP NAME = ' || TO_CHAR(P_EMP_NAME));    DBMS_OUTPUT.PUT_LINE('EMP NAME = ' || TO_CHAR(P_MESSAGE_TEXT));      COMMIT; END; 

6-Click on DBMS or Press Keyboard ALT_CTR_D
you should see your result


Toad for Oracle arabic problem when run queries [solved]

1- change your NLS_Lang registry key to
AMERICAN_AMERICA.AR8MSWIN1256

do this for all oracle homes in windows.

2- change your windows Region and Language Format to arabic (egypt ) or saudi araia

you should run queries now fine.

if you solve NLS_Lang problem toad will not work untill set your format to arabic this is stupid issue.


Friday, April 25, 2014

SQL SERVER CHECK PARAMETER TEXT LENGTH EXAMPLE

BEGIN
DECLARE @RESULT VARCHAR(50)
DECLARE @JOB_TITLE_ID NVARCHAR(50)
SET @JOB_TITLE_ID ='';
IF(
(SELECT LEN(@JOB_TITLE_ID))>0)
SET @RESULT ='GREATER THAN ZERO'
ELSE
SET @RESULT = 'LESS OR EQUAL ZERO'
SELECT @RESULT;
END

Wednesday, April 23, 2014

backup IIS Configuration for server - How to Copy windows Server 2008 IIS Configurations

How to Copy windows Server 2008 IIS Configurations
TO TAKE FULL BACKUP FOLLOW THE LINK BELOW
http://blogs.iis.net/bills/archive/2008/03/24/how-to-backup-restore-iis7-configuration.aspx
---------------------------------------------------------------------------------------------------------------------
How to copy IIS configuration from existing server to new one 
I'd say export your config
In IIS manager, you need to export the config from server 1. In IIS manager, click the Server node, and go to Shared Configuration under Management and Click “Export Configuration”. You can use a password if you are sending them across the internet, if you are just gonna move them via a USB key then don't sweat it.
Move these files to your new server
administration.config
applicationHost.config
configEncKey.key
On the new server, go back to the “Shared Configuration” section and check “Enable shared configuration.” Enter the location in physical path to these files and apply them.
It should prompt for the encryption password(if you set it) and reset IIS.
BAM! Go have a beer!

using wizard to export IIS configuration you should install web deploy tool
http://www.iis.net/learn/publish/using-web-deploy/use-the-web-deployment-tool
source
http://technet.microsoft.com/es-es/library/dd569059(v=ws.10).aspx
----------------------------------------------------------------------------------------------------------------
To run commands using Command Prompt use the following commands.
Run Command Prompt with administration Privileges.

To Export the Application Pools on IIS 7 :
%windir%\system32\inetsrv\appcmd list apppool /config /xml > c:\apppools.xml
This will export all the application pools on you’re webserver, therefor you need to edit the apppools.xml and remove the application that you do not need to import for example:
  • DefaultAppPool
  • Classic .NET AppPool
  • SecurityTokenServiceApplicationPool
And other apppools that already exist on the second webserver, appcmd doesn’t skip already existing apppools, it just quit’s and doesn’t import any.
To import the Application Pools:
%windir%\system32\inetsrv\appcmd add apppool /in < c:\apppools.xml
All the AppPools in the xml will be created on you’re second webserver.
To Export all you’re website:
%windir%\system32\inetsrv\appcmd list site /config /xml > c:\sites.xml
This will export all the websites on you’re webserver, therefor you need to edit the sites.xml and remove the websites that you do not need to import for example:
  • Default Website
And all other websites that already exist on the second webserver.
To Import the website:
%windir%\system32\inetsrv\appcmd add site /in < c:\sites.xml
It’s also possible to export a single website or application pool all you need to do is add the name of the Application Pool or Website to the command line:
To export/import a single application pool:
%windir%\system32\inetsrv\appcmd list apppool “MyAppPool” /config /xml > c:\myapppool.xml
Import:
%windir%\system32\inetsrv\appcmd add apppool /in < c:\myapppool.xml
To export/import a single website:
%windir%\system32\inetsrv\appcmd list site “MyWebsite” /config /xml > c:\mywebsite.xml
Import:
%windir%\system32\inetsrv\appcmd add site /in < c:\mywebsite.xml


Sunday, April 20, 2014

Microsoft Outlook 2010 separate mails from sender to separated Folder

http://office.microsoft.com/en-us/outlook-help/create-a-rule-based-on-email-message-sender-or-recipients-HA102063132.aspx

STEPS :
1- OPEN HOME TAB
2-CLICK ON RULES FOLDER
3-CREATE NEW RULE
4- CHOOSE FROM SENDER OR MESSAGE TITLE AND NEXT TO COMPLETE CONFIGURAITONS