Wednesday, November 27, 2013

Run Visual Studio as an Administrator in Windows 8

In Windows 8, you have to right-click devenv.exe and select "Troubleshoot compatibility".
1.    select "Troubleshoot program"
2.    check "The program requires additional permissions"
3.    click "Next", click "Test the program..."
4.    wait for the program to launch
5.    click "Next"
6.    select "Yes, save these settings for this program"
7.    click "Close"

If you are getting the error 'Unable to debug the server' when trying to debug a solution, try running visual studio as administrator.  The above forces Visual Studio to always run as administrator so you won't get this error again

Monday, September 30, 2013

T-SQL: List all table foreign keys

SELECT AS ForeignKey,
OBJECT_NAME(f.parent_object_id) AS TableName,
fc.parent_column_id) AS ColumnName,
OBJECT_NAME (f.referenced_object_id) AS ReferenceTableName,
fc.referenced_column_id) AS ReferenceColumnName
FROM sys.foreign_keys AS f
INNER JOIN sys.foreign_key_columns AS fc
ON f.OBJECT_ID = fc.constraint_object_id

Thursday, June 27, 2013

Find number of active SQL connections and kill them

How to find number of active SQL connections

    db_name(dbid) as [Database Name], 
    count(dbid) as [No Of Connections],
    loginame as [Login Name]
    dbid > 0
group by 
    dbid, loginame

How to kill active SQL connections to a single database

set nocount on
declare @databasename varchar(100)
declare @query varchar(max)
set @query = ''

set @databasename = 'My database'
if db_id(@databasename) < 4
         print 'system database connection cannot be killeed'

select @query=coalesce(@query,',' )+'kill '+convert(varchar, spid)+ '; '
from master..sysprocesses where dbid=db_id(@databasename)

if len(@query) > 0
print @query

Link to article

Tuesday, February 26, 2013

T-SQL: Get current date and time

Functions available to get the current date and time

Function Result Return type
GETDATE() 2013-02-26 20:54:24.057 DATETIME
CURRENT_TIMESTAMP 2013-02-26 20:54:24.057 DATETIME
GETUTCDATE() 2013-02-26 20:09:17.467 DATETIME
SYSDATETIME() 2013-02-26 21:09:17.4680514 DATETIME2
SYSUTCDATETIME() 2013-02-26 20:09:17.4680514 DATETIME2
SYSDATETIMEOFFSET() 2013-02-26 21:09:17.4680514 +01:00 DATETIMEOFFSET

UTC means Coordinated Universal Time and is widely used as time standard in web applications. The result above were taken on a PC with the time zone (UTC+01:00). Note that the UTC functions return the time one hour before the rest.

CURRENT_TIMESTAMP is the recommended one as it is the ANSI equivalent of GETDATE()

Don't forget that if you only need the current DATE or TIME, you can cast the return of the above functions to a DATE or TIME



which will return


For all DateTime functions visit the following link

Monday, January 21, 2013

ASP.NET: How to check ViewState size

Just enter the following code in the console of firebug or chrome developer tools and press Enter. Or call the code upon a button click
alert("View state is " + document.forms[0]["__VIEWSTATE"].value.length+ " bytes");