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 )

Use Microsoft.Data.DataConnectionDialog in your projects to retrieve connection string

This is the use of the Visual Studio connection dialog in your own projects, for instance tool kits to inspect databases. Steps are:

  1. NuGet
  2. Search and add Data Connection (Windows Forms)
  3. Add code, sample is in VB, but C# is similar

 


Imports Microsoft.Data.ConnectionUI

    Private Sub GetDataConnection()

        Dim dcd As New DataConnectionDialog
        DataSource.AddStandardDataSources(dcd)
        dcd.SelectedDataSource = DataSource.SqlDataSource

        If DataConnectionDialog.Show(dcd) = Windows.Forms.DialogResult.OK Then
            Select Case dcd.SelectedDataProvider.Name
                Case DataProvider.SqlDataProvider.Name
                    Dim cn As New SqlClient.SqlConnection(dcd.ConnectionString)
                    DataSourceToolStripTextBox.Text = cn.DataSource
                    DatabaseDefaultToolStripTextBox.Text = cn.Database
                    'MessageBox.Show(String.Concat("Found SQL: ", cn.ConnectionString))

                Case Else
                    MessageBox.Show(dcd.ConnectionString)
            End Select
        End If

    End Sub

See also
http://wildermuth.com/2007/1/29/Using_the_Visual_Studio_Connection_String_Dialog

Change Team Foundation Server – The solution is in a directory mapped to team server …

Scenario

Project was on one TFS Server and you want to move it to another. In this case to visualstudio.com

How did I move the code to a different TFS Server

  1. First unbind the solution projects from the current TFS Server – TODO method
  2. Connected to the new TFS Server
  3. Right-click on Solution – Add solution to source control
    This returned message:
    “Change Team Foundation Server – The solution is in a directory mapped to team server …<the old server>
    Continuing will close the existing team server <the new desired server> and open team server <the old server>. Continue ?
  4. To resolve see steps in: http://support.microsoft.com/kb/957110. I did not do exactly as stated and instead backed up and then edited the VersionConfig.config:
    Note to self: If I get further problems then delete all the files and folders in the Cache as suggested in this web page
  5. Navigate to %userprofile%\AppData\Local\Microsoft\Team Foundation\3.0\Cache\VersionConfig.config
  6. I removed the whole related <ServerInfo> section, which in my case only had one mapped path.
  7. Appears to have resolved the matter

End.

Find and remove adware on Internet Explorer

Started getting adware underlined hyperlinks on IE today. This directs you to svr123.com and then on to a web advert

With thanks to http://geekvisit.com/remove-double-underlined-adware-rrfilter

Found in services and msconfig and disabled in both

  1. In RegEdit.exe delete following folder
    HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\RrFilterService64
    HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\yewimmxqbs64
  2. In Explorer
    %program files (x86)% delete folder Rr Savings
  3. In Explorer
    %program files% delete folder RrFilter
  4. Also in IE > Tools > Manage Add-ons
    Disable Adpeak – RrSavings
    Also More Information – Took a screen shot and noted the ClassID
  5. Searched for the ClassID in RegEdit and deleted it from a few 2-3 places

 

WPF List Box

ItemTemplate – DataTemplate

            <ListBox ItemsSource="{Binding}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <StackPanel.Resources>
                                    <Style TargetType="TextBlock">
                                        <Setter Property="Margin" Value="0, 0, 5, 0" />
                                    </Style>
                                </StackPanel.Resources>
                                <TextBlock Text="{Binding Path=ID}" />
                                <TextBlock Text="{Binding Path=Task1}" />
                                <TextBlock Text="{Binding Path=PercentComplete}" />
                            </StackPanel>
                            <TextBlock Text="Resource names here" Margin="50, 0, 0, 0" />
                            <!--<TextBlock Text="{Binding Path=ResourceName}" Margin="50, 0, 0, 0" />-->
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

Sorting

        xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"

        <CollectionViewSource x:Key="taskViewSource" d:DesignSource="{d:DesignInstance my:Task, CreateList=True}">
            <CollectionViewSource.SortDescriptions>
                <scm:SortDescription PropertyName="CompleteFlag"
                                     Direction="Descending" />
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>

 

Style DataTrigger

            <ListBox ItemsSource="{Binding}">
                <ListBox.Resources>
                    <Style TargetType="{x:Type ListBoxItem}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=CompleteFlag}"
                                         Value="True">
                                <Setter Property="Background"
                                        Value="Yellow" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ListBox.Resources>
...
            </ListBox>

Visual Studio 2013 and MSDN – a justification list

A location for me to add justification notes for upgrade to VS 2013 and MSDN Subscription

Visual Studio 2013

  1. WPF improvements
  2. Entity data model wizard – code first from database

MSDN Subscription

  1. Visual Studio online has more facilities including:
    Test cases

 

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;.blob.core.windows.net/<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

 

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);
}