Thursday, June 19, 2014

Maintain Scroll Position after Asynch Postback

  
    var goTop = parseInt($.cookie("posName"));
    if (goTop) {
        $(document).scrollTop(goTop);
        $.cookie("posName""");
    }
 
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    try {
        prm.add_initializeRequest(InitializeRequest);
        prm.add_endRequest(EndRequest);
    }
    catch (err) { }
    
 
    
    function InitializeRequest(sender, args) {
        try {
            //debugger;
            var elem = document.getElementById('Container');
            var scrollTop = $(document).scrollTop();
            debugger;
            $.cookie("posName", scrollTop);
            
            showHideLoading(truetrue);
 
        } catch (err) { }
 
    }

JQueryUI DatePicker doesnt work in UpdatePanel after partial post back?

Heres the solution:
Im showing an alert if no data available, after alert the datepicker stopped working due to partial post, adding EndRequestHandlerfixed the issue.

 <script type="text/javascript">
     $(document).ready(function () {
         Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
 
         function EndRequestHandler(sender, args) {
             
             $('.datepicker').datepicker({ dateFormat: 'dd-mm-yy' });
         }
 
     });
    </script>  

SQL Server Variable Scope inside loops, Not what U think if u come from C#/Java...

Guess what prints in this loop? 

Will @i b 1 every time ? Will @outTbl  only have one row?
Actually no, scope of loop variables is to the script, a Gotcha 4 ya!
If u use table variables in loop make sure u delete on each iteration to clear.!


Related:
SQL Server variable scope is per batch or the entire function/procedure/trigger, not per black/nested construct

set nocount on

declare @tt int
set @tt =10
while @tt>0
begin
-- scope to loop or scope to sript?
declare @i int
Declare @outTbl TABLE(Release_App_schedule_ID int)

insert into @outTbl
select  @tt
set @i = isnull(@i,0) + 1

select '@outTbl', * from @outTbl
select '@i', @i
   
    set @tt=@tt-1

end


IS SAME AS


set nocount on

declare @tt int
-- scope to loop or scope to sript?
declare @i int
Declare @outTbl TABLE(Release_App_schedule_ID int)


set @tt =10
while @tt>0
begin


insert into @outTbl
select  @tt
set @i = isnull(@i,0) + 1

select '@outTbl', * from @outTbl
select '@i', @i
   
    set @tt=@tt-1

end

Wednesday, June 18, 2014

Search and Print sprocs in SQL Server SUPER fast

Tired of using the SSMS Object Explorer to find sprocs/functions and the delay? 


Tired of the delay to view a sproc when clicking on the treeview in SSMS? Well here is the super duper fast way to view sprocs, If u know the name or part of the name of the sproc U want U can use the below script to BOOM....Get ur sproc definition printed in about...Oh....3 ms. Boom

1. Create the sp_LongPrint sproc (below), this is needed to PRINT large strings, because the default PRINT() function only allows like 8000, so create this first! credit from these guys : SP_LongPrint author

2. Run the below script GetSprocs.sql, enter the full or part name of your sproc u want, or a date it was altered, or search by a key word, Just plain bad ass. When U run the script, the sproc will show up in the Messages panel.

This is the difference between 1second and 1minute to find a sproc, Add that up over a day/week/month and U just saved a shitload of time, Time = $$$...now back to work...

--GetSprocs.sql

use master
go
set nocount on
DECLARE MY_CURSOR Cursor
FOR
SELECT r.Routine_Definition, routine_name
FROM INFORMATION_SCHEMA.Routines r
where
--last_altered > '2013-11-16 20:20:26.193' -- search by date?
routine_name like '%print%' -- search by name?
--ROUTINE_DEFINITION LIKE '%Metal_UID%' -- search by contents in sproc?
order by last_altered desc
DECLARE @sprocR VARCHAR(MAX)
set @sprocR = ''
OPEN MY_CURSOR
    DECLARE @sproc VARCHAR(MAX) , @name varchar(max), @txt varchar(max)
    FETCH NEXT FROM MY_CURSOR INTO @sproc, @name
    WHILE (@@FETCH_STATUS <> -1)
   BEGIN
        IF (@@FETCH_STATUS <> -2)
    select @name = 'dbo.' + @name
    select @txt = '-- *************************START procedure ' + @name
    exec [sp_LongPrint]  @txt
-- get sproc definition
    SELECT @txt= OBJECT_DEFINITION(OBJECT_ID(@name))
        exec [sp_LongPrint] @txt
    select @txt = 'go '
    exec [sp_LongPrint] @txt
    select @txt = '-- *************************END procedure ' + @name
    exec [sp_LongPrint] @txt
           FETCH NEXT FROM MY_CURSOR INTO @sproc, @name
    END
CLOSE MY_CURSOR
DEALLOCATE MY_CURSOR
GO



--[sp_LongPrint]

USE master
GO
/****** Object:  StoredProcedure [dbo].[sp_LongPrint]    Script Date: 12/8/2013 8:53:15 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create PROCEDURE [dbo].[sp_LongPrint]
      @String NVARCHAR(MAX)

AS

/*
Example:

exec [sp_LongPrint] @string =
'This String
Exists to test
the system.'

*/

/* This procedure is designed to overcome the limitation
in the SQL print command that causes it to truncate strings
longer than 8000 characters (4000 for nvarchar).

It will print the text passed to it in substrings smaller than 4000
characters.  If there are carriage returns (CRs) or new lines (NLs in the text),
it will break up the substrings at the carriage returns and the
printed version will exactly reflect the string passed.

If there are insufficient line breaks in the text, it will
print it out in blocks of 4000 characters with an extra carriage
return at that point.

If it is passed a null value, it will do virtually nothing.

NOTE: This is substantially slower than a simple print, so should only be used
when actually needed.
 */

DECLARE
               @CurrentEnd BIGINT, /* track the length of the next substring */
               @offset tinyint /*tracks the amount of offset needed */


set @string = replace(  replace(@string, char(13) + char(10), char(10))   , char(13), char(10))

WHILE LEN(@String) > 1
BEGIN

           
    IF CHARINDEX(CHAR(10), @String) between 1 AND 4000
    BEGIN

           SET @CurrentEnd =  CHARINDEX(char(10), @String) -1
           set @offset = 2
    END
    ELSE
    BEGIN
           SET @CurrentEnd = 4000
            set @offset = 1
    END
 

    PRINT SUBSTRING(@String, 1, @CurrentEnd)
                                               
    set @string = SUBSTRING(@String, @CurrentEnd+@offset, 1073741822)
           
END /*End While loop*/





Friday, June 13, 2014

Symantec VIP Service crashes , and no one on Internet has a solution

If u ever get this error, if u use VIP service for your VPN security token, take solace I have encountered the below error twice, and NOTHING resolves it, UnInstall - ReInstall doesnt work...I found a work-around.....You gotta clear out the local temp files that this pain in the butt app uses....
I 4 got how I fixed it like 2 weeks ago, Im digging thru old notes now and Ill post again shortly with the exact solution,

Ok heres what I had to do:
1. Check ur log file: to see errors:
C:\Users\[user]\AppData\LocalLow\Symantec\VIPAccessClient
2.  VIP Access -> Araow -> Reset Credential -> Close/Open VIP -> Login again, works

http://[YourWebSecuritySite]VPNSoftToken.aspx

then
http://[YourWebSecuritySite]/vipssp

then
https://ssp.vip.symantec.com/vipssp/home.v?successUrl=http://...
then
                enter sec code
        then

      reboot and it worked






Tools I can't live without, Save time !

These simple tools are a daily life-saver for, They are the difference between 5 min and 2 hours, and that means $$$, The best developers is sometimes not the smartest, he or she might just be the best because they are the most productive and adhere to KISS and SOLID as much as they can.

Utility Apps

TextPad : Fastest File System searching, e.g: Find ALL sql and c# code that has the word Event_ID
KillProcess.exe : Multi Select Processes and Kill em!! Task Manager on steroids
DebugView: See all the output from System.Diagnostics.Debug.WriteLine() and default output
ProcessExplorer (kill those handles that lock files!)
XPathTester : when Im in XML hell....This saves the day!
WinDiff : Old school from VS 6.0 and still awesome!
Winrar : boom extract!

Zoho: Cloud based notebook and remote assistance is what I use!
notepad.cc : awesome, simple notepad in cloud
GoogleDrive: Duh!
JSFiddle
SQLFiddle/
SQLTidy All 3 are super utilities

In SSMS:

SqlTreeo: Create Folders in SSMS Object Explorer, The way SSMS SHOULD work but doesn't!
sp_who3 : Sproc that shows who, what, when and where for SPIDS! Who is killing my DB? This answers
vw_DBAObjects : a view to search ALL SQL Objects that contain a keyword, Views, udfs, Tables and Sproc are union-ed, This view saves MASSIVE TIME! Stop using SSMS to find dependencies.
SplitEx : udf to split a string!




VS.Net

JS Parser AddIn : Oh man! Best ever most awesome shows JS functios in Outline, handles JQuery to! If ur doing web dev and are NOT a JS "expert" U gotta try this!!!!
Code Snippets: Custom stuff, e.g: try catch in one click! ect...These are my settings for vs.net, macros, and snippets
Power Command: Adds all the menus that MS forgot to add...Like Collapse Solution, Copy Reference

If U like to do more in less time to, let me know what Ur fav tools are to!

Thursday, June 12, 2014

VS Themes and Settings and a wierd name 'son of obsidian

Workin' a hardcore 12 hours stint of ssms and vs.net got me wanting a diff color to focus my eyes on, the default settings create a strain afta' 9 hours....Found these gems and played with a few but ended up going back to default color scheme, When u got a hard deadline changing VS settings is a risk...Slowing down by a mere minute can cost 1000's ...Anyway check the color...And I even found a few SSMS setting files to use here
http://www.jimmcleod.net/blog/index.php/2012/06/26/beautify-your-management-studio-2012/
and vs.net here
http://studiostyl.es/schemes/son-of-obsidian


C# code28

#region Studio Style
class Program : IThemeable
{
    static int _I = 1;
    delegate void DoSomething();

    /// <summary>
    /// The quick brown fox jumps over the lazy dog
    /// THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
    /// </summary>
    static void Main(string[] args)
    {
        string normalStr = "The time now is approximately " + DateTime.Now;
        Uri Illegal1Uri = new Uri("http://packmyboxwith/jugs.html?q=five-dozen&t=liquor");
        Regex OperatorRegex = new Regex(@"\S#$", RegexOptions.IgnorePatternWhitespace);

        for (int O = 0; O < 123456789; O++)
        {
            _I += (O % 3) * ((O / 1) ^ 2) - 5;
            if (!OperatorRegex.IsMatch(Illegal1Uri.ToString()))
            {
                // no idea what this does!?
                Console.WriteLine(Illegal1Uri + normalStr);
            }
        }
    }
}
#endregion

Advanced highlighting