Monday, January 18, 2016
Dev Tools
- Resharper
- Red Gate SQL Prompt
- SQL Search
- SQL Compare
- SQL Data Compare
- SQL Source Control
- SQL Doc
- Winmerge
- Agent Ransack
- Beyond Compare
- Royal TS
- DotPeek
- SoapUI
- Vagrant UP
- ELMAH
- Source Tree
- TurtoiseGit
Unit Test on Private Methods in C#
There is an object in Microsoft.VisualStudio.TestTools.UnitTesting (Not sure
about NUNIT) called PrivateObject
Usage:
namespace Tests
{
[TestClass]
public class Test1
{
[TestMethod]
public void NoDuplicateTest()
{
string[] fileList = Directory.GetFiles(@"\\TestData\NoDuplicates");
string backUpFolder = @"\\TestData\NoDuplicates\Sent\";
PrivateObject privateMethod = new PrivateObject(new ClassName(string.Empty,string.Empty));
var result = privateMethod.Invoke("MethodName", new[] {fileList.GetType(), backUpFolder.GetType()}, new object[] {fileList, backUpFolder});
Assert.IsTrue((bool)result);
}
}
}
Wednesday, July 04, 2007
Best Practices Analyzer for SQL Server
I found these tools for Analysing SQL Server -
For 2000
http://www.microsoft.com/downloads/details.aspx?familyid=B352EB1F-D3CA-44EE-893E-9E07339C1F22&displaylang=en
For 2005
http://www.microsoft.com/downloads/details.aspx?FamilyId=DA0531E4-E94C-4991-82FA-F0E3FBD05E63&displaylang=en
Though didn't get much time to go in detail and analyse the reports but few glimpses impressed me.
For 2000
http://www.microsoft.com/downloads/details.aspx?familyid=B352EB1F-D3CA-44EE-893E-9E07339C1F22&displaylang=en
For 2005
http://www.microsoft.com/downloads/details.aspx?FamilyId=DA0531E4-E94C-4991-82FA-F0E3FBD05E63&displaylang=en
Though didn't get much time to go in detail and analyse the reports but few glimpses impressed me.
Tuesday, October 10, 2006
Randomizing rows
Select Top (@Top) from order by checksum(newID())
NewID - generates unique identifier
Checksum() - converts the uniqe identifier to integer / hash value.
NewID - generates unique identifier
Checksum() - converts the uniqe identifier to integer / hash value.
Scope_Identity, @@Identity, Ident_Current
Scope_Identity - Current Scope
@@Identity - Current Session
Ident_Current(TableName) - sort of max(PrimaryKey Column)
@@Identity - Current Session
Ident_Current(TableName) - sort of max(PrimaryKey Column)
Redirecting the non-secure connection to secure connection
Response.Buffer = True
if Request.ServerVariables("HTTPS") = "off" then
strMethod = Request.ServerVariables("REQUEST_METHOD")
strServer = Request.ServerVariables("SERVER_NAME")
strSciptName = Request.ServerVariables("SCRIPT_NAME")
strRedirect = "https://" & strServer & StrSciptName
strQryStr = Request.Querystring
if Len(strQryStr) > 0 Then strRedirect = strRedirect & "?" & strQryStr
if strMethod = "POST" then
Response.Write "<form method=post action=" & strRedirect & " name='f'>"
for x = 1 to Request.Form.Count()
tname = Request.Form.Key(x)
tvalue = Server.HTMLEncode(Request.Form.Item(x))
Response.Write "<input type=hidden name=" & tname & " value=""" & tValue & """>" & vbCrLf
next
Response.Write "<input type=submit value=Go></form>"
Response.Write "<script>" & vbCrLf
Response.Write "document.f.submit();" & vbCrLf
Response.Write "</script>"
else
Response.Redirect strRedirect
end if
end if
if Request.ServerVariables("HTTPS") = "off" then
strMethod = Request.ServerVariables("REQUEST_METHOD")
strServer = Request.ServerVariables("SERVER_NAME")
strSciptName = Request.ServerVariables("SCRIPT_NAME")
strRedirect = "https://" & strServer & StrSciptName
strQryStr = Request.Querystring
if Len(strQryStr) > 0 Then strRedirect = strRedirect & "?" & strQryStr
if strMethod = "POST" then
Response.Write "<form method=post action=" & strRedirect & " name='f'>"
for x = 1 to Request.Form.Count()
tname = Request.Form.Key(x)
tvalue = Server.HTMLEncode(Request.Form.Item(x))
Response.Write "<input type=hidden name=" & tname & " value=""" & tValue & """>" & vbCrLf
next
Response.Write "<input type=submit value=Go></form>"
Response.Write "<script>" & vbCrLf
Response.Write "document.f.submit();" & vbCrLf
Response.Write "</script>"
else
Response.Redirect strRedirect
end if
end if
Searching Databases for a String
Use this query to search a string in the metadata of the database.
SET NOCOUNT ON
-- Set @searchstr to value that you want to search for in existing
-- procedures (all single quotes and % signs are required)
DECLARE @searchstr VARCHAR(50)
SELECT @searchstr = '''%1444%'''
SELECT @searchstr = RTRIM (@searchstr)
SELECT @searchstr AS Search_String
DECLARE @objname NVARCHAR(776)
DECLARE @dbname SYSNAME
DECLARE @blankspaceadded INT
DECLARE @basepos INT
DECLARE @currentpos INT
DECLARE @textlength INT
DECLARE @lineid INT
DECLARE @addonlen INT
DECLARE @lfcr INT
DECLARE @definedlength INT
DECLARE @syscomtext NVARCHAR(4000)
DECLARE @line NVARCHAR(255)
CREATE TABLE #storedproctext (
stored_proc_name VARCHAR(128), lineid
INTEGER,text NVARCHAR(255)
)
DECLARE sp_name_cursor SCROLL CURSOR
FOR SELECT name
FROM sysobjects (NOLOCK)
WHERE TYPE = 'P'
ORDER BY name
FOR READ ONLY
OPEN sp_name_cursor
FETCH NEXT FROM sp_name_cursor
INTO @objname
WHILE (@@FETCH_STATUS <> -1)
BEGIN
IF (@@FETCH_STATUS <> -2)
BEGIN
SELECT @definedlength = 255
SELECT @blankspaceadded = 0
SELECT @dbname = PARSENAME(@objname,3)
SELECT @lfcr = 2
SELECT @lineid = 1
DECLARE syscomcursor CURSOR
FOR SELECT text
FROM syscomments
WHERE id = OBJECT_ID(@objname)
AND encrypted = 0
ORDER BY number, colid
FOR READ ONLY
OPEN syscomcursor
FETCH NEXT FROM syscomcursor INTO @syscomtext
WHILE @@FETCH_STATUS >= 0
BEGIN
SELECT @basepos = 1
SELECT @currentpos = 1
SELECT @textlength = LEN(@syscomtext)
WHILE @currentpos != 0
BEGIN
SELECT @currentpos = CHARINDEX(CHAR(13)+CHAR(10),@syscomtext, @basepos)
IF @currentpos != 0
BEGIN
WHILE (ISNULL(LEN(@line),0) + @blankspaceadded + @currentpos-@basepos + @lfcr) > @definedlength
BEGIN
SELECT @addonlen = @definedlength-(ISNULL(LEN(@line),0) + @blankspaceadded)
INSERT #storedproctext VALUES ( @objname, @lineid,
ISNULL(@line, N'') +
ISNULL(SUBSTRING(@syscomtext, @basepos, @addonlen), N''))
SELECT @line = NULL, @lineid = @lineid + 1,@basepos = @basepos + @addonlen,@blankspaceadded = 0
END
SELECT @line = ISNULL(@line, N'') +ISNULL(SUBSTRING(@syscomtext, @basepos, @currentpos-@basepos + @lfcr),N'')
SELECT @basepos = @currentpos+2
INSERT #storedproctext VALUES( @objname, @lineid,@line )
SELECT @lineid = @lineid + 1
SELECT @line = NULL
END
ELSE
BEGIN
IF @basepos < @textlength
BEGIN
WHILE (ISNULL(LEN(@line),0) + @blankspaceadded + @textlength-@basepos+1 ) > @definedlength
BEGIN
SELECT @addonlen = @definedlength - (ISNULL(LEN(@line),0) + @blankspaceadded )
INSERT #storedproctext VALUES
( @objname, @lineid,ISNULL(@line, N'') + ISNULL(SUBSTRING(@syscomtext, @basepos, @addonlen), N''))
SELECT @line = NULL, @lineid = @lineid + 1,@basepos = @basepos + @addonlen,@blankspaceadded = 0
END
SELECT @line = ISNULL(@line, N'') +ISNULL(SUBSTRING(@syscomtext, @basepos, @textlength-@basepos+1 ), N'')
IF CHARINDEX(' ', @syscomtext, @textlength+1 ) > 0
BEGIN
SELECT @line = @line + ' ', @blankspaceadded =1
END
BREAK
END
END
END
FETCH NEXT FROM syscomcursor INTO @syscomtext
END
IF @line IS NOT NULL
INSERT #storedproctext VALUES( @objname, @lineid, @line )
END
CLOSE syscomcursor
DEALLOCATE syscomcursor
FETCH NEXT FROM sp_name_cursor
INTO @objname
END
CLOSE sp_name_cursor
DEALLOCATE sp_name_cursor
DECLARE @strSELECT NVARCHAR(300)
SET @strSELECT = 'SELECT DISTINCT (SUBSTRING(stored_proc_name,1,60)) AS Stored_Procedure_Name FROM #storedproctext WHERE text like ' +
@searchstr + 'ORDER BY Stored_Procedure_Name'
EXEC sp_executesql @strSELECT
DROP TABLE #storedproctext
SET NOCOUNT ON
-- Set @searchstr to value that you want to search for in existing
-- procedures (all single quotes and % signs are required)
DECLARE @searchstr VARCHAR(50)
SELECT @searchstr = '''%1444%'''
SELECT @searchstr = RTRIM (@searchstr)
SELECT @searchstr AS Search_String
DECLARE @objname NVARCHAR(776)
DECLARE @dbname SYSNAME
DECLARE @blankspaceadded INT
DECLARE @basepos INT
DECLARE @currentpos INT
DECLARE @textlength INT
DECLARE @lineid INT
DECLARE @addonlen INT
DECLARE @lfcr INT
DECLARE @definedlength INT
DECLARE @syscomtext NVARCHAR(4000)
DECLARE @line NVARCHAR(255)
CREATE TABLE #storedproctext (
stored_proc_name VARCHAR(128), lineid
INTEGER,text NVARCHAR(255)
)
DECLARE sp_name_cursor SCROLL CURSOR
FOR SELECT name
FROM sysobjects (NOLOCK)
WHERE TYPE = 'P'
ORDER BY name
FOR READ ONLY
OPEN sp_name_cursor
FETCH NEXT FROM sp_name_cursor
INTO @objname
WHILE (@@FETCH_STATUS <> -1)
BEGIN
IF (@@FETCH_STATUS <> -2)
BEGIN
SELECT @definedlength = 255
SELECT @blankspaceadded = 0
SELECT @dbname = PARSENAME(@objname,3)
SELECT @lfcr = 2
SELECT @lineid = 1
DECLARE syscomcursor CURSOR
FOR SELECT text
FROM syscomments
WHERE id = OBJECT_ID(@objname)
AND encrypted = 0
ORDER BY number, colid
FOR READ ONLY
OPEN syscomcursor
FETCH NEXT FROM syscomcursor INTO @syscomtext
WHILE @@FETCH_STATUS >= 0
BEGIN
SELECT @basepos = 1
SELECT @currentpos = 1
SELECT @textlength = LEN(@syscomtext)
WHILE @currentpos != 0
BEGIN
SELECT @currentpos = CHARINDEX(CHAR(13)+CHAR(10),@syscomtext, @basepos)
IF @currentpos != 0
BEGIN
WHILE (ISNULL(LEN(@line),0) + @blankspaceadded + @currentpos-@basepos + @lfcr) > @definedlength
BEGIN
SELECT @addonlen = @definedlength-(ISNULL(LEN(@line),0) + @blankspaceadded)
INSERT #storedproctext VALUES ( @objname, @lineid,
ISNULL(@line, N'') +
ISNULL(SUBSTRING(@syscomtext, @basepos, @addonlen), N''))
SELECT @line = NULL, @lineid = @lineid + 1,@basepos = @basepos + @addonlen,@blankspaceadded = 0
END
SELECT @line = ISNULL(@line, N'') +ISNULL(SUBSTRING(@syscomtext, @basepos, @currentpos-@basepos + @lfcr),N'')
SELECT @basepos = @currentpos+2
INSERT #storedproctext VALUES( @objname, @lineid,@line )
SELECT @lineid = @lineid + 1
SELECT @line = NULL
END
ELSE
BEGIN
IF @basepos < @textlength
BEGIN
WHILE (ISNULL(LEN(@line),0) + @blankspaceadded + @textlength-@basepos+1 ) > @definedlength
BEGIN
SELECT @addonlen = @definedlength - (ISNULL(LEN(@line),0) + @blankspaceadded )
INSERT #storedproctext VALUES
( @objname, @lineid,ISNULL(@line, N'') + ISNULL(SUBSTRING(@syscomtext, @basepos, @addonlen), N''))
SELECT @line = NULL, @lineid = @lineid + 1,@basepos = @basepos + @addonlen,@blankspaceadded = 0
END
SELECT @line = ISNULL(@line, N'') +ISNULL(SUBSTRING(@syscomtext, @basepos, @textlength-@basepos+1 ), N'')
IF CHARINDEX(' ', @syscomtext, @textlength+1 ) > 0
BEGIN
SELECT @line = @line + ' ', @blankspaceadded =1
END
BREAK
END
END
END
FETCH NEXT FROM syscomcursor INTO @syscomtext
END
IF @line IS NOT NULL
INSERT #storedproctext VALUES( @objname, @lineid, @line )
END
CLOSE syscomcursor
DEALLOCATE syscomcursor
FETCH NEXT FROM sp_name_cursor
INTO @objname
END
CLOSE sp_name_cursor
DEALLOCATE sp_name_cursor
DECLARE @strSELECT NVARCHAR(300)
SET @strSELECT = 'SELECT DISTINCT (SUBSTRING(stored_proc_name,1,60)) AS Stored_Procedure_Name FROM #storedproctext WHERE text like ' +
@searchstr + 'ORDER BY Stored_Procedure_Name'
EXEC sp_executesql @strSELECT
DROP TABLE #storedproctext