Monday, September 18, 2017

SQL Server AAD Authentication Error

Are you seeing this error from your ADO.NET Code Trying to Connect To Your SQL Server via Active Directory Authentication:

Exception=System.Data.SqlClient.SqlException (0x80131904): Failed to authenticate the user NT Authority\Anonymous Logon in Active Directory (Authentication=ActiveDirectoryIntegrated). Error code 0x800703FA; state 10 Illegal operation attempted on a registry key that has been marked for deletion. 

The issue might be that you are running a windows service or a scheduled task with a user that has logged off. In Windows Server the registry hive for the current user is loaded when the user logs into the machine, and unloaded when they log off. This means that if you service account is running under a user that is logged off then the registry hive will not be available. ADO.NET AAD in .NET 4.6.1 uses the registry hive of the running user -- which could be the user of a service.

To solve this problem you need to tell Windows Server not to unload the registry hive for users when they log off.


The Core 2.0 Environment for NodeJs Developers

NodeJs & .Net Core

NodeJs and the ecosystems have used very different paradigms until recently. This article will show you where they are similar – the 10,000 feet view – when using the Core 2.0 environment.

With NodeJs, as the developer you might have chosen to build a web server or a cli tool.  Your favorite interactive development environment (IDE) might just be a terminal window or Google Chrome DevTools.

With (not .Net Core), Microsoft provided the web server (IIS) and the IDE (Visual Studio). You can develop many different applications including web sites and cli tools. With .Net Core 2.0, the focus is on portable code, and the result feels much closer to NodeJs.

For this article, I'm going to ignore all issues that would make the comparison apples to oranges and instead focus on issues that make the comparison apples to apples.

Moving forward, any reference to Core 2.0 will be just .Net Core. NodeJs 6.9.1 will be just Node. The example project name will be kittens so you can see how it is used when it is relevant.

Text Only

The files of both .Net Core and Node are both text files. A project has a single configuration file. The top of each code file references the libraries that are used in the file.

In .Net Core 1.0, the project file was a package.json, but in .Net Core 2.0, the project file is a *.csproj file. The package file for .Net Core is created with the cli of "dotnet new...". The XML of the .Net Core file will be familiar to .Net developers.

<Project Sdk="Microsoft.NET.Sdk">
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />

In Node, the project file is the package.json created by the NPM cli of "npm init" with the result of a JSON object containing information about the project. I added expressjs to the package so the dependencies object would have an entry.

  "name": "kittens",
  "version": "1.0.0",
  "description": "",
  "main": "kittens.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.15.4"

In their own way, each of the package files configure the project but in very different ways. The .Net Core file is focused on the .Net Core version and final built assets of the project – things the compiler and dependencies need to run.

The Node package.json file lists all dependencies to pull in, as well as meta data about the project – it is the single location a developer touches to control the project as a whole, including building and testing. I usually have a long list of items in the Node package.json scripts section for building, testing, and running.


Both Node and .Net Core applications are built via terminal/command line. Both are executed in the context of the parent application: dotnet or node.

While Node needs a single point of entry of a javascript file, such as kitten.js, .Net Core uses the project name (<name>.csproj).

> node kittens.js

> dotnet kittens.dll

Dependencies are added to Node projects with the npm or yarn package managers. The dependencies are placed in a folder named node_modules.

> npm add <packagename>

For .Net Core dependencies, use the NuGet package manager. There isn't a single list of dependencies in a human readable format that is opened/viewed by developers on a regular basis.

> dotnet add package <packagename>

Both npm and dotnet allow you to specify versions but it is optional. Npm and yarn have been dealing with package interdepencies and version conflicts. I believe both are now able to avoid version conflicts of interdepencies.


Both platforms allow you to 'git clone' then install the package dependencies and run.

.Net Core uses a folder containing many files depending on the execution platform (windows, mac, linux).  For Node, just install and run a single file. Node will then find the rest of the files.

> dotnet restore && dotnet ./<path-to-bin-directory>/kittens.dll

> npm install && node kittens.js


The reason I mention serverless is you may not want to deal with the execution environment details.
Node has a variety of host platforms and open-source projects to run serverless.

Currently, the best way to run .Net Core serverless right now is Azure Functions. While there are other platforms such as AWS Lamdba that can run .Net Core code, those platforms may be slightly behind (or vastly behind) release .Net Core platform ability.


Docker containers are a great way to develop and deploy applications. I always look for owner created containers. If it works for them, it will work for me.

Here are the owner created containers for each:


For Node, the specific owner container isn't that interesting because there are a million ways you may want to run Node and a different container may get you much closer to your needs in terms of dependencies and tools.

For .Net Core, the owner container is probably the best bet for the short-term while the project is still new-ish.