Azure Cosmos DB Emulator on Docker

Microsoft instructions were fairly ok.

Couple of gotchas:

The output is quite different to the documentation.

  • It suggests the directory is C:\CosmosDB.Emulator\bind-mount
    It is actually at %localappdata%CosmosDBEmulator\bind-mount

The log was useful. The Data Explorer is available at the last endpoint in the log. For me it was http://<AnIP&gt;:8081/

How to enable Azure VM IIS hosted website public access

  1. Setup IIS
  2. Confirm able to browse default website locally
  3. Azure Management Portal
  4. Select Virtual Machine
  5. Endpoints
  6. Add HTTP
  7. Confirm able to access the default site from a public web browser
  8. Optionally add FTP, HTTPS ( use for SSL )

Azure Virtual Machines adding virtual hard disks VHD

See also Azure Powershell and Azure VM with SQL

If you have a Pluralsight subscription then they have a good course “Windows Azure Infrastructure as a Service Essentials” then chapter “Storage and Disks” and screen cast “Creating Virtual Hard Disks”

First create a local VHD

  1. Start – “Create and format hard disk partitions”
  2. Action Create VHD
  3. Set location, size, fixed size, OK
  4. Right-click on newly created disk and Initialise
  5. Think MBR – OK
  6. Detach VHD

Upload local VHD to Azure Storage using Azure Powershell

  1. Ensure that you can run local scripts, see Azure Powershell post
  2. Run script:
    add-azurevhd -destination http://<address&gt;<container>/<blobname>.vhd -LocalFilePath :\vhds\VHD01.vhd

Set as Virtual Machines Disk

  1.  Azure management portal
  2. Virtual machines
  3. Disks
  4. Create, enter name, pick from storage, OK

Attach to the Virtual Machine

  1. Azure management portal
  2. Virtual machines
  3. Select machine
  4. Dashboard
  5. Attach – Attach disk
  6. Read/Write
  7. Tick, OK






Azure Virtual Machines – with SQL Server

Setting up a VM for SQL Server Web Edition

  1. Created my first virtual machine with SQL Server Web edition on it.
  2. Added a windows user. Added the equivalent SQL Server windows user.
  3. Checked could login to SQL Server OK
  4. Used sysprep as a starting point
  5. Then took an image.
  6. Then created a new virtual machine from that image
  7. Logged in to new VM ok – but error on logging in to SQL Server.
  8. Then after a weekend the error had changed to “A connection was successfully established with the server, but then an error occurred during the login process (provider: Shared Memory Provider: 0 – No process is on the other end of the pipe)(Microsoft SQL Server, Error: 233)
  9. This was because SQL Server Agent was not running – started it
  10. In fact in SQL Server Configuration SQL Server Agent and Browser had to be changed to automatic startup
  11. Then back to original error

Error Login failed for user (Microsoft SQL Server Error 18456) on VM with SQL Server

  1. It seems that the user who created the SQL login on the first machine is not the same as the user who created the new machine after the sysprep
  2. So destroyed the machine and started again.
  3. New strategy – put SQL Server into Mixed Authentication Mode
  4. Create a SQL Server Login
  5. Give that login sysadmin
  6. Create the image.
  7. Create the VM from the image.
  8. Confirm that the Windows logins do not work for SQL Server
  9. Login as that SQL Server login admin created before, rather than the Windows Authentication only.
  10. Then script to drop and create the windows logins
  11. Issue resolved

Mixed Authentication Mode is required if logging into the SQL Server from another machine in any case.

So if creating a new VM from the image then start from step 7 above


Error: Login failed for remote SQL server



In the VM > Network and Sharing Center > View your active networks

The network had been set to private – reset to public and it now works again



How to setup a Virtual Machine for connection to SQL Server from another Machine


Azure Powershell

This was useful

When I installed Powershell I think I downloaded a publishsettings file. I copied this to c:\Temp and renamed it without spaces. Then as per above I used:

Import-AzurePublishSettingsFile ‘c:\temp\<publishsettingsfilename.publishsettings>’

Everything then worked including:




To store a script use notepad and change the file extension to .ps1


File ps1 cannot be loaded because running scripts is disabled on this system


To resolve this issue, follow these steps:

  1. Run the Windows Azure Active Directory Module for Windows PowerShell as an admin. To do this, click Start, click All Programs, click Windows Azure Active Directory, right-click Windows Azure Active Directory Module for Windows PowerShell, and then click Run as administrator.
  2. Set the execution policy to Unrestricted. To do this, type the following cmdlet, and then press Enter:
    Set-ExecutionPolicy Unrestricted
  3. Run the Windows PowerShell cmdlets that you want.
  4. Set the execution policy to Restricted. To do this, type the following cmdlet, and then press Enter:

    Set-ExecutionPolicy Restricted



  1. Open mmc.exe
  2. Add snap-in for Group Policy – local computer
  3. Computer configuration
  4. Administrative templates
  5. Windows components
  6. Windows Powershell
  7. Turn on Script Execution
  8. Right-click Edit
  9. Enabled
  10. Execution policy bottom LHS = Allow Local Scripts and remote Signed Scripts

After finish disable it.

How to create a certificate – for Azure

Using MakeCert

After using makecert, it may say Succeeded, but you may not be able to find the certificate.
If you started from c:\Windows\system32 then It may be in c:\Windows\SysWOW64

To create your own self-signed management certificates which will be valid for Azure, open a Visual Studio command prompt as an administrator, and then run the following command:

makecert -sky exchange -r -n “CN=<CertificateName>” -pe -a sha1 -len 2048 -ss My “<CertificateName>.cer”

The CN may need to be

NOTE: If you get:
Error: CryptCertStrToNameW failed => 0x80092023 (-2146885597)

Then try manually deleting each ” and re-typing


Export from MMC

Not sure still learning, but current notes are

  1. Windows start type mmc.exe
  2. Probably current user for self-signed
  3. Select certificate
  4. Right-click All Tasks – Export
  5. Export with Private Key and Password
  6. Upload to the Service – Certificates in Azure



Configuring SSL for an application in Windows Azure

How to create a WCF Service Web Role and publish to Azure and consume it

Create the Project

Visual Studio > New Project > Visual Basic or Visual C# > Cloud > Windows Azure Cloud Service
> Select WCFServiceWebRole
If this is missing then Install “Windows Azure SDK for .Net”

Code quick start: Create and deploy a WCF service in Windows Azure

Code Quick Start: Create a client application that uses a WCF service deployed to Windows Azure

Also see:

Code the Project

Follow the instructions above.

You cannot overload a method. So I had GetMakes and GetMakes(VehicleTypeID) this will mean the service cannot be activated.

Deployment to Azure

Points to watch are:

  1. In ServiceConfiguration.Cloud.cscfg
    <Instances count=”2″ />
  2. In the role, e.g. WCFServiceWebRole1 on Configuration specify the storage account credentials for the Diagnostics results:
    Use the eclipse and pick existing Azure account

Change the name of a service

MyService.svc is actually 2 files, with a linked code behind file.
Using right-click MyService.svc may be opened for code or for markup. If opened for markup then the service name is exposed. If you change the name of the project then you need to change the name here to the fully qualified name.

Consume the service

Mostly fine by following the example. Notable point here.

  1. Add service reference to a project in Visual Studio
  2. Right-click and Configure Service Reference
  3. Under Data Type > Tick On the “Always generate message contracts”

Otherwise the Get..Request() or Get..Response() may not be visible.


You could remote desktop to the Azure instance and then use:

  1. the Event Viewer – Application to view errors.
  2. IIS > Management > Configuration Editor
    If this will not open, then it may display what error was found in the Web.Config file. Correct this.

For debugging In Web.confg you may add the following section so that actual errors appear on web inspection:

    <customErrors mode="Off"/>

but configSections must be first and there should be only one open and close tag for configuration.


Error 1

If debugging then it would crash OnStart when calling AzureLocalStorageTraceListener.GetLogDirectory. Issue here was in ServiceDefinition.csdef there was no log defined.

Error 1 Solution

       <LocalStorage name="WCFServiceWebRole1.svclog" sizeInMB="1000" cleanOnRoleRecycle="false" />

Error 2

Metadata contains a reference that cannot be resolved: ‘http://<ip address>:<port no>/CatalogueService.svc?wsdl’.
The document format is not recognized (the content type is ‘text/html; charset=UTF-8’).
Metadata contains a reference that cannot be resolved: ‘http://<ip address:<port no>/CatalogueService.svc’.
There was no endpoint listening at http://<ip address>:<port no>/CatalogueService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
The remote server returned an error: (404) Not Found.
If the service is defined in the current solution, try building the solution and adding the service reference again.

Error 2 Solution

I had inadvertently commented out the [ServiceContract] from the IService
Also make sure that the markup of the service is correct.

Error 3

“The remote server returned an error (500) Internal Server Error”

Error 3 Solution

Unfortunately this just means there has been an error. I changed a number of things and then it started again, i do not know which fixed the issue for me:

  1. Added an [OperationContract] to the ICatalogueService and did not explicity implement it.
  2. An issue with remote desktop publish
  3. Overloaded a method with the same name
  4. Remmed out next line
    public interface ICatalogueService

Error 4

I had a test fail possibly when returning a lot of data.

System.ServiceModel.CommunicationException: The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element. —> System.ServiceModel.QuotaExceededException: The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

Error 4 Solution

Surprisingly I didn’t change anything on the outgoing service.
Instead on the calling application in the app.config file there are some settings for the bindings.

<?xml version="1.0" encoding="utf-8" ?>
                <binding name="BasicHttpBinding_IMyService" closeTimeout="00:01:00"
                    maxBufferSize="6553600" maxBufferPoolSize="524288" maxReceivedMessageSize="6553600"
            <endpoint address="http://xxx.xx/MyService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService"
                contract="CatalogueCloudService.IMyService" name="BasicHttpBinding_IMyService" />

Error 5 – The type or namespace ‘..’ could not be found (are you missing a using directive or an assembly reference?) in  – …\..\Reference.cs

Solution 5

I tried removing [Serializable][DataContract] from class and remove [DataMember] from properties and then re-deployed the web service and the error went away.

Error 6 – Web.Config errors

Resulted in Internal Server Erorr 500

Solution 6

See top of troubleshooting. Use IIS and try and use the Configuration Editor. This may display your error. Possible errors include:

  1. You should have only 1 configuration open and close tag
  2. configSections should be the first element


Error 7 Busy (Starting role… Unhandled Exception: Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironmentException

Does not progress beyond this. You have to delete that deployment for now.

Solution to Error 7

This is similar to error 2 above.

The Web Role project in AzureLocalStorageTraceListener the name of the path must be the same as the service

publicclassAzureLocalStorageTraceListener : XmlWriterTraceListener

public AzureLocalStorageTraceListener() : base(Path.Combine(AzureLocalStorageTraceListener.GetLogDirectory().Path, “WCFServiceWebRole2.svclog”)) {}

publicstaticDirectoryConfiguration GetLogDirectory()
DirectoryConfiguration directory = newDirectoryConfiguration();
directory.Container = “wad-tracefiles”;
directory.DirectoryQuotaInMB = 10;
directory.Path = RoleEnvironment.GetLocalResource(“WCFServiceWebRole2.svclog”).RootPath;
return directory;

Error 8

The type ‘WCFServiceWebRole.VRMService’, provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.

Solution to Error 8

Right-Click on the service with the bug and use View Markup. The Service name may have got out of sync with the project name

<%@ServiceHostLanguage=”C#”Debug=”true”Service=”WCFServiceWebRole.MyService”CodeBehind=”MyService.svc.cs” %>


The name in the Azure Service Project > Roles > Your Role > Properties > Local Storage > must have the same name



Using SSL on the WCF WebRole

Links to:

If you have a subscription then see Pluralsight course: Windows Azure fundementals > Windows Azure Roles


Publish ASP.Net to Azure ‘freezes’

Steps to reproduce freeze when publishing a website to Azure

This assumes you have previously published a site

  1. Visual Studio
  2. Right-click on ASP.Net project that you wish to publish
  3. Publish
  4. Preview
  5. Start Preview
  6. Publish
  7. Freezes after build

How to resolve

If your solution has multiple projects, make sure that the ASP.Net project is the “Start up project”

Deleting an ASP.Net azure hosted website using Entity Framework can potentially delete the linked database

I had a database on Azure that was being updated using Windows Forms. I then created an ASP.Net MVC application using EF to work against the same database. However I following a tutorial which used Code First

This would not publish until I used Nu-Get to:


However I think I then used code first migrations on publish. However I published the website with high credentials and wanted to change the credentials to lower. Could not see how to do this in Azure, so deleted the website. At this point the database disappeared without warning.

This is why the last posts have been about SQL Azure backup. However recovered using on-site data and re-created database.

Microsoft support helped with the ASP.Net so:


Check the file created, but do not check the box on publish.

Tested by deleting the Website – This then asked if you wanted to delete the linked database. Answer: No. Database stays ok.

How do I backup SQL Azure to a Blob Storage Account using bacpac

My word press blog entry