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

 

Solution

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

http://azure.microsoft.com/en-us/documentation/articles/virtual-machines-provision-sql-server/

 

Learning WCF

With help from book “Learning WCF” by Michele Leroux Bustamante

Notes from working through samples:

Note 1:

Surprisingly it is possible/advisable to host the service from a different project or projects. This gives the possibility of one service to have different types of host running

Error 1:  System.ServiceModel.AddressAccessDeniedException: HTTP could not register URL http://.. Your process does not have access rights to this namespace

Solution 1:

Run Visual Studio as an administrator

Error 2: App.Config does not have context menu option “Edit WCF configuration”

Solution 2:

Use Tools > WCF Service Configuration Editor then close it

Then right-click on App.Config and the “Edit WCF configuration” will be there

 

Error 3: ASP.Net HTTP Error 403.14 – Forbidden – The Web server is configured to not list the contents of this directory

Solution 3:

  1. IIS
  2. Select the web site
  3. Double-click Directory Browsing
  4. Enable

(Nice to have an easy problem)

 

Error 4: IIS – Web site – Configuration Editor – system.web/compilation – Bug Unrecognized element folderlevelbuildproviders

Solution 4

With thanks to:

http://forums.iis.net/t/1180915.aspx which led to

http://www.hanselman.com/blog/ASPNET4BreakingChangesAndStuffToBeAwareOf.aspx

If you install ASP.Net 4 and then install IIS then you need to make sure IIS is configured to know about ASP.Net 4 otherwise IIS will have no idea how to run ASP.Net 4 applications.

There’s a simple workaround:

  • If you are already in this state, drop to the command line and navigate to the FX install directory.  Then run “aspnet_regiis –iru“.
    • Note if you are on a 64-bit machine, run this command from the 64-bit FX install directory – not the 32-bit installation directory.

or for future reference, try to enable IIS and the ASP.NET extensibility option *first* when your are building machines or VMs.  That way when VS 2010 or .NET are subsequently installed, the installation will automatically detect the presence of IIS and will auto-register with it.

 

 

How to host a service in a solution and have the client add service reference

Run without debugging – to do this use Ctrl + F5 or use the Debug menu, but the option may not be there, if you start with a VB IDE. If it is not there then you may add it using customise.

If you run with debugging as usual you will not be able to edit the client.

Hosting the service in IIS

Error no website with code 500

Not surprised that I had issues with hosting here. I had a WSS Windows SharePoint Services and SharePoint Central Administration using my IIS. Took a while to sort, what follows is not comprehensive, but a guide to what I did. I took the view that I have not used SharePoint Central Administration and so was prepared to sacrifice it. Some steps included:

IIS > Sites > Default Web Site > Right-Click > Edit Bindings.

Remove all bindings except http

Then under Default Web Site I had a folder wss -> Virtual Directories -> 80 -> my sample application landed here. Not sure why.

I removed all SharePoint (80) web sites, hope that is ok. And archived the wss folder in its entirety.

Everything started working again.

 

WCF Test Client executable

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\WcfTestClient.exe

Useful quick test.

 

 

 

 

 

Common method for outputting arrays and lists of any type

In unit tests I might want to output the results of a returned list of any type. Instead of writing a new method for each type, here are some techniques with thanks to:

http://stackoverflow.com/questions/9655262/common-method-for-printing-arrays-and-lists-of-any-types

Using Join

Split is a useful function, here is the reverse Join

int[] actual = new int[] {1,2,3}

string actual = new string[] {“one”, “two”, “three”}

TestContext.WriteLine(string.Join(“, “, actual));

 

Using Generics

public void PrintCollection<T>(IEnumerable<T> col)
{
foreach (var item in col) TestContext.WriteLine(item);
}

 

Using ForEach(Action a)

http://msdn.microsoft.com/en-us/library/bwabdf9z(v=vs.110).aspx

[TestMethod()]
publicvoid AListTest()
{
List<string> target = newList<string>();
target.ForEach(PrintCollection2);
}

privatevoid PrintCollection2(string s)
{
TestContext.WriteLine(s);
}

 

 

 

Azure Powershell

This was useful

http://michaelwasham.com/2012/06/08/automating-windows-azure-virtual-machines-with-powershell/

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:

Get-AzureSubscription

Get-AzureStorage

 

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

Error

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

Solution

http://support.microsoft.com/kb/2411920

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

 

Alternatively

  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.

 

http://blog.whatsupduck.net/2010/09/issues-with-configuring-powershell.html