Thursday, 8 February 2018

npm install (the command) to work behind proxy

npm config set strict-ssl false

npm config set registry "http://registry.npmjs.org/"
  
npm --proxy http://<username>:<password>@<proxy server>:<port> \


npm set registry https://registry.npmjs.org/

Wednesday, 7 February 2018

Search text in all database objects


DECLARE @cmd                        varchar(1000),
            @search_string          varchar(200)

CREATE TABLE #temp(
      [Database_Name]         sysname,
      [Schema_Name]           sysname,
      [Object_Name]           sysname,
      [Object_Type]           nvarchar(60))

-- Set the search string
SET @search_string = 'gokul'

SET @cmd = 'INSERT INTO #temp SELECT DISTINCT ''?'', s.name AS Schema_Name, o.name AS Object_Name, o.type_desc FROM [?].sys.sql_modules m INNER JOIN [?].sys.objects o ON m.object_id = o.object_id INNER JOIN [?].sys.schemas s ON o.schema_id = s.schema_id WHERE m.definition Like ''%' + @search_string + '%'''



EXEC sp_msforeachdb @cmd


SELECT *
FROM #temp
ORDER BY [Database_Name], [Object_Name], [Object_Type]


DROP TABLE #temp


GO

Friday, 7 July 2017

2 way SSL WCF service call from an console application # issue "System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel."


Emailer.WSSoapClient obj = new    Emailer.WSSoapClient();

var clientCertificate = new X509Certificate2(AppDomain.CurrentDomain.BaseDirectory + "certname", "Fr@123");

 obj.ClientCredentials.ClientCertificate.Certificate = clientCertificate;

Friday, 7 April 2017

How to a call a soap web service from VB6

Private Sub Command3_Click()
''Define our WebService constants
Const WebService_ServerURL = "http://localhost:59629/XXXXXXXasmx"

Const WebService_NameSpace = "http://tempuri.org"

''Declare the objects (Early Binding)
Dim Envelope As PocketSOAP.CoEnvelope
Dim Transport As winhttp.WinHttpRequest

''Instantiate the Objects
Set Envelope = New PocketSOAP.CoEnvelope12
Set Transport = New winhttp.WinHttpRequest


Dim PXML As String

PXML = "<Root></Root>"
''Set the methodName and methodname Namespace values
Envelope.SetMethod "Request", "http://tempuri.org/"
Envelope.Parameters.Create "strRequest", PXML, "http://tempuri.org/"
''Define the parameters

''Initialize WinHTTP
Transport.Open "POST", WebService_ServerURL, False
'' Set Request Headers
Transport.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
Transport.setRequestHeader "SOAPAction", WebService_NameSpace & "/" & Envelope.MethodName

'e.SetMethod "query", ns
'e.Parameters.Create "query", "select Id, name from account order by systemModStamp desc limit 5", ns





' Transport.SetClientCertificate()



'' Send the serialized SOAP request
'' This is where the actual data is transmitted, and the response is received.
'' This may take a little while to return.
Transport.send Envelope.Serialize


'' Parse the response, and display the result
Envelope.Parse Transport.responseText
MsgBox Transport.responseText

End Sub

Monday, 20 February 2017

How to Unprotect an excel sheet without password

-- Press ALT +  F11 or click on View Code in Developers Tabs



Sub PasswordBreaker()

    'Breaks worksheet password protection.
    Dim i As Integer, j As Integer, k As Integer
    Dim l As Integer, m As Integer, n As Integer
    Dim i1 As Integer, i2 As Integer, i3 As Integer
    Dim i4 As Integer, i5 As Integer, i6 As Integer
    On Error Resume Next
    For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
    For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
    For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
    For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
    ActiveSheet.Unprotect Chr(i) & Chr(j) & Chr(k) & _
        Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
        Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
    If ActiveSheet.ProtectContents = False Then
        MsgBox "One usable password is " & Chr(i) & Chr(j) & _
            Chr(k) & Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & _
            Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
         Exit Sub
    End If
    Next: Next: Next: Next: Next: Next
    Next: Next: Next: Next: Next: Next

End Sub

Wednesday, 8 February 2017

Getting data via ODBC gets truncated when exceeding 32000 the TextSize length

ODBC program that read data via ODBC from Sybase ASE. limits to 32000

Solution

textsize=1000000 in the config file for connection string;

Monday, 16 January 2017

read xml in sql


--  IPS_DOC_DETAILS.query('data(/IPSDoc/CLIENTINFO/Client/FIRST_NAME)')
declare  @x xml = '<x>hello<y>world</y></x><x>again</x>'
select @x.query('data(/*)')

Thursday, 1 December 2016

How Kill a windows Service

C:\Windows\System32>sc queryex  servicesname 

Result get the PID

SERVICE_NAME: servicesname
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 3  STOP_PENDING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0
        PID                : 944
        FLAGS     

run the below cmd

C:\Windows\System32>taskkill /PID 944 /F

Friday, 23 September 2016

Get Definition of a view in DB2



select name, cast(text as varchar(10000))
from SYSIBM.SYSVIEWS
where name='CONTACTS_OPENS_VIEW'

Wednesday, 20 July 2016

How to Delete using INNER JOIN with SQL Ser

DELETE FROM WorkRecord2 INNER JOIN Employee ON EmployeeRun=EmployeeNo
Where Company = '1' AND Date = '2013-05-06'

Error - Msg 156, Level 15, State 1, Line 15 Incorrect syntax near the keyword 'INNER'.


You need to specify what table you are deleting from, here is a version with an alias:


DELETE w
FROM WorkRecord2 w
INNER JOIN Employee e
  ON EmployeeRun=EmployeeNo
Where Company = '1' AND Date = '2013-05-06'

Wednesday, 22 June 2016

How to: Write to a Text File C#

 string[] lines = { "First line", "Second line", "Third line" };
        // WriteAllLines creates a file, writes a collection of strings to the file,
        // and then closes the file.  You do NOT need to call Flush() or Close().
        System.IO.File.WriteAllLines(@"C:\Users\Public\TestFolder\WriteLines.txt", lines);


 string text = "A class is the most powerful data type in C#. Like a structure, " +
                       "a class defines the data and behavior of the data type. ";
        // WriteAllText creates a file, writes the specified string to the file,
        // and then closes the file.    You do NOT need to call Flush() or Close().
        System.IO.File.WriteAllText(@"C:\Users\Public\TestFolder\WriteText.txt", text);


Sunday, 5 June 2016

Wednesday, 2 March 2016

Call a javascript function on all Postback





<script type="text/javascript">
 
   $(document).ready(function () {
 var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_endRequest(function (s, e) {
        alert('Postback!'); // write ur Fn here
    });

  });
</script>

Tuesday, 16 February 2016

javascript to capture the browser or tab closed event



/*Refer  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> too*/

var validNavigation = false;

function endSession() {
  // Browser or broswer tab is closed
  // Do here ...
  alert("bye");
}

function wireUpEvents() {
  /*
  * For a list of events that triggers onbeforeunload on IE
  * check http://msdn.microsoft.com/en-us/library/ms536907(VS.85).aspx
  */
  window.onbeforeunload = function() {
      if (!validNavigation) {
         endSession();
      }
  }

  // Attach the event keypress to exclude the F5 refresh
  $(document).bind('keypress', function(e) {
    if (e.keyCode == 116){
      validNavigation = true;
    }
  });

  // Attach the event click for all links in the page
  $("a").bind("click", function() {
    validNavigation = true;
  });

  // Attach the event submit for all forms in the page
  $("form").bind("submit", function() {
    validNavigation = true;
  });

  // Attach the event click for all inputs in the page
  $("input[type=submit]").bind("click", function() {
    validNavigation = true;
  });
 
}

// Wire up the events as soon as the DOM tree is ready
$(document).ready(function() {
  wireUpEvents();
});

Wednesday, 3 February 2016

SP for maintaining same table structure for Main and archive table.

GO

/****** Object:  StoredProcedure [dbo].[USP_ManageArchivalTableStrucutures]    Script Date: 2/2/2016 11:00:02 AM ******/

SET ANSI_NULLS ON;
GO
SET QUOTED_IDENTIFIER ON;
GO

-- =============================================
-- Author:           Gokuldas Palapatta
-- Create date:  2016-02-01 12:32:18.960
-- Description:      Help_archiveTables
--
--Table Details
-- CREATE TABLE [dbo].[Archive_Setting](
-- [Id] [int] IDENTITY(1,1) NOT NULL,
-- [SnapShotTable] [varchar](100) NOT NULL,
-- [ArchiveTable] [varchar](100) NOT NULL)
-- =============================================
ALTER PROCEDURE [dbo].[USP_ManageArchivalTableStrucutures]
-- Add the parameters for the stored procedure here
AS
    BEGIN
        -- SET NOCOUNT ON added to prevent extra result sets from
        -- interfering with SELECT statements.
        SET NOCOUNT ON;
        --Declaring All variables


        DECLARE @Query VARCHAR(MAX) = '';
        IF OBJECT_ID('tempdb..#temp1') IS NOT NULL
            BEGIN
                DROP TABLE #temp1;
            END;
            IF OBJECT_ID('tempdb..#temp2') IS NOT NULL
                BEGIN
                    DROP TABLE #temp2;
                END;
                IF OBJECT_ID('tempdb..#temp3') IS NOT NULL
                    BEGIN
                        DROP TABLE #temp3;
                    END;

                    -- pushing all the details to temptable
                    SELECT C2.*,
                           C1.* INTO #TEMP1
                    FROM INFORMATION_SCHEMA.COLUMNS C2
                         JOIN ARCHIVE_SETTING C1 ON C2.TABLE_NAME = C1.SNAPSHOTTABLE
                                                 OR C2.TABLE_NAME = C1.ARCHIVETABLE;


                    -- Filtering only changed and new coloumns
                    SELECT * INTO #TEMP2
                    FROM(
                        SELECT DISTINCT COLUMN_NAME,
                                        C2.DATA_TYPE,
                                        C2.CHARACTER_MAXIMUM_LENGTH,
                                        C2.TABLE_NAME,
                                        0 AS ISCHANGED,
                                        1 AS NEW,
                                        ARCHIVETABLE AS ALTERTABLE,
                                        C2.IS_NULLABLE
                        FROM #TEMP1 C2
                        WHERE TABLE_NAME = SNAPSHOTTABLE
                          AND C2.COLUMN_NAME NOT IN(
                                 SELECT COLUMN_NAME
                                 FROM #TEMP1
                                 WHERE TABLE_NAME = ARCHIVETABLE )
                        UNION ALL
                        SELECT DISTINCT C2.COLUMN_NAME,
                                        C2.DATA_TYPE,
                                        C2.CHARACTER_MAXIMUM_LENGTH,
                                        C2.TABLE_NAME,
                                        1 AS ISCHANGED,
                                        0 AS NEW,
                                        ARCHIVETABLE AS ALTERTABLE,
                                        C2.IS_NULLABLE
                        FROM #TEMP1 C2
                        WHERE TABLE_NAME = SNAPSHOTTABLE
                          AND C2.COLUMN_NAME IN(
                                 SELECT COLUMN_NAME
                                 FROM #TEMP1 C1
                                 WHERE TABLE_NAME = ARCHIVETABLE
                                   AND C2.COLUMN_NAME = C1.COLUMN_NAME
                                   AND ( C2.IS_NULLABLE <> C1.IS_NULLABLE
                                      OR C1.DATA_TYPE <> C2.DATA_TYPE
                                      OR C1.CHARACTER_MAXIMUM_LENGTH <> C2.CHARACTER_MAXIMUM_LENGTH
                                       ))) AS CT;

                    -- preparing Query based on the changes
                    SELECT * INTO #Temp3
                    FROM(
                        SELECT *,
                               CASE
                                   WHEN data_type = 'varchar'
                                     OR data_type = 'nvarchar'
                                     OR data_type = 'char'
                                   THEN 'ALTER TABLE ' + AlterTable + '
ALTER COLUMN ' + COLUMN_NAME + ' ' + data_type + ' (' + CAST(CHARACTER_MAXIMUM_LENGTH AS VARCHAR(10)) + ' )' + ' ' + CASE
                                                                                                                         WHEN IS_NULLABLE = 'YES'
                                                                                                                         THEN 'null'
                                                                                                                         ELSE 'Not null'
                                                                                                                     END
                                   ELSE 'ALTER TABLE ' + AlterTable + '
ALTER COLUMN ' + COLUMN_NAME + ' ' + data_type + ' ' + CASE
                                                           WHEN IS_NULLABLE = 'YES'
                                                           THEN 'null'
                                                           ELSE 'Not null'
                                                       END
                               END AS Query
                        FROM #temp2
                        WHERE IsChanged = 1
                          AND NEW = 0
                        UNION ALL
                        SELECT *,
                               CASE
                                   WHEN data_type = 'varchar'
                                     OR data_type = 'nvarchar'
                                     OR data_type = 'char'
                                   THEN 'ALTER TABLE ' + AlterTable + '
ADD  ' + COLUMN_NAME + ' ' + data_type + ' (' + CAST(CHARACTER_MAXIMUM_LENGTH AS VARCHAR(10)) + ' )' + ' ' + CASE
                                                                                                                 WHEN IS_NULLABLE = 'YES'
                                                                                                                 THEN 'null'
                                                                                                                 ELSE 'Not null'
                                                                                                             END
                                   ELSE 'ALTER TABLE ' + AlterTable + '
ADD  ' + COLUMN_NAME + ' ' + data_type + ' ' + CASE
                                                   WHEN IS_NULLABLE = 'YES'
                                                   THEN 'null'
                                                   ELSE 'Not null'
                                               END
                               END AS Query
                        FROM #temp2
                        WHERE IsChanged = 0
                          AND NEW = 1 ) AS CX;

                    -- concardinating  Query based
                    SELECT @Query = COALESCE(@Query + ' ', '') + Query
                    FROM #Temp3;
                    EXEC ( @Query );
    END;

Monday, 18 January 2016

SP to find a string inside table values in a DB in SQL

-- Pass the search string to the SP, it will return table + column name.


CREATE PROC SearchAllTables
(
    @SearchStr nvarchar(100)
)
AS
BEGIN

    CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630))

    SET NOCOUNT ON

    DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)
    SET  @TableName = ''
    SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')

    WHILE @TableName IS NOT NULL

    BEGIN
        SET @ColumnName = ''
        SET @TableName =
        (
            SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
            FROM     INFORMATION_SCHEMA.TABLES
            WHERE         TABLE_TYPE = 'BASE TABLE'
                AND    QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName
                AND    OBJECTPROPERTY(
                        OBJECT_ID(
                            QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
                             ), 'IsMSShipped'
                               ) = 0
        )

        WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)

        BEGIN
            SET @ColumnName =
            (
                SELECT MIN(QUOTENAME(COLUMN_NAME))
                FROM     INFORMATION_SCHEMA.COLUMNS
                WHERE         TABLE_SCHEMA    = PARSENAME(@TableName, 2)
                    AND    TABLE_NAME    = PARSENAME(@TableName, 1)
                    AND    DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar', 'int', 'decimal')
                    AND    QUOTENAME(COLUMN_NAME) > @ColumnName
            )

            IF @ColumnName IS NOT NULL

            BEGIN
                INSERT INTO #Results
                EXEC
                (
                    'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630)
                    FROM ' + @TableName + ' (NOLOCK) ' +
                    ' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2
                )
            END
        END   
    END

    SELECT ColumnName, ColumnValue FROM #Results

END

Thursday, 10 December 2015

auto-format-entered-date-onkeypress

  C# textbox.Attributes.Add("onkeyup", "javascript:return getDate(event);");

JavaScript


 function getDate(elem){
var elemVal = elem.value;
var elemId = elem.id;

switch(elemVal.length){
case 2:
elemVal = elemVal+"/";
break;
case 5:
elemVal = elemVal+"/";
break;
}
document.getElementById(elemId).value = elemVal;
}


Sunday, 6 December 2015

Download feature not working within update-panel in asp-net






You cannot return an attachment in an UpdatePanel partial postback, since the results are used by the ScriptManager to update a DIV (not the whole response). The simplest fix for what you're trying to do would be to make your download button as a postback control. That would cause that button to initiate a full postback. Here's the code below to include in your Page_Load


ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(this.lnkDownload);

Thursday, 3 December 2015

Transpose a data table in C#

 private DataTable GenerateTransposedTable(DataTable inputTable)
        {
            DataTable outputTable = new DataTable();

            // Add columns by looping rows

            // Header row's first column is same as in inputTable
            outputTable.Columns.Add(inputTable.Columns[0].ColumnName.ToString());

            // Header row's second column onwards, 'inputTable's first column taken
            foreach (DataRow inRow in inputTable.Rows)
            {
                string newColName = inRow[0].ToString();
                outputTable.Columns.Add(newColName);
            }

            // Add rows by looping columns      
            for (int rCount = 1; rCount <= inputTable.Columns.Count - 1; rCount++)
            {
                DataRow newRow = outputTable.NewRow();

                // First column is inputTable's Header row's second column
                newRow[0] = inputTable.Columns[rCount].ColumnName.ToString();
                for (int cCount = 0; cCount <= inputTable.Rows.Count - 1; cCount++)
                {
                    string colValue = inputTable.Rows[cCount][rCount].ToString();
                    newRow[cCount + 1] = colValue;
                }
                outputTable.Rows.Add(newRow);
            }

            return outputTable;
        }
        protected DataTable Transpose(DataTable dt)
        {
            DataTable inputTable = dt;

            dt.Columns.Remove("SlNo");
            dt.Columns.Remove("Id#");
            dt.Columns["Stage"].ColumnName = "IndexFields";
            // Table shown in Figure 1.1

            DataTable transposedTable = GenerateTransposedTable(inputTable);
            return transposedTable;

        }

Monday, 30 November 2015

Tessnet2 Init-Method crashes with certain tessdata path

The problem is that if you have Tesseract installed there is an environment variable set ( TESSDATA_PREFIX )which contains the path of the tessdata. To use your own path it is necessary to uninstall Tesseract and delete the environment variable.