IT Nota

  • Home
  • How To
  • .NET
  • WordPress
  • Contact

How to Install Python on Windows Server

Python is an excellent general purpose language that can be used for batch processing and other tasks on your server.

To install Python on Windows Server operating system, you just need to run the installer and use the simplest configuration.

Steps to Install Python on Windows Server Operating System

  1. Download the installer (full as opposed to the web sintaller) and save it to your temp folder.

    Python installer in Windows Temp folder

  2. Right-click on the file and select Run as administrator.

    Run Python installer as administrator

  3. You’ll see a User Account Control popup window with a question, “Do you want to allow the following program to make changes to this computer?” Just click on Yes.

  4. Check the Add Python 3.7 to PATH checkbox at the bottom of the window (or whatever the latest version you’re installing).

    Install Python setup screen

  5. If you don’t care where the program is installed, you can just clik on the Install Now, there’s nothing wrong with the setup and Python will run and this is generally fine for desktop installation.

    For server installation, you should be more mindful with the program location better location rather than the default installation under a specific user folder who ran the installer. So it’s better to choose Customize installation.

  6. In Optional Features screen, make sure you at least check the following: pip, py launcher, and for all users. Click Next.

    Python customize installation optional features

  7. On the next screen, Advanced Options, make sure you check Install for all users which then will change the value of Customize install location, just accept the default installation in C:\Program Files unless you have a reason to install it somewhere else. Click Install.

    Python customize installation advanced options for all users

  8. Once you see Setup was successful just click the Close button.

  9. Make sure that C:\Program Files\Python37 and C:\Program Files\Python37\Scripts are in the Path of your System variables.

    Python added to path in Windows Environment Variables

    If you’re able to click on Edit button, you can see all the path entries in each line which is easier to read and edit. In this case, the button is greyed out due to the group policy.

As a final check, you can open Programs and Features and check if Python and Python Launcher are shown.

Programs and Features

That’s all there is to have your server running Python scripts.

If you work mostly with Microsoft stack and need to connect to a SQL Server database using Python, then check this post about Python SQL Server Driver.

Further Reading

How to Activate Built-in Web Server
How to Use Python to Connect to SQL Server

Download

Python Download

May 22, 2019 Filed Under: How To Tagged With: Microsoft, Python, Windows Server

How to Add Custom Logging to SSIS Package

This post will demonstrate one way to add custom logging to SSIS Package. This is still considered one of the better practice that comes in handy when we need to troubleshoot SSIS packages and track progress.

There’s no better way to explain the concept other than giving a simple case example on how to add it to a real SSIS package.

For starter, the package in this example does a simple data load from LDAP table to a SQL Server table with some minimal check done with a Script Component.

Setup Global Variables for Logging

Before we do anything else, it’s recommended to setup a few global variables that we can use to keep track of the log variables.

Setup global variables for the log folder and filename with a prefix of gv for Global Variable. The use of prefix is very handy since all those global variables will be sorted nicely and will be easy to find during troubleshooting.

SSIS Global Variables setup
*One of the global variable is made up with an expression to dynamically name the log file according to today’s date.

@[Log::gv_RootPath] + "\\" +  @[Log::gv_LogDir] + "\\" + REPLACE(@[Log::gv_LogFileName], ".log", "") + "-" + SUBSTRING((DT_STR, 50, 1252) GETDATE(), 1, 10) + ".log"

Setup Log File Connection Manager

We are going to write the log to a text file, so create a new connection manager by selecting New Flat File Connection… and name it CM_FF_DST_Log.

Add new Flat File Connection Manager for SSIS Logging

It’s not too important what you want to name the file, because we want to use a dynamic file name based on the date that we’ve already setup with gv_LogFile global variable. Once, it’s setup you can do a right-click on the CM_FF_DST_Log and check on the Properties.

Expand the Expressions and click on the ellipsis in ConnectionString, an Expression Builder window will be opened.

Expand the Variables and Parameters and double-click on the Log::gv_LogFile so it will go to the Expression: box and click OK.

SSIS Connection Manager Properties Expression Builder

Now, when you double-click on the CM_FF_DST_Log connection manager, the log filename will be dynamically populated according to today’s date (see File: below). You can close the window by clicking OK or Cancel as we do not need to modify this setup further.

SSIS File Connection Manager Editor Create File for Logging

Enable SSIS Logging

We finished the connection manager for the log file, but we still need to enable SSIS Logging and associate that with the log connection manager. In order to do this, go to the top menu and click on SSIS and select Logging… as shown below.

SSIS Logging menu

You will next see a new Configure SSIS Logs window. Make sure all checkboxes under the Containers are checked. We also need to make sure that on the right pane of that window, under Details we check at least OnError, OnTaskFailed, and OnWarning.

Important: Make sure this step is done for each container listed on the left side (yes, it’s tedious, but fortunately you only need to set this up once per project).

SSIS Configure SSIS Logs Details

Go to the Providers and Logs, now we want to setup the log provider to use the flat file connection manager CM_FF_DST_Log. If you setup the connection manager correctly, CM_FF_DST_Log should be available on the Configuration drop-down list. This part also needs to be done for each container.

SSIS configure logs with Flat File Connection Managers as the provider

Once this setup is complete, we’re ready to add our log in SSIS workflow.

Write the Log

Try to put the tasks within containers for each task you want to add log to.

SSIS Package Database Load

If you double-click on the SCR Log Start and click on the Edit Script…, here’s the C# script contained in the task:

SCR Log Start

public void Main()
{
  Dts.Log("Package starting...", 99, null);

  foreach(Variable v in Dts.Variables)
  {
    Dts.Log("Name: " + v.Name, 99, null);
    Dts.Log("Value: " + v.Value.ToString(), 99, null);
  }
 
  Dts.TaskResult = (int)ScriptResults.Success;
}

Data Flow Counters

Under the Data Flow tab, you can see that from each data source, there’s a Row Count component that is attached to it. In this process, the values from the Row Count component will be passed on to the global variables we setup. In this example, they are gvCNT_LDAPRowCount and gvCNT_LDAPRowCountBlanks.

SSIS Row Count Component to Global Variable

And we include a detailed count of each count and grand total in a Script Task called SCR LDAP Row Counts. Just make sure we also include the global variables in the ReadOnlyVariables like so, then click on the Edit Script….

SSIS Assign to Global Variables with Script Task

Add the calculation logic and write to the log.

public void Main()
{
  // Get LDAP row count with sAMAccountName row counts
  int rowLDAPCount = (int)Dts.Variables["CNT::gvCNT_LDAPRowCount"].Value;
 
  // Get LDAP row count that are blank
  int rowLDAPBlanks = (int)Dts.Variables["CNT::gvCNT_LDAPRowCountBlanks"].Value;
 
  // Total rows
  int rowTotalLDAPCount = 0;
  rowTotalLDAPCount = rowLDAPCount + rowLDAPBlanks;
 
  // Log if LDAP has no records.
  if (rowTotalLDAPCount > 0)
  {
    Dts.Log(String.Format(" Total records with NT ID accounts: {0}", rowLDAPCount.ToString("###,###,###")), 99, null);
    Dts.Log(String.Format(" Total records without NT ID accounts: {0}", rowLDAPBlanks.ToString("###,###,###")), 99, null);
    Dts.Log(String.Format(" Total records from LDAP source: {0}", rowTotalLDAPCount.ToString("###,###,###")), 99, null);
  } else
  {
    Dts.Log(String.Format(" No record is found in LDAP source. {0}", rowTotalLDAPCount.ToString("###,###,###")), 99, null);
  }
  
  Dts.TaskResult = (int)ScriptResults.Success;
}

At the end of the process flow, just add another script SCR Log Finish to indicate the end of the logging session after the package run.

SCR Log Finish

public void Main()
{
  Dts.Log("~ Log Cleanup Package completed. ~", 99, null);
 
  Dts.TaskResult = (int)ScriptResults.Success;
}

So what does the log file look like? Here’s an example what’s reported. It’s probably easier to read if you look at the raw file instead.

#Fields: event,computer,operator,source,sourceid,executionid,starttime,endtime,datacode,databytes,message
PackageStart,ITNOTA-SERVER,ITNOTA\UserId,SSIS-ITNota,{GUID1},{MACHINEGUID},3/5/2019 3:40:08 AM,3/5/2019 3:40:08 AM,0,0x,Beginning of package execution.

User:ScriptTaskLogEntry,ITNOTA-SERVER,ITNOTA\UserId,SCR_LogStart,{GUID2},{MACHINEGUID},3/5/2019 3:40:08 AM,3/5/2019 3:40:08 AM,99,(null),Package starting...
User:ScriptTaskLogEntry,ITNOTA-SERVER,ITNOTA\UserId,SCR LDAP Row Counts,{GUID3},{MACHINEGUID},3/5/2019 3:41:07 AM,3/5/2019 3:41:07 AM,99,(null), Total records with NT ID accounts: 11,236
User:ScriptTaskLogEntry,ITNOTA-SERVER,ITNOTA\UserId,SCR LDAP Row Counts,{GUID3},{MACHINEGUID},3/5/2019 3:41:07 AM,3/5/2019 3:41:07 AM,99,(null), Total records without NT ID accounts: 10,009
User:ScriptTaskLogEntry,ITNOTA-SERVER,ITNOTA\UserId,SCR LDAP Row Counts,{GUID3},{MACHINEGUID},3/5/2019 3:41:07 AM,3/5/2019 3:41:07 AM,99,(null), Total records from LDAP source: 21,245
User:ScriptTaskLogEntry,ITNOTA-SERVER,ITNOTA\UserId,SCR Log Finish,{GUID4},{MACHINEGUID},3/5/2019 3:41:07 AM,3/5/2019 3:41:07 AM,99,(null),~ Log Cleanup Package completed. ~
PackageEnd,ITNOTA-SERVER,ITNOTA\UserId,SSIS-ITNota,{GUID1},{MACHINEGUID},3/5/2019 3:41:07 AM,3/5/2019 3:41:07 AM,0,0x,End of package execution.

That’s all there is to it to add a custom logging to SSIS package.

This may look like a lot of work initially, but as your SSIS package grows in complexity it will save you so much time in diagnosis and troubleshooting that you will thank yourself later.

Hope it helps.

Further Reading

SSIS Best Practice with Naming Conventions
How to Create SSIS Package in Visual Studio 2017
How to Build SSIS Package for Different SQL Server Version with Visual Studio 2017 and SSDT

March 7, 2019 Filed Under: How To Tagged With: ETL, Microsoft, SSIS

How to Backup IIS Manager Connections List on Windows

You’ve been using IIS Manager to manage remote IIS from your local computer. But how do you export the connections list if you move to a new computer or just to back it up if you lost all data?

IIS Manager Connect Remote Server

This post will show you how you can export and back up IIS Manager connections list on your local PC.

All connections in IIS Manager are saved in a binary file called InetMgr.preferences and it can be found in the following folder:

%APPDATA%\Microsoft\WebManagement\7.0.0.0

Or

C:\Users\{NTID}\AppData\Roaming\Microsoft\WebManagement\7.0.0.0

*Replace the {NTID} with the user id you use to logon to your computer.

IIS Manager preferences file

This is the file you want to backup so copy this file to your backup folder. When you need to restore it, just copy this file back to the above folder and you should be back in business.

Important: Do not try to restore the file when IIS Manager is open. When you quit the application, it will write the last settings on that InetMgr.preferences file.

Further Reading

How to Manage IIS Servers Remotely

March 6, 2019 Filed Under: How To Tagged With: IIS, Internet Information Services, Microsoft, Windows, Windows 10

How to Use System.Configuration.ConfigurationManager on .NET CORE

When you need to convert an existing .NET Framework Console application to .NET Core, there’s one pending question that is kept being asked. Can you still use the System.Configuration and App.config (XML) configuration instead of using the new Appsettings.json file instead?

There’s always a need for a most robust configuration file and with JSON, it offers more flexibility and scalability but it doesn’t make sense to use it for a console application that only need to read one or two values as parameters from the *.config file.

As an example on this particular case, the console file just need a data of which file to look for based on a date.

App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"  />
    </startup>
  <appSettings>
    <!-- Date value must be in mm/dd/yyyy format. -->
    <add key="Rundate" value="mm/dd/yyyy"  />
  </appSettings>
</configuration>

Running a .NET Core console application can expedite the runtime which will improve the completion time of the batch job and also as it’s leaner it will have a lower operating cost. Moreover, .NET Core is the future of .NET so we’re future proofing the processor.

So how do we use the same App.config file for a .NET Core application?

Setup the System.Configuration

  1. From your Visual Studio, open the Package Manager Console by going to Tools menu, then pick NuGet Package Manager. You will see the window open with the following initial message and PM> prompt.

      Each package is licensed to you by its owner. NuGet is not responsible for, nor does it grant any licenses to, third-party packages. Some packages may include dependencies which are governed by additional licenses. Follow the package source (feed) URL to determine any dependencies.
     
      Package Manager Console Host Version 4.9.2.5706
     
      Type 'get-help NuGet' to see all available NuGet commands.
     
      PM>
    

    Visual Studio NuGet Package Manager Console

  2. If you check the nuget.org website for System.Configuration.ConfigurationManager, you can just copy the command line (just substitute the version number you want to use).

      PM> Install-Package System.Configuration.ConfigurationManager -Version 4.5.0
    

    Or if you want to use the latest, just click on the Copy button and paste it on your Package Manager Console window.

    NuGet .NET System.Configuration.ConfigurationManager

  3. Once it’s installed, don’t forget to add using System.Configuration directive in your code.

    Add back System.Configuration directive in Visual Studio

  4. Open App.config file and remove the block so it will look like the following:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
        <!-- Date value must be in mm/dd/yyyy format. -->
        <add key="Rundate" value="mm/dd/yyyy"  />
      </appSettings>
    </configuration>
    
  5. Test the program.

This is just a simple way to convert your existing .NET Framework console application to .NET CORE without complicating the existing configuration.

Further Reading

.NET System.Configuration.ConfigurationManager
How to Check Installed .NET Core Version

February 7, 2019 Filed Under: How To Tagged With: .NET Core, Microsoft

How to Check Installed .NET Core Version

This is one way to determine what version of .NET Core is installed on your machine (or if it’s not installed):

  1. Launch Windows PowerShell.
  2. Runtime
    (dir (Get-Command dotnet).Path.Replace('dotnet.exe', 'shared\Microsoft.NETCore.App')).Name
    
  3. SDK
    (dir (Get-Command dotnet).Path.Replace('dotnet.exe', 'sdk')).Name
    

In the following example, you can see that .NET Core 2.1.2 Runtime is installed, but the SDK is not installed with the following error message:

dir : Cannot find path 'C:\Program Files\dotnet\sdk' because it does not exist.
At line:1 char:2
+ (dir (Get-Command dotnet).Path.Replace('dotnet.exe', 'sdk')).Name
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Program Files\dotnet\sdk:String) [Get-ChildItem], ItemNotFoundExcept
   ion
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
 
PS C:\Windows\system32>

PowerShell query for installed .NET Core version

Otherwise, it will look more like the next screenshot:

PowerShell query for installed .NET Core version for both Runtime and SDK

Another Way

There’s another way to accomplish the same thing with a much simpler command and this works on either Windows or macOS.

  1. Depending on your operating system, launch either Windows PowerShell or Terminal.
  2. Runtime
    dotnet --list-runtimes
    
  3. SDK
    dotnet --list-sdks
    
Installed .NET Core versions for both Runtime and SDK from PowerShell

Windows PowerShell

 

Installed .NET Core versions for both Runtime and SDK from macOS Terminal

macOS Terminal

 

When you see more than one entries, that means you have several versions installed and actually that’s the advantage of using .NET Core, you can have different versions installed side-by-side. The latest version is the last version number at the bottom of the result.

If you need a way to check the installed version of .NET Framework instead, check the link here.

Further Reading

How to Check Installed .NET Framework Version
How to determine if .NET Core is installed
How to: Determine which .NET Framework versions are installed
How to: Determine which .NET Framework security updates and hotfixes are installed
How to Remove .NET Runtime and SDK on Mac
How to Use System.Configuration.ConfigurationManager on .NET CORE

January 30, 2019 Filed Under: How To Tagged With: .NET, .NET Core, Microsoft, PowerShell, Windows

« Previous Page
Next Page »
Buy me a coffee Support this site
Buy Me a Coffee?

Categories

  • .NET
  • Coding
  • Cybersecurity
  • Database
  • How To
  • Internet
  • Multimedia
  • Photography
  • Programming
  • Resources
  • Review
  • Tips and Tricks
  • Uncategorized
  • Use Case
  • WordPress
  • Writing

Recent Posts

  • How to View Stored Procedure Code in SQL Server
  • How to Find a String in SQL Server Stored Procedures
  • How to Remove Cached Credentials without Rebooting Windows
  • ESP Work Automation: Empowering Enterprises with Streamlined Workflows and Operational Efficiency
  • How to Search for a String in All Tables in a Database

Recent Posts

  • How to View Stored Procedure Code in SQL Server
  • How to Find a String in SQL Server Stored Procedures
  • How to Remove Cached Credentials without Rebooting Windows
  • ESP Work Automation: Empowering Enterprises with Streamlined Workflows and Operational Efficiency
  • How to Search for a String in All Tables in a Database

Tags

.NET .NET Core AdSense ASP.NET Cdonts Dll Classic ASP Code Editor ETL FSharp Genesis Framework Git Google HP Asset Manager HTML5 Hugo IIS Information Security Internet Internet Information Services iOS JAMStack Linux macOS Microsoft Microsoft SQL Server MVC PHP PowerShell Python Simple Mail Transfer Protocol Smtp Server SQL SQL Server SSIS SSMS SSRS Sublime Text Visual Studio Visual Studio Code VPN Windows Windows 8 Windows 10 Windows 2012 Windows Server

Copyright © 2011-2025 IT Nota. All rights reserved. Terms of Use | Privacy Policy | Disclosure