Saturday, 6 February 2021

List table triggers in SQL Server database

 select schema_name(tab.schema_id) + '.' + as [table], as trigger_name,
    case when is_instead_of_trigger = 1 then 'Instead of'
        else 'After' end as [activation],
    (case when objectproperty(trig.object_id, 'ExecIsUpdateTrigger') = 1 
            then 'Update ' else '' end
    + case when objectproperty(trig.object_id, 'ExecIsDeleteTrigger') = 1 
            then 'Delete ' else '' end
    + case when objectproperty(trig.object_id, 'ExecIsInsertTrigger') = 1 
            then 'Insert ' else '' end
    ) as [event],
    case when trig.[type] = 'TA' then 'Assembly (CLR) trigger'
        when trig.[type] = 'TR' then 'SQL trigger' 
        else '' end as [type],
    case when is_disabled = 1 then 'Disabled'
        else 'Active' end as [status],
    object_definition(trig.object_id) as [definition]
from sys.triggers trig
    inner join sys.objects tab
        on trig.parent_id = tab.object_id
order by schema_name(tab.schema_id) + '.' +,;

Saturday, 16 January 2021

Install windows service command line with different name

Install windows service command line with different name

Install Service
SC create MyService binPath= "MyService.exe" DisplayName= "MyService"  

Stop Service
SC STOP MyService

Delete Service

Tuesday, 5 January 2021

SSRS export to excel/Pdf in console application in C#

SSRS (SQL Server Reporting Services) export to excel in console application in C#


using RestSharp;
using RestSharp.Authenticators;
using System;
using System.IO;

   private static void GenerateReport(string strReportPath,string _parameters, string FileName, string FileType = "Excel")
                string strReportPath = strReportPath;//"UserDetails"
                //string FileType = "Excel";
                string URL = ConfigurationManager.AppSettings["ReportServerPath"].ToString() + "?" + strReportPath + "&rs:Command=Render&rs:Format=" + FileType + _parameters;
                var client = new RestClient(URL);                
                client.Authenticator = new NtlmAuthenticator(ConfigurationManager.AppSettings["ReportUser"].ToString(), ConfigurationManager.AppSettings["ReportPwd"].ToString());
                var request = new RestRequest(Method.GET);
                Byte[] FileByte = client.DownloadData(request);
                ByteToFile(FileName, FileByte, FileType);
            catch (Exception ex)

        static void ByteToFile(string FileName, Byte[] bytes, string FileType)
            string path = AppDomain.CurrentDomain.BaseDirectory + "\\Data";
            if (!Directory.Exists(path))
            path = AppDomain.CurrentDomain.BaseDirectory + "\\Data\\" + System.DateTime.Now.ToString("yyyyMMdd");
            if (!Directory.Exists(path))
            if (FileType == "Excel")
                FileName += ".xls";
                FileName += ".pdf";
            File.WriteAllBytes(path + "\\"+ FileName, bytes);

Excel Export Example:

GenerateReport("UserDetails", "&From=11-Aug-2020&UpTo=01-Jan-2021", "UserDetails","Excel');

PDF Export Example:

GenerateReport("UserDetails", "&From=11-Aug-2020&UpTo=01-Jan-2021", "UserDetails","Pdf');

Monday, 9 November 2020

Try cleaning-up your local repository with

 Try cleaning-up your local repository with:

$ git gc --prune=now

$ git remote prune origin

git diff --name-only "@{3 days ago}" "@{2 days ago}"

Thursday, 9 July 2020

Types of SQL Server Backups

SQL Server offers many options for  creating backups.  In a previous topic, Recovery Models, we discussed what types of backups can be performed based on the recovery model of the database.  In this section we will talk about each of these backup options and how to perform these backups using SSMS and T-SQL.

The different types of backups that you can create are as follows:

  • Full backups
  • Differential backups
  • File backups
  • Filegroup backups
  • Partial backups
  • Copy-Only backups
  • Mirror backups
  • Transaction log backups

Thursday, 4 June 2020

Live Darshan From Shree Kashi Vishwanath Temple Varanasi

Live Darshan From Shree Kashi Vishwanath Temple Varanasi
(श्री काशी विश्वनाथ मंदिर से लाइव दर्शन )


Friday, 20 March 2020

Best Practices for Personal Productivity

Best Practices for Personal Productivity:

  1. Structure your day like you would in the office: When working from home, you're your own personal manager. Without things like an in-person meeting schedule to break up your day, you can be quick to lose focus or burn out. To stay on schedule, segment what you'll do and when for the day. 
  2. Choose a dedicated workspace: Just because you're not working at an office doesn't mean you can't, well, have an office. Rather than cooping yourself up in your room or on the couch -- spaces that are associated with leisure time -- dedicate a specific room or surface in your home to work.
  3. Your calendar is sacred: Set timers for food breaks, leisure walks, time off, family obligations, etc. Call out good work! Do this more often than usual and with consistency. Start your meetings with kudos.
  4. Make it harder for yourself to mess around on social media: Social media is designed to make it easy for you to open and browse quickly. At work, though, this convenience can be the detriment of your productivity. To counteract your social networks' ease of use during work hours, remove them from your browser shortcuts and, according to Fast Company, log out of every account. You might even consider working primarily in a private or if you're using Chrome, an "Incognito" browser window. This ensures you stay signed out of all your accounts and each web search you conduct doesn't autocomplete the word you're typing. It's a guarantee that you won't be tempted into taking too many social breaks during the day.
  5. Commit to doing more: Projects always take longer than you initially think they will. For that reason, you'll frequently get done less than you set out to do. So, just as you're encouraged to overestimate how much time you'll spend doing one thing, you should also overestimate how many things you'll do during the day. Even if you come up short of your goal, you'll still come out of that day with a solid list of tasks filed under 'complete.'
  6. Work when you're at your most productive: Nobody sprints through their work from morning to evening -- your motivation will naturally ebb and flow throughout the day. When you're working from home, however, it's all the more important to know when those ebbs and flows will take place and plan your schedule around it.
    To capitalize on your most productive periods, save your harder tasks for when you know you'll be in the right headspace for them. Use slower points of the day to knock out the easier, logistical tasks that are also on your plate. Verily Magazine calls these tasks "small acts of success," and they can help build your momentum for the heavier projects that are waiting for you later on.
  7. Communicate expectations with anyone who will be home with you: Of course, you might be working from home but still have "company." Make sure any roommates, siblings, parents, spouses, etc. respect your space during work hours. Just because you're working from home doesn't mean you're home.
  8. Take clear breaks: It can be so easy to get distracted as a telecommuter that you avoid breaks altogether. Don't let the guilt of working in the building you sleep in prevent you from taking five to relax. Rather than just opening YouTube and watching some comfort clips, however, use your breaks to get away from your desk. Go for a walk outside or spend time with others who might also be in the house.
  9. Eat on time, eat healthy, stay hydrated: Set timelines for this on your calendar so you’re not skipping meals. Hydrate. Stretch every 30 minutes. Hydrate. Have strict timelines on when you eat. 
  10. Prepare your meals the night before: When you're in your own home, it can be tempting to spend time preparing a really nice breakfast and lunch for yourself, chopping and cooking included. Don't use precious minutes making your food the day of work -- cook it the night before.
    Preparing food ahead of time ensures you can actually use your meal times to eat, and that you aren't performing non-work tasks that spend energy better used at your desk.
  11. Pick a definitive finishing time each day: You might be under the impression that working from home establishes more work-life balance, but be careful with that assumption. Working from home can also feel confusing -- you can get so caught up in your activity, in a relaxing environment, that you lose complete track of time.
  12. Call out good work! : Do this more often than usual and with consistency. Start your meetings with kudos.

List table triggers in SQL Server database

 select schema_name(tab.schema_id) + '.' + as [table], as trigger_name,     case when is_instead_of_trigger =...