RDP- Automatically sign out of disconnected users?

  • Open the ‘Group Policy Editor’ for your server.
  • Navigate to: Local Computer Policy / Computer Configuration / Administrative Templates / Windows Components / Remote Desktop Services / Remote Desktop Session Host / Session Time Limits.
  • Find the key ‘Set time limit for disconnected sessions’
  • Enable and set the Time Limit at dropdown, what ever you need, I have used 8Hours.

Remove Empty Directories using c#

private static void DeleteEmptyDirectory(string startLocation)
{
foreach (var directory in Directory.GetDirectories(startLocation))
{
DeleteEmptyDirectory(directory);
if (Directory.GetFiles(directory).Length == 0 &&
Directory.GetDirectories(directory).Length == 0)
{
Directory.Delete(directory, false);
}
}
}

To turn on BitLocker Encryption in Windows 10/11.

  • You must be login using Administrator Account.
  • Click Start button, and then under Windows System, select Control Panel. In Control Panel, select System and Security, and then under BitLocker Drive Encryption, select Manage BitLocker.
  • Select Turn on BitLocker and then follow the instructions.
  • Make Sure you Save the Key.

How to ALTER all tables columns in SQL Database

declare @cols table (i int identity, tablename varchar(100), colname varchar(100))

insert into @cols
select TABLE_NAME, COLUMN_NAME
from information_schema.COLUMNS
where DATA_TYPE='nvarchar'

select * from @cols

declare @i int, @maxi int
select @i = 1, @maxi = MAX(i) from @cols

declare @sql nvarchar(max)

while(@i <= @maxi)
begin
    select @sql = 'alter table sub_history.'+tablename+' alter column ' + colname + ' varchar(255) NULL'  from @cols where i = @i
    exec sp_executesql @sql
    select @i = @i + 1
end

Exception- The definition for user-defined data type ‘MyTypeList’ has changed.

The definition for user-defined data type ‘MyTypeList’ has changed. Exception when we rename or changed any User defined TYPE and it used in stored procedures.
Stored Procedures which is using this type variable will not run and throwing the exception. If we have large numbers of SP then it will to time consuming or irritating to re-compile all SP one by one.
Instead of using this manual process this script will help to fix all references.

DECLARE @Name NVARCHAR(776);

DECLARE REF_CURSOR CURSOR FOR
SELECT referencing_schema_name + '.' + referencing_entity_name
FROM sys.dm_sql_referencing_entities('dbo.MyTypeList', 'TYPE');

OPEN REF_CURSOR;

FETCH NEXT FROM REF_CURSOR INTO @Name;
WHILE (@@FETCH_STATUS = 0)
BEGIN
    EXEC sys.sp_refreshsqlmodule @name = @Name;
	PRINT @Name
    FETCH NEXT FROM REF_CURSOR INTO @Name;
END;

CLOSE REF_CURSOR;
DEALLOCATE REF_CURSOR;

Installing TORTOISE-SVN. MSI error 2503 2502 errors

Install Tortoise-svn.msi, or MSI and other programs in the process reported 2503, 2502 error, mainly the user’s permissions

Open CMD as “Run As administrator”
Then enter msiexec/package “c:\temp\TortoiseSVN-1.14.1.29085-x64-svn-1.14.1.msi” in the inside;
Press Enter, and the installation box will pop up, then click Next to proceed.

ASP.NET MVC Redirect to Action from a Class

var context = new System.Web.HttpContextWrapper(System.Web.HttpContext.Current);
                var rc = new System.Web.Routing.RequestContext(context, new System.Web.Routing.RouteData());
                var urlHelper = new UrlHelper(rc);
                context.Response.Redirect(urlHelper.Action("login", "account"), false);
                return;

How to check SQL Job is in running state?

Method 1:
System Stored procedure: sp_help_job, returns information on the job, its steps, and more.

EXEC msdb.dbo.sp_help_job @Job_name = ‘Your Job Name’

Method 2:

IF EXISTS(SELECT 1
FROM msdb.dbo.sysjobs J
JOIN msdb.dbo.sysjobactivity A
ON A.job_id=J.job_id
WHERE J.name=N’Your Job Name’
AND A.run_requested_date IS NOT NULL
AND A.stop_execution_date IS NULL
)
PRINT ‘The job is running!’
ELSE
PRINT ‘The job is not running.’