Monday, June 20, 2016

Run Stored Procedure from Batch file (MS SQL & Oracle)

In this post we will lean how to run a stored procedure from a batch file (.bat) externally. This is used very often to run a schedule job set in the server. The whole job logic is written in the Stored procedure and we are executing that from an external batch file. So what we have to do to run this, lets see.

We will use the sqlcmd.exe file to run the stored procedure from command.  First of all create a Stored procedure in your MS. SQL server.



CREATE PROCEDURE SP_TESTSP
AS
BEGIN
      print 'THIS IS A TEST MESSAGE. LOGGED AT ' + CONVERT(VARCHAR, getdate(), 120)
END
GO


I named this as SP_TESTSP, go with your name and now open a Notepad or any other editor and write down the following script.



sqlcmd -Q "exec <STORED PROCEDURE NAME>" -S <SERVER NAME> -d <DATABSE NAME> -o <OUTPUT FILE NAME WITH PATH>


As my server name "arka-PC\SQLEXPRESS" and using Database as "DEMO", so in this case the command will be,



sqlcmd -Q "exec SP_TESTSP" -S arka-PC\SQLEXPRESS -d Attendance -o D:\SPOutput.txt


Before run this script create a file name with SPOutput.txt in the D:\ drive or where you want to save. The output of the stored procedure will be captured.

Now save the file with an extension of  ".bat". Set all the privileges and run the file by clicking twice. Check the log file, it will contain the result of the executed stored procedure.

Output:



THIS IS TEST MESSAGE. LOGGED AT 2016-06-19 23:52:48


In the next tutorial we will see how to put a bat file in a Task Scheduler in windows server.

Sunday, April 17, 2016

How to prevent F12 in browser

Introduction:

Opening the console log of browser and change element value of a web page is like a headache for the developer. To prevent this situation here is the remedy.

Description:

So how to stop this kind of situation, you could get a message while user is opening the console log and take necessary step or you could prevent user from opening that. We will discuss both the situation in this article one by one.

Getting noticed while opening the console of the browser:

Create a normal HTML page and and add a div to show the status of the development tool box. And write down the code.



<body>
    status: <div id="status"></div>
</body>
 
After that write down the code within the script tag under body section.



<script>
    var checkStatus;

    var element = new Image();
    element.__defineGetter__('id', function () {
        checkStatus = 'on';
    });

    setInterval(function () {
        checkStatus = 'off';
        console.log(element);
        console.clear();
        document.querySelector('#status').innerHTML = checkStatus;
    }, 1000)
</script>


 Output:



Prevent Clicking F12 and Mouse Right Click:

This trick is not like showing status. By showing status you can do all your customization in your code but here in this example of coding user will not be able to click F12 and mouse right click. Lets see how.

Before starting add JQuery into your page. To add it add the bellow script to the top of all the JQuery code.



<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
 
After that within a script tag write down the  bellow code.



<script>
    $(document).keydown(function (event) {
        if (event.keyCode == 123) {
            return false;
        }
        else if (event.ctrlKey && event.shiftKey && event.keyCode == 73) {
            return false;
        }
    });

    $(document).on("contextmenu", function (e) {
        e.preventDefault();
    });
</script>


As you can see we have used the Key code to detect the clicking of buttons and mouse. Here 123 stands for F12 and 73 for I key. To know more visit https://msdn.microsoft.com/en-us/library/aa243025(v=vs.60).aspx.

Run both the examples and enjoy.




 

Popular Posts

Pageviews