Cannot Connect to Database Master at SQL Server at “” . The Database might not exist, or the current user does not have permission to connect to it

Finally, I have started working with SharePoint 2016… in 2017 😉

So as always, I like to setup my development environment. Instead of using VMWare workstation, I decided to try out Hyper-V on Windows 10. And guess what? I love it.

I always begin the very first install of SharePoint manually, piece by piece before I start using the AutoSPInstaller scripts. I like to know whats’ what in the box before I begin using automation for the process. It adds to my understanding and knowledge of how pieces fit together. That’s just me.

Anyways, so I created a Win Server 2012 Hyper-V VM, installed the Active Directory services feature, added service accounts for the install, installed sql, installed SharePoint 2016 binaries. This link is what you should follow when setting up SharePoint 2016


And THEN! I ran the Configuration Wizard. On step 3, creating the configuration database… the error “Cannot Connect to Database Master at SQL Server at ‘xxx’ . The Database might not exist, or the current user does not have permission to connect to it” .

So I begin the quest to find whats wrong. I came across blogs that told me to checked TCP/IP, named pipes, sql server access and the list goes on but nothing matched up with solving the issue.

I came across a blog that mentioned about adding the IP address of your active directory server to your host file. And it WORKED!

On my VM, my Domain is called SP.Com. I added a entry in there to the machine I was building my development environment on.


So in my case, this was the fix.


Hope that helps. Also wish to give credit to the blog that gave me this hint but I forgot which one it was. It was a late night. Sorry





LINQ to SELECT from lists collection

A neat bit of code to write out all lists at the Root Web level that are hidden!

using(SPSite site = new SPSite(http://phillau)


SPWeb web = site.RootWeb

var lists = from list in web.Lists.OfType<SPList>()

where list.Hidden == true

select list;

foreach(var list in lists)






SharePoint Authentication methods overview

Window Authentication

– authentication managed by Windows Server and IIS

Forms Based Authentication

– authentication managed by ASP.NET and an authentication provider

Claims Authentication

– authentication managed by a security token service (STS


SharePoint creates a profile for each user a the site collection level

– User information list used to track identities

–  Identity seen by developers as SPUser


User information list is automatically created at the top level site.

– Tracks security principals using an integer ID


SharePoint may rely on external source for authentication but it controls all authorisation to its resources and entities.

CSOM – Get site object using JavaScript

Working with CSOM using JavaScript is slight different in syntax, but the process involved with getting the objects required for coding is the same! You still need to use the context object, load the context object, and execute the query that will send the context object off to SharePoint to tell it what you want and have it returned back.

The syntax is slightly different and the context return object is used in a different way:

var ctx;

var web;

var lists;


function onPageLoad()


ExecuteOrDelayUntilScriptLoaded(LoadAll, “sp.js”);


function LoadAll()


ctx = SP.ClientContext.get_current();

web = ctx.get_web();



lists = web.get_lists();


ctx.executeQueryAsync(doSomething, displayError);


function doSomething()


var siteTitle = web.get_title();

var siteId = web.get_id().toString();

var siteUrl = web.get_url();

var currentUser = web.get_currentUser().get_loginName();


function onError(sender, args)




CSOM – Get lists via Managed Code

I have been working on CSOM recently and I wanted to share this snipplet of code that I used to get the Web object, List Collection, and create a new list via the client object model through managed C# code.

// Create the client context by passing in the web url I want to use

ClientContext cctx = new ClientContext(“;);

cctx.Credentials = CredentialCache.DefaultCredentials;

Web ctxWeb = cctx.Web;

ListCollection lists = ctxWeb.Lists;

// Load the context object with instructions to only populate the title field in the site object

cctx.Load(site s => s.Title);

// Request gets send to retrieve the site title


Console.WriteLine(“Site Title:” + ctxWeb.Title);

//Create a new list. Specify what you want it to be!

ListCreationInformation list = new ListCreationInformation();

list.Title = “Ships”;

list.Url = “List/Ships”;

list.TemplateType = (int)ListTemplateType.GenericList;

// Add to list collection


// Load into context object to be launched!


// Submit list blueprint!


foreach(List list in lists)





Core results web part: Raw XML property and result

I have come across situations while working with the core results web part xslt to display the results, I just want to see what property is retrieving what value. Raw xml is the best way forward!

Edit the core results web part, expand Display Properties, select the XSL Editor button. Inside the text box, copy the existing xslt out of the editor and paste the following into it:

<?xml version=”1.0″ encoding=”utf-8″?>

<xsl:stylesheet version=”1.0″ xmlns:xsl=””&gt;

<xsl:output method=”xml” version=”1.0″ encoding=”utf-8″ indent=”yes”/>

    <xsl:template match=”/”>


              <xsl:copy-of select=”*”/>




Click OK and save the page.

Reload the page and the Raw XML will be displayed for search results!

Handy xsl 🙂




Accessing embedded xml file using C#

I have recently been embedding xml files into assemblies so the information can be accessed in code.

This is how I get a reference to the current assembly where the code and xml file is residing

Assembly currentAssembly = Assembly.GetExecutingAssembly();

I invoke the method to get my xml file by doing the following:

Stream stream = currentAssembly.GetManifestResourceStream(this.GetType(), “ValidationRules.xml”);

I create a new XmlDocument and load the content of the xml file into there:

XmlDocument doc = new XmlDocument();

Given my xml is kind of like this:

<?xml version=”1.0″ encoding=”utf-8″ ?>


<Name>Question 1a</Name>
<ValidationMessage>The Question 1a field cannot be empty</ValidationMessage>
<DependentFields>Question 2a</DependentFields>
<ValidationMessage>Question 1b cannot be empty</ValidationMessage>


Depending on the structure of your xml, I would iterate through the element nodes using a foreach. I would go through each element by doing the following:

 foreach (XmlElement xmlField in doc.SelectNodes(“/Fields/Field”))
string fieldName = xmlField.SelectSingleNode(“Name”).InnerText;
string dependentFields = xmlField.SelectSingleNode(“DependentFields”).InnerText;

I can now use the data from the xml file to do other processing in my code.