Wednesday, February 19, 2020

How do I copy to the clipboard in JavaScript?

html page: 

 <button onclick="copyToClipboard();return false">copy to the clipboard</button> 
 <asp:HiddenField runat="server" ID="hdnCopyContent" ClientIDMode="Static" value="clipboard in JavaScript" />

Javascript function

function copyToClipboard() {     
        var text = $("input[Id$='hdnCopyContent']").val();
        if (text != undefined || text != null || text != "") {       
            alert(text);
        }       
        if (window.clipboardData && window.clipboardData.setData) {
            // IE specific code path to prevent textarea being shown while dialog is visible.
            return clipboardData.setData("Text", text);

        } else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
            var textarea = document.createElement("textarea");
            textarea.textContent = text;
            textarea.style.position = "fixed";  // Prevent scrolling to bottom of page in MS Edge.
            document.body.appendChild(textarea);
            textarea.select();
            try {
                return document.execCommand("copy");  // Security exception may be thrown by some browsers.
            } catch (ex) {
                console.warn("Copy to clipboard failed.", ex);
                return false;
            } finally {
                document.body.removeChild(textarea);
            }
        }
    }

Why does xcopy exit with code 9009 in Visual Studio post-build step?

xcopy "$(ProjectDir)config\Web.config.$(ConfigurationName)" "$(ProjectDir)Web.config" /Y/R

"'xcopy' is not recognized as an internal or external command."

I then changed my statement to:

C:\Windows\System32\xcopy "$(ProjectDir)config\Web.config.$(ConfigurationName)" "$(ProjectDir)Web.config" /Y/R

Tuesday, February 18, 2020

Getting Columns Headers without Result Data in SQL Server

 SET FMTONLY ON


SET FMTONLY ON returns only metadata to the client. It can be used to test the format of the response without actually running the query. When this setting is ON the resultset only have headers of the results but no data. If resultset has Spatial Results, it will have the spatial results tab as well, however, no spatial data.

sample :-


Monday, February 17, 2020

SQL Server Profiler

What is an SQL Server Profiler?
An SQL server profiler is a tool for tracing, recreating, and troubleshooting problems in MS SQL Server, Microsoft’s Relational Database Management System (RDBMS). The profiler lets developers and Database Administrators (DBAs) create and handle traces and replay and analyze trace results

How it works
It works by giving DBAs and developers a high-level view of the operation of a system. Users create traces to capture data and monitor errors and other problems. They then use the profiler to store, retrieve, and view the results of many traces graphically for purposes of troubleshooting and repair. This function all happens on the client-side, meaning it uses resources on the same machine it’s monitoring.

Benefits

  • Clarity. It can reveal how an instance works when it’s interacting with a client.
  • Troubleshoot problems. It can help zero in on trouble spots by allowing us to capture and replay key events. This function also helps with stress testing and identifying slowly executing queries.
  • Allow non-administrator users to create traces securely. It can cater to the needs of DBAs, developers, database designers, business intelligence specialists, IT professionals, and even accountants.
  • Compare activity to baselines. It lets users save trace data and compare it to newer data to spotlight new trouble spots.
  • Capture traces for Transact-SQL, SSIS, and Analysis Services.

Thursday, February 6, 2020

SQL join: where clause vs. on clause


SELECT *
FROM Orders
LEFT JOIN OrderLines ON OrderLines.OrderID=Orders.ID
WHERE Orders.ID = 12345
and

SELECT *
FROM Orders
LEFT JOIN OrderLines ON OrderLines.OrderID=Orders.ID
    AND Orders.ID = 12345


a. WHERE clause: After joining. Records will be filtered after join has taken place.

b. ON clause - Before joining. Records (from right table) will be filtered before joining

JavaScript — What’s the difference between Null & Undefined?

null is an assigned value. It means nothing.
undefined means a variable has been declared but not defined yet.
null is an object. undefined is of type undefined.
null !== undefined but null == undefined.

Differences between Response.End() and Response.Flush()

Response.Flush
Forces all currently buffered output to be sent to the client. The Flush method can be called multiple times during request processing.
Response.End
Sends all currently buffered output to the client, stops execution of the page, and raises the EndRequest event.

You should try using this code if you are not doing any processing on the page after Response.Write and want to stop processing the page.
    context.HttpContext.Response.Clear();
    context.HttpContext.Response.Write(htmlString);              
    context.HttpContext.Response.Flush(); // send all buffered output to client 
    context.HttpContext.Response.End(); // response.end would work fine now.

Change default Port on Next.js app

 If any other app or process is running on port 3000 , you will get this error in your terminal Port 3000 is already in use. error Command f...