 <?xml-stylesheet type="text/css" href="https://www.esdm.co.uk/Data/style/rss1.css" ?> <?xml-stylesheet type="text/xsl" href="https://www.esdm.co.uk/Data/style/rss1.xsl" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
  <channel>
    <title>The knowledge base blog</title>
    <link>https://www.esdm.co.uk/knowledge</link>
    <description />
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>mojoPortal Blog Module</generator>
    <language>en-GB</language>
    <ttl>120</ttl>
    <atom:link href="https://www.esdm.co.uk/Blog/RSS.aspx?p=138~108~4" rel="self" type="application/rss+xml" />
    <itunes:owner />
    <itunes:explicit>no</itunes:explicit>
    <item>
      <title>Mapserver returning WFS attributes scrambled when using msplugin_mssql2008 plugin</title>
      <description><![CDATA[<p>We recently upgraded Mapserver to the current version for a project because we wanted the WFS id field to be populated in geojson which required a recent version of (OGR &gt;=2.3) which was included in mapserver build 7.2.1</p><p>All went well and we modified the mapserver geojson output format to specify the field we wanted to use (originally named id in our case) but adding in the line: FORMATOPTION "LCO:ID_FIELD=id"</p><blockquote><p>OUTPUTFORMAT<br>&nbsp;&nbsp; NAME "geojson"<br>&nbsp;&nbsp; DRIVER "OGR/GEOJSON"<br>&nbsp;&nbsp; MIMETYPE "application/json; subtype=geojson"<br>&nbsp;&nbsp; FORMATOPTION "STORAGE=stream"<br>&nbsp;&nbsp; FORMATOPTION "FORM=SIMPLE"<br>&nbsp;&nbsp; FORMATOPTION "LCO:COORDINATE_PRECISION=0"<br>&nbsp;&nbsp; FORMATOPTION "LCO:ID_FIELD=id"<br>
END</p></blockquote><p>The field “id” needed to be included in the relevant map layer in the gml_include_items e.g.:</p><blockquote><p> "gml_include_items"&nbsp;&nbsp;&nbsp;&nbsp; "name,recsubtype,recsubtypecode,rectype,ref,uid,id"</p></blockquote><p>After those changes – all seemed to be going well and the id was appearing in our WFS return</p><p><a href="https://www.esdm.co.uk/Data/Sites/1/media/wlw/image_151.png"><img width="244" height="52" title="image" style="margin: 0px; display: inline; background-image: none;" alt="image" src="https://www.esdm.co.uk/Data/Sites/1/media/wlw/image_thumb_122.png" border="0"></a></p><p>However when we looked at some of the other attributes we noticed scrambled characters (these had been fine with the previous version of mapserver). e.g. rectype in screenshot below</p><p><a href="https://www.esdm.co.uk/Data/Sites/1/media/wlw/image_152.png"><img width="244" height="57" title="image" style="margin: 0px; display: inline; background-image: none;" alt="image" src="https://www.esdm.co.uk/Data/Sites/1/media/wlw/image_thumb_123.png" border="0"></a></p><p>Our data was coming from SQL server using the msplugin_mssql2008 plugin– and if we set debug in the mapserver layer and looked at the log we saw:</p><blockquote><p><em>msConvertWideStringToUTF8(): General error message. Unable to convert string in encoding 'UCS-2LE' to UTF8 An invalid multibyte sequence has been encountered in the input</em></p></blockquote><p>So it looked as it something was going wrong in the unicode translation.&nbsp; The workaround was refreshingly simple – we just had to alter the view that the data was being pulled from to force the conversion e.g. change:</p><blockquote><p>‘Site’</p><p>to:</p><p>CONVERT(nvarchar(1),N’Site’)</p></blockquote><p>then all was well again.</p><br /><a href='https://www.esdm.co.uk/mapserver-returning-wfs-attributes-scrambled-when-using-msplugin_mssql2008-plugin'></a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/mapserver-returning-wfs-attributes-scrambled-when-using-msplugin_mssql2008-plugin'>...</a>]]></description>
      <link>https://www.esdm.co.uk/mapserver-returning-wfs-attributes-scrambled-when-using-msplugin_mssql2008-plugin</link>
      <author>()</author>
      <comments>https://www.esdm.co.uk/mapserver-returning-wfs-attributes-scrambled-when-using-msplugin_mssql2008-plugin</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/mapserver-returning-wfs-attributes-scrambled-when-using-msplugin_mssql2008-plugin</guid>
      <pubDate>Thu, 21 Feb 2019 12:54:32 GMT</pubDate>
    </item>
    <item>
      <title>Using cloudscribe with Identity Server 4 with a SQL Server store on .Net Core 2 MVC securing APIs</title>
      <description><![CDATA[<p>Well that’s a bit of a mouthful of a title – but it does describe what I was trying to do, and I didn’t find it easy. It’s not that complicated when you know how, but there are an awful lot of options and it wasn’t clear (to me at least) which ones to pick, so I hope this saves others some time.</p>

<h4>Aim</h4>

<p>I wanted a <a href="https://www.cloudscribe.com/">cloudscribe</a> site running allowing users to be able to logon as usual using cookies, but I also wanted to have an API that could be secured for clients external to the site without having to use the cookie login and I wanted to use Identity Server 4 with a SQL data store.</p>

<h3>Starting setup</h3>

<h4>Server</h4>

<p>I used Joe Audette's excellent cloudscribe Visual Studio template <a href="https://www.cloudscribe.com/blog/2017/09/11/announcing-cloudscribe-project-templates">https://www.cloudscribe.com/blog/2017/09/11/announcing-cloudscribe-project-templates</a> and selected use MSSQL Server and the Include Identity Server integration option. Also selecting the 2 options in the “Expert Zone” gave me an example API to test with.</p>

<p><a href="https://www.esdm.co.uk/Data/Sites/1/media/wlw/clip_image002_8.jpg"><img alt="clip_image002" border="0" height="244" src="https://www.esdm.co.uk/Data/Sites/1/media/wlw/clip_image002_thumb_7.jpg" style="margin: 0px; display: inline; background-image: none;" title="clip_image002" width="227" /></a></p>

<p>This gave me the basic website and was the one I wanted to add the secured API into. The VS project has a weather forecast API as an example.</p>

<h4>Client</h4>

<p>I then setup a separate MVC project using a basic template to act as the client application. This was all done using Visual Studio 2017 and .Net Core 2.</p>

<h3>Server application</h3>

<p>By default, the weather forecast API is accessible to all users. Try: http://localhost:35668/api/SampleData/WeatherForecasts</p>

<p>You can secure this by adding the [Authorize] statement to the API on the SampleDataController.cs page e.g.</p>

<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
[Authorize]
[HttpGet(<span style="color: rgb(0, 96, 128);">"[action]"</span>)]
<span style="color: rgb(0, 0, 255);">public</span> IEnumerable&lt;WeatherForecast&gt; WeatherForecasts()
{
    var rng = <span style="color: rgb(0, 0, 255);">new</span> Random();</pre>
</div>

<p>but you will find this presents the standard cloudscribe logon screen to access it – not exactly what’s wanted for an API.</p>

<p>In order to solve this we need to use JWT authorisation alongside the standard cookie authentication, but tell the API to only secure using the JWT authorisation . This is done by filtering the authentication scheme used by the Authorize statement as below (you will probably have to add the following assemblies to your code)</p>

<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
<span style="color: rgb(0, 0, 255);">using</span> Microsoft.AspNetCore.Authorization;
<span style="color: rgb(0, 0, 255);">using</span> Microsoft.AspNetCore.Authentication.JwtBearer;</pre>
</div>

<p>and then add the filter to the authorize statement.</p>

<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[HttpGet(<span style="color: rgb(0, 96, 128);">"[action]"</span>)]
<span style="color: rgb(0, 0, 255);">public</span> IEnumerable&lt;WeatherForecast&gt; WeatherForecasts()
{
    var rng = <span style="color: rgb(0, 0, 255);">new</span> Random();</pre>
</div>

<p>We have now told the API to authenticate using JWTBearer but we haven’t yet added JWT authentication to our applications pipeline. So in the startup.cs page we need to add in some assemblies:</p>

<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
<span style="color: rgb(0, 0, 255);">using</span> Microsoft.AspNetCore.Authentication.JwtBearer;</pre>
</div>

<p>and then add the JWT service into the ConfigureServices method. (I added the statement below just above services.AddCors(options =&gt;)</p>

<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
services.AddAuthentication(options =&gt;
{
    options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
})

.AddJwtBearer(options =&gt;
{
    options.Authority = <span style="color: rgb(0, 96, 128);">"http://localhost:35668"</span>; <span style="color: rgb(0, 128, 0);">//No trailing /</span>
    options.Audience = <span style="color: rgb(0, 96, 128);">"api2"</span>; <span style="color: rgb(0, 128, 0);">//Name of api</span>
    options.RequireHttpsMetadata = <span style="color: rgb(0, 0, 255);">false</span>;

});</pre>
</div>

<p>Where:</p>

<p>.Authority is the address of the website with the api (note no trailing slash)</p>

<p>.Audience is the name you have given to the api in the Identity server 4 security setup (see more details below)</p>

<p>And then we need to tell our pipeline to use Authentication. So add the app.UseAuthentication() into the end of the ConfigureServices method just above the UseMVC call</p>

<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
app.UseAuthentication();
UseMvc(app, multiTenantOptions.Mode == cloudscribe.Core.Models.MultiTenantMode.FolderName);</pre>
</div>

<p>Now if you try and access the api -&nbsp;http://localhost:35668/api/SampleData/WeatherForecasts&nbsp;- you should get an unauthorised message - even if you are logged onto the cloudscribe site using cookie authentication.</p>

<h3>Identity Server 4 configuration (through cloudscribe)</h3>

<p>Identity server has many options – which can be bewildering to start with. Full documentation is here: <a href="https://identityserver4.readthedocs.io/">https://identityserver4.readthedocs.io/</a></p>

<p>For our purposes here – I’m outlining the bare minimum that we need to setup security for our API, either using:</p>

<p>· A client credential using a secret</p>

<p>· A username and password</p>

<h4>API resources</h4>

<p>Under the admin menu in cloudscribe select security settings / API resources and create a new API record giving it a name (e.g. api2) making sure it matches the name you entered as the .Audience in the startup.cs .</p>

<p>Then we need to add a single scope record – called “allowapi2” in this example.</p>

<p><a href="https://www.esdm.co.uk/Data/Sites/1/media/wlw/clip_image004_5.jpg"><img alt="clip_image004" border="0" height="155" src="https://www.esdm.co.uk/Data/Sites/1/media/wlw/clip_image004_thumb_5.jpg" style="margin: 0px; display: inline; background-image: none;" title="clip_image004" width="244" /></a></p>

<h4>Client resources</h4>

<p>Under the admin menu in cloudscribe select security settings / API Clients and create a new client (I’ve called it client2 – remember this name for when we make the call from the client application). Edit the new client record and add:</p>

<p>· Allowed Scope record – e.g. allowapi2 – this must match the scope we entered for the api and is used to specify which apis this client can access</p>

<p><a href="https://www.esdm.co.uk/Data/Sites/1/media/wlw/clip_image006_3.jpg"><img alt="clip_image006" border="0" height="86" src="https://www.esdm.co.uk/Data/Sites/1/media/wlw/clip_image006_thumb_3.jpg" style="margin: 0px; display: inline; background-image: none;" title="clip_image006" width="214" /></a></p>

<p>· Client Secrets – the value is the SHA56 value of the secret we wish to use (in this example secret2) <s>– at the moment the cloudscribe interface doesn’t do this conversion for us so we have to do it manually somewhere&nbsp;(e.g. I used string s = "secret2".ToSha256();)&nbsp; &nbsp;</s></p>

<p><s>I added the secret using the web page and then pasted the converted secret direct into the relevant field in the record in the csids_ClientSecrets table in the database - but I think it would work equally well just pasting the converted value into the web page.</s></p>

<p><s>.ToSha256() is a string extension method&nbsp;in the IdentityModel assembly - this seems to do more than simply convert to sha256 - see&nbsp;<a href="https://github.com/IdentityModel/IdentityModel/blob/master/source/IdentityModel.Net45/Extensions/HashStringExtensions.cs">https://github.com/IdentityModel/IdentityModel/blob/master/source/IdentityModel.Net45/Extensions/HashStringExtensions.cs</a>.</s></p>

<p><s>It’s important that we set the secret type as well – in our example here it must be “SharedSecret”</s></p>

<p>Joe Audette has updated his nuget packages so saving a client secret now gives you a range of options for the secret type - in our example we need to pick "SharedSecret" and select to encrypt using Sha256 (see Joe's post in comments below for other options) which should make things easier.</p>

<p><a href="https://www.esdm.co.uk/Data/Sites/1/media/wlw/clip_image008_1.jpg"><img alt="clip_image008" border="0" height="68" src="https://www.esdm.co.uk/Data/Sites/1/media/wlw/clip_image008_thumb_1.jpg" style="margin: 0px; display: inline; background-image: none;" title="clip_image008" width="244" /></a></p>

<p>· Allowed Grant types – we are entering “password” and “client_credentials”. These determine how we can authenticate from the client app as we see below in the next section. Password means that authentication can use a username / pwd combination (i.e. a cloudscribe login). Client_credentials means we can login using a client secret and don’t have to be a known user on the site.</p>

<p><a href="https://www.esdm.co.uk/Data/Sites/1/media/wlw/clip_image010_1.jpg"><img alt="clip_image010" border="0" height="81" src="https://www.esdm.co.uk/Data/Sites/1/media/wlw/clip_image010_thumb_1.jpg" style="display: inline; background-image: none;" title="clip_image010" width="200" /></a></p>

<h3>Client application</h3>

<p>To connect securely to the API using a client connection with a secret use:</p>

<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
var tokenClient = <span style="color: rgb(0, 0, 255);">new</span> TokenClient(disco.TokenEndpoint, <span style="color: rgb(0, 96, 128);">"client2"</span>, <span style="color: rgb(0, 96, 128);">"secret2"</span>);</pre>
</div>

<p>To connect using a username and password use:</p>

<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
var tokenResponsePassword = await tokenClient.RequestResourceOwnerPasswordAsync(<span style="color: rgb(0, 96, 128);">"admin"</span>, <span style="color: rgb(0, 96, 128);">"admin"</span>, <span style="color: rgb(0, 96, 128);">"allowapi2"</span>);</pre>
</div>

<p>Note that the user name is the user name not the email which can be used to login interactively.</p>

<p>The whole method in the controller looked something like this – the rest of the code is deserializing the JSON return from the API and putting it into an object that can be displayed on a view page</p>

<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
<span style="color: rgb(0, 0, 255);">using</span> System;
<span style="color: rgb(0, 0, 255);">using</span> System.Collections.Generic;
<span style="color: rgb(0, 0, 255);">using</span> System.Diagnostics;
<span style="color: rgb(0, 0, 255);">using</span> System.Threading.Tasks;
<span style="color: rgb(0, 0, 255);">using</span> Microsoft.AspNetCore.Mvc;
<span style="color: rgb(0, 0, 255);">using</span> ESDM.Models;
<span style="color: rgb(0, 0, 255);">using</span> System.Net.Http;
<span style="color: rgb(0, 0, 255);">using</span> Newtonsoft.Json;
<span style="color: rgb(0, 0, 255);">using</span> IdentityModel.Client;
<span style="color: rgb(0, 0, 255);">using</span> IdentityServerClient.Models;
<span style="color: rgb(0, 0, 255);">using</span> IdentityModel;</pre>
</div>

<p>and then</p>

<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
<span style="color: rgb(0, 128, 0);">//Hosted web API REST Service base url  </span>
<span style="color: rgb(0, 0, 255);">string</span> Baseurl = <span style="color: rgb(0, 96, 128);">"http://localhost:35668"</span>;

<span style="color: rgb(0, 0, 255);">public</span> async Task&lt;ActionResult&gt; Index()
{
    List&lt;WeatherForecast&gt; ans = <span style="color: rgb(0, 0, 255);">new</span> List&lt;WeatherForecast&gt;();
     <span style="color: rgb(0, 0, 255);">using</span> (var client = <span style="color: rgb(0, 0, 255);">new</span> HttpClient())
    {
        <span style="color: rgb(0, 128, 0);">// discover endpoints from metadata</span>
        var disco = await DiscoveryClient.GetAsync(Baseurl);
        var tokenClient = <span style="color: rgb(0, 0, 255);">new</span> TokenClient(disco.TokenEndpoint, <span style="color: rgb(0, 96, 128);">"client2"</span>, <span style="color: rgb(0, 96, 128);">"secret2"</span>);
        var tokenResponse = await tokenClient.RequestClientCredentialsAsync(<span style="color: rgb(0, 96, 128);">"allowapi2"</span>);

<span style="color: rgb(0, 128, 0);">//Example getting alternative token if you want to use username / pwd </span>
        var tokenResponsePassword = await tokenClient.RequestResourceOwnerPasswordAsync(<span style="color: rgb(0, 96, 128);">"admin"</span>, <span style="color: rgb(0, 96, 128);">"admin"</span>, <span style="color: rgb(0, 96, 128);">"allowapi2"</span>);

        <span style="color: rgb(0, 128, 0);">// call api - change for tokenResponsePassword if you want to use username / pwd</span>
        client.SetBearerToken(tokenResponse.AccessToken);

        var response = await client.GetAsync(Baseurl + <span style="color: rgb(0, 96, 128);">"/api/SampleData/WeatherForecasts"</span>);
        <span style="color: rgb(0, 0, 255);">if</span> (response.IsSuccessStatusCode)
        {
            var content =  response.Content.ReadAsStringAsync().Result;
            ans = JsonConvert.DeserializeObject&lt;List&lt;WeatherForecast&gt;&gt;(content);
        }
        <span style="color: rgb(0, 0, 255);">return</span> View(ans);
    }</pre>
</div>

<p>The model for the forecast data was:</p>

<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
<span style="color: rgb(0, 0, 255);">namespace</span> ESDM.Models
{
    <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">partial</span> <span style="color: rgb(0, 0, 255);">class</span> WeatherForecast
    {
        <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">string</span> DateFormatted { get; set; }
        <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">int</span> TemperatureC { get; set; }
        <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">string</span> Summary { get; set; }

        <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">int</span> TemperatureF
        {
            get
            {
                <span style="color: rgb(0, 0, 255);">return</span> 32 + (<span style="color: rgb(0, 0, 255);">int</span>)(TemperatureC / 0.5556);
            }
        }
    }
}
</pre>
</div>

<p>And my view contained</p>

<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
@model IEnumerable&lt;ESDM.Models.WeatherForecast&gt;
&lt;div&gt;
    &lt;ul&gt;
        @<span style="color: rgb(0, 0, 255);">foreach</span> (var forecast <span style="color: rgb(0, 0, 255);">in</span> Model)
        {
            &lt;li&gt;@forecast.Summary&lt;/li&gt;
        }
    &lt;/ul&gt;
&lt;/div&gt;</pre>
</div>
<br /><a href='https://www.esdm.co.uk/using-cloudscribe-with-identity-server-4-with-a-sql-server-store-on-net-core-2-mvc-securing-apis'></a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/using-cloudscribe-with-identity-server-4-with-a-sql-server-store-on-net-core-2-mvc-securing-apis'>...</a>]]></description>
      <link>https://www.esdm.co.uk/using-cloudscribe-with-identity-server-4-with-a-sql-server-store-on-net-core-2-mvc-securing-apis</link>
      <author>()</author>
      <comments>https://www.esdm.co.uk/using-cloudscribe-with-identity-server-4-with-a-sql-server-store-on-net-core-2-mvc-securing-apis</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/using-cloudscribe-with-identity-server-4-with-a-sql-server-store-on-net-core-2-mvc-securing-apis</guid>
      <pubDate>Fri, 03 Nov 2017 22:14:00 GMT</pubDate>
    </item>
    <item>
      <title>How to link SQL Server / RDBMS tables into MS Access without a DSN</title>
      <description><![CDATA[<p>Linking tables from RDBMS like SQL Server into an Access front end doesn't need an ODBC DSN to be configured, it can be done with a one-liner. I’m just posting this here because I keep having to look it up and can never&nbsp;find it.<br />
This example is for SQL Server; change the driver for other databases. Run this from the immediate window or a macro (adjust server, table names and credentials to suit):</p>

<p><font face="Courier New">docmd.TransferDatabase acLink, "ODBC","ODBC;DRIVER=SQL Server;SERVER=myServer\myInstanceIfNeeded;DATABASE=myDatabaseName;Trusted_connection=yes;", acTable,"myTableName","myTableName",False,True</font></p>

<p>The final parameter ensures that login credentials are stored.</p>

<p>Of course our&nbsp;production applications&nbsp;like HBSMR and PACS manage&nbsp;database connections&nbsp;in a more sophisticated manner, with the ability to switch databases and define which tables/views are attached in one operation, but the above technique can be useful where MS Access is being used for&nbsp;quick querying/editing/reporting operations.</p>
<br /><a href='https://www.esdm.co.uk/how-to-link-sql-server--rdbms-tables-into-ms-access-without-a-dsn'>Crispin Flower</a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/how-to-link-sql-server--rdbms-tables-into-ms-access-without-a-dsn'>...</a>]]></description>
      <link>https://www.esdm.co.uk/how-to-link-sql-server--rdbms-tables-into-ms-access-without-a-dsn</link>
      <author>crispin.flower@idoxgroup.com (Crispin Flower)</author>
      <comments>https://www.esdm.co.uk/how-to-link-sql-server--rdbms-tables-into-ms-access-without-a-dsn</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/how-to-link-sql-server--rdbms-tables-into-ms-access-without-a-dsn</guid>
      <pubDate>Thu, 30 Mar 2017 18:24:00 GMT</pubDate>
    </item>
    <item>
      <title>GeoServer WFS fails on SQL Server tables/views with GUID data type</title>
      <description><![CDATA[<p>Just a quick note that might be useful to some.</p>

<h4>The problem...</h4>

<p>If you publish a SQL Server (in this case 2014) table or view with a GUID field using GeoServer (version&nbsp;2.10), it will fail to make&nbsp; a valid WFS because the &amp;request=DescribeFeatureType response <em>will not include these layers</em>.</p>

<p>This manifests itself in various ways depending on the client, but in QGIS on trying to load the layer into the map we get this in the "Log Messages Panel":</p>

<blockquote>
<p>Analysis of DescribeFeatureType response failed for url&nbsp; srsname='EPSG:27700' typename=xxx:yyyurl='https://mysite.com/myworkspace/wfs' version='1.0.0' table="" sql=: it is probably a schema for Complex Features</p>
</blockquote>

<p>which had me puzzled for quite some time!</p>

<h4>The solution...</h4>

<p>Changing the data source view to include this field with</p>

<p>CAST(myGUID AS varchar(36)) AS myGUID</p>

<p>then hitting "Reload feature type" in the GeoServer layer configuration screen fixes it. This changes the field data type from "UUID" to "string" in that screen. Or just omit the field entirely.</p>

<p>My guess is this will not help transactional WFS, but I have not tested this. Overall, GUIDs are still best avoided in GIS-land as they are so poorly supported by the database drivers.</p>
<br /><a href='https://www.esdm.co.uk/geoserver-wfs-fails-on-sql-server-tablesviews-with-guid-data-type'>Crispin Flower</a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/geoserver-wfs-fails-on-sql-server-tablesviews-with-guid-data-type'>...</a>]]></description>
      <link>https://www.esdm.co.uk/geoserver-wfs-fails-on-sql-server-tablesviews-with-guid-data-type</link>
      <author>crispin.flower@idoxgroup.com (Crispin Flower)</author>
      <comments>https://www.esdm.co.uk/geoserver-wfs-fails-on-sql-server-tablesviews-with-guid-data-type</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/geoserver-wfs-fails-on-sql-server-tablesviews-with-guid-data-type</guid>
      <pubDate>Wed, 11 Jan 2017 22:23:00 GMT</pubDate>
    </item>
    <item>
      <title>Troubleshooting issues with VSS from backup chain and SQL Server</title>
      <description><![CDATA[<h2>Symptoms:</h2> <p>BackupChain fails almost as soon as it starts when backing up SQL Server VM</p> <p>SQL server VM Application log is riddled with errors</p> <h2>Diagnostics:</h2> <h3>Use VSSDiag</h3> <p>You can start by using the VssDiag <a href="http://backupchain.com/VssDiag.html">http://backupchain.com/VssDiag.html</a> and enter the exact time when the error was reported by backup chain(within 5 minutes) on the SQL Server VM</p> <p>This will list any VSS issues from the log</p> <p>I saw an error like:</p> <blockquote> <p><em>A VSS writer has rejected an event with error 0x800423f4, The writer experienced a non-transient error.&nbsp; If the backup process is retried,<br>the error is likely to reoccur.<br>. Changes that the writer made to the writer components while handling the event will not be available to the requester.<br>Check the event log for related events from the application hosting the VSS writer.</em></p> <p><br><em>Operation:<br>&nbsp;&nbsp; PrepareForSnapshot Event</em></p> <p><em>Context:<br>&nbsp;&nbsp; Execution Context: Writer<br>&nbsp;&nbsp; Writer Class Id: {a65faa63-5ea8-4ebc-9dbd-a0c4db26912a}<br>&nbsp;&nbsp; Writer Name: SqlServerWriter<br>&nbsp;&nbsp; Writer Instance Name: SQL Server 2008 R2:SQLWriter<br>&nbsp;&nbsp; Writer Instance ID: {d78d914d-4a11-4350-8334-af08bff3ce07}<br>&nbsp;&nbsp; Command Line: "C:\Program Files\Microsoft SQL Server\90\Shared\sqlwriter.exe"<br>&nbsp;&nbsp; Process ID: 2408</em></p></blockquote> <h3>Look in VM Application Event Log</h3> <p>I saw several entries for databases:</p> <blockquote> <p><em>The log for database 'CMSi-TNC-demo' is not available. Check the event log for related error messages. Resolve any errors and restart the database.</em></p></blockquote> <p>If in Enterprise manager you run DBCC CHECKDB&nbsp; for the database mentioned you may see a host of errors</p> <h2>Fix:</h2> <p>I found the fix was to take the database in question&nbsp; offline and then put it back online again.</p> <p>Running DBCC CHECKDB again then reported no errors</p> <p>After I had worked through all the databases that had this error – BackupChain could then run a VM backup</p><br /><a href='https://www.esdm.co.uk/troubleshooting-issues-with-vss-from-backup-chain-and-sql-server'></a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/troubleshooting-issues-with-vss-from-backup-chain-and-sql-server'>...</a>]]></description>
      <link>https://www.esdm.co.uk/troubleshooting-issues-with-vss-from-backup-chain-and-sql-server</link>
      <author>()</author>
      <comments>https://www.esdm.co.uk/troubleshooting-issues-with-vss-from-backup-chain-and-sql-server</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/troubleshooting-issues-with-vss-from-backup-chain-and-sql-server</guid>
      <pubDate>Thu, 12 Mar 2015 09:12:25 GMT</pubDate>
    </item>
    <item>
      <title>Confusion when renaming SQL Server views</title>
      <description><![CDATA[<p>If you rename a view through the interface in SQL server, it can lead to strange behaviour later on if you ever come to recompile the view. Symptoms include views failing to recompile and, in extreme cases, the entire structure of a view (not necessarily the one you're recompiling) changing when the&nbsp;built-in <code>sp_refreshview</code> procedure is run.</p>

<p>Behind the scenes, SQL Server stores information about the views in its system tables;&nbsp; the key one for our purposes here is <code>Information_Schema.Views</code>, which includes, among other things, the view's name and its SQL definition, something like the example below:</p>

<table border="1" cellpadding="1" cellspacing="1" height="93" width="100%">
	<tbody>
		<tr>
			<th>Name</th>
			<th>Definition</th>
		</tr>
		<tr>
			<td>vieContacts</td>
			<td>
			<p>Create View vieContacts as Select ContactID, Name, PhoneNumber from ContactsTable</p>
			</td>
		</tr>
	</tbody>
</table>

<p>Now, suppose I rename <code>vieContacts</code> in the interface to <code>OldVieContacts</code>. This will update the name in the system table, but does not update the definition, so I end up with the following:</p>

<table border="1" cellpadding="1" cellspacing="1" height="112" width="100%">
	<tbody>
		<tr>
			<th>Name</th>
			<th>Definition</th>
		</tr>
		<tr>
			<td>OldVieContacts</td>
			<td>
			<p>Create View vieContacts as Select ContactID, Name, PhoneNumber from ContactsTable</p>
			</td>
		</tr>
	</tbody>
</table>

<p>When I come to recompile the view, it will fail, giving me the error "<code>Msg 208, Level 16, State 6, Procedure sp_refreshsqlmodule_internal, Line 75<br />
Invalid object name 'vieContacts'.</code>" This is because the name doesn't match what is stored in the definition.</p>

<p>Unfortunately, the problem doesn't stop there. If I use the copy/paste funtion in SQL Managent Studio, I can copy a view, rename it so that it's a backup and then edit my original. This sounds like a good idea, but because of the problems that renaming causes, it can lead to major headaches later on. To illustrate why this can be so confusing, let's imagine I copy my vieContacts, rename the copy to OldVieContacts and modify my vieContacts to include another couple of fields. After this, I would have the following in <code>Information_Schema.Views</code>:</p>

<table border="1" cellpadding="1" cellspacing="1" height="112" width="100%">
	<tbody>
		<tr>
			<th>Name</th>
			<th>Definition</th>
		</tr>
		<tr>
			<td>OldVieContacts</td>
			<td>
			<p>Create View vieContacts as Select ContactID, Name, PhoneNumber from ContactsTable</p>
			</td>
		</tr>
		<tr>
			<td>vieContacts</td>
			<td>
			<p>Create View vieContacts as Select ContactID, Name, PhoneNumber, Address, Email from ContactsTable</p>
			</td>
		</tr>
	</tbody>
</table>

<p>What makes this such a potential problem is that if I recompile OldVieContacts (and this might be done as part of a script that refreshes all the views) the inbuilt function reads the definition out of <code>Information_Schema.Views</code>, which tells it to rebuild vieContacts, so the result is that vieContacts gets overwritten and I would see my two new columns disappear from it. Worse, the refresh process also updates the definition in <code>Information_Schema.Views</code>, so now vieContacts would be stuck with the incorrect structure and no easy way to fix it.</p>

<p>So what can you do about these problems? Well, here are some suggestions:</p>

<ol>
	<li>Prevention is better than cure. Don't rename views thorugh the SQL Management Studio interface.</li>
	<li>If you need to change the name of the view, drop the view and recreate it with the new name - you can use the "Script View As" option to create a SQL script that will do the drop and create for you, and you can just change the name in the script for the creation before running it.</li>
	<li>If you're lucky, you may be able to rename the view in the interface back to its old name. This isn't recommended though as it's not as sure as other methods.</li>
	<li>Rather than copying a view, just copy the SQL definition from the designer into a new blank view. This may seem more complex than just copying &amp; pasting the view, but it will be better in the long term</li>
	<li>If you suspect that some of your views may suffer from this issue, you can check to see how severe the problem is by running this SQL command from a query window: <code>Select TABLE_NAME, VIEW_DEFINITION from INFORMATION_SCHEMA.VIEWS where VIEW_DEFINITION not like '%' + TABLE_NAME + '%'</code> - this will identify the views that need attention.</li>
	<li>You can repair a view that has suffered in this way by running an <code>Alter View</code> script to alter the view to the correct definition.</li>
</ol>

<p>The best thing, though, is to avoid renaming views through the SQL Server Management Studio interface.</p>
<br /><a href='https://www.esdm.co.uk/confusion-when-renaming-sql-server-views'>Timothy Derbyshire</a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/confusion-when-renaming-sql-server-views'>...</a>]]></description>
      <link>https://www.esdm.co.uk/confusion-when-renaming-sql-server-views</link>
      <author>timothyd@esdm.co.uk (Timothy Derbyshire)</author>
      <comments>https://www.esdm.co.uk/confusion-when-renaming-sql-server-views</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/confusion-when-renaming-sql-server-views</guid>
      <pubDate>Fri, 05 Dec 2014 14:47:00 GMT</pubDate>
    </item>
    <item>
      <title>WMS/WFS down when a GeoServer store is disabled after Windows updates</title>
      <description><![CDATA[<p>Last night some of our servers restarted after scheduled updates, and we awoke to warning emails that some of our GIS web services were down. The affected WMS/WFS services were from <a href="http://geoserver.org/" target="_blank" title="GeoServer web site">GeoServer</a>, so we knew immediately what to look for as this has happened before… the “Store” representing the connection to the GIS data repository – in this case a PostGIS database - had switched itself off, or become disabled:</p>

<p><img alt="GeoServer store disabled after server restart" border="0" height="480" src="https://www.esdm.co.uk/Data/Sites/1/media/wlw/image_139.png" style="border: 0px currentColor; border-image: none; padding-top: 0px; padding-right: 0px; padding-left: 0px; display: inline; background-image: none;" title="GeoServer store disabled after server restart" width="469" /></p>

<p>Ticking the box and saving the Store fixed the problem.</p>

<p>Our hypothesis is that if the GeoServer service is re-started when the database server is not yet available, GeoServer automatically disables the affected Stores. [I later found <a href="http://osgeo-org.1560.x6.nabble.com/PostGIS-Store-disabled-on-server-reboot-td3789469.html" target="_blank">this discussion</a> in which one of the GroServer developers confirms that "the startup code checks if the stores are available, and if not, it<br />
disables them".</p>

<p>We will try to prevent this happening again by ensuring that the GIS server is restarted well after the database servers, but we’d welcome any other ideas.</p>
<br /><a href='https://www.esdm.co.uk/wmswfs-down-when-a-geoserver-store-is-disabled-after-windows-updates'>Crispin Flower</a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/wmswfs-down-when-a-geoserver-store-is-disabled-after-windows-updates'>...</a>]]></description>
      <link>https://www.esdm.co.uk/wmswfs-down-when-a-geoserver-store-is-disabled-after-windows-updates</link>
      <author>crispin.flower@idoxgroup.com (Crispin Flower)</author>
      <comments>https://www.esdm.co.uk/wmswfs-down-when-a-geoserver-store-is-disabled-after-windows-updates</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/wmswfs-down-when-a-geoserver-store-is-disabled-after-windows-updates</guid>
      <pubDate>Thu, 13 Nov 2014 09:31:00 GMT</pubDate>
    </item>
    <item>
      <title>SQL Server - Listing all tables in database, the space used and row counts</title>
      <description><![CDATA[<p>This is a very useful SQL script to listing all of the tables in a SQL Server database with the row count and the amount of space being used by that table, handy for troubleshooting databases that are using more space that expected.</p>

<p>CREATE TABLE #RowCountsAndSizes (TableName NVARCHAR(128),rows CHAR(11), &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp;reserved VARCHAR(18),data VARCHAR(18),index_size VARCHAR(18),&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp;unused VARCHAR(18))</p>

<p>EXEC &nbsp; &nbsp; &nbsp; sp_MSForEachTable 'INSERT INTO #RowCountsAndSizes EXEC sp_spaceused ''?'' '</p>

<p>SELECT &nbsp; &nbsp; TableName,CONVERT(bigint,rows) AS NumberOfRows,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CONVERT(bigint,left(reserved,len(reserved)-3)) AS SizeinKB<br />
FROM &nbsp; &nbsp; &nbsp; #RowCountsAndSizes&nbsp;<br />
ORDER BY &nbsp; NumberOfRows DESC,SizeinKB DESC,TableName</p>

<p>DROP TABLE #RowCountsAndSizes</p>

<p>The original details including some other useful scripts can be found using the following link:</p>

<p><a href="http://www.sqlmatters.com/Articles/Listing%20all%20tables%20in%20a%20database%20and%20their%20row%20counts%20and%20sizes.aspx">&nbsp;http://www.sqlmatters.com/Articles/Listing%20all%20tables%20in%20a%20database%20and%20their%20row%20counts%20and%20sizes.aspx</a></p>
<br /><a href='https://www.esdm.co.uk/sql-server-listing-all-tables-in-database-the-space-used-and-row-counts'>Steve Ellwood</a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/sql-server-listing-all-tables-in-database-the-space-used-and-row-counts'>...</a>]]></description>
      <link>https://www.esdm.co.uk/sql-server-listing-all-tables-in-database-the-space-used-and-row-counts</link>
      <author>stevee@esdm.co.uk (Steve Ellwood)</author>
      <comments>https://www.esdm.co.uk/sql-server-listing-all-tables-in-database-the-space-used-and-row-counts</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/sql-server-listing-all-tables-in-database-the-space-used-and-row-counts</guid>
      <pubDate>Mon, 22 Sep 2014 15:37:00 GMT</pubDate>
    </item>
    <item>
      <title>Remote connection to SQL server on dynamic ports</title>
      <description><![CDATA[<p>SQL server has conventionally used port 1433.&nbsp; However recently Microsoft made some changes and when suing named instanced you are likely to find your SQL Server is using dynamic ports.&nbsp;</p>

<p>This means that SQL server chooses the port to use, which can cause issues if trying to open up the correct port number in a firewall for example.&nbsp; Note that although it is called “dynamic”, once allocated (after SQL restart) it is likely to remain fixed – as on any subsequent restart SQL Server will try and use the same port and will only change port number if that port is no longer available.</p>

<p>If running over a LAN a client to the SQL Server can work out which port to connect on so long as sqlbrowser.exe is allowed in the firewall on the SQL Server machine.&nbsp; This publishes the existence of the SQL Server instance and also which port to connect on.&nbsp;&nbsp; This&nbsp;<a href="http://technet.microsoft.com/en-us/library/ms175043.aspx">TechNet article</a>&nbsp;explains that to connect, the client will send a UDP packet to port 1434 first to resolve the dynamic port.&nbsp; Then it will connect as normal.</p>

<p>There is a good description of what needs opening on a SQL Server server firewall (<a href="https://cs.thomsonreuters.com/ua/toolbox/cs_us_en/kb/k73037522.htm" title="https://cs.thomsonreuters.com/ua/toolbox/cs_us_en/kb/k73037522.htm">https://cs.thomsonreuters.com/ua/toolbox/cs_us_en/kb/k73037522.htm</a>).&nbsp; Basically open port 1433 and allow exceptions for sqlservr.exe and sqlbrowser.exe.</p>

<p>Having done this you should be able to connect from any client so long as outbound ports are not blocked (unusual on a LAN).&nbsp;</p>

<p>However if you are connecting from the internet you may need to open the specific port that sql server is running on.&nbsp; This is a little trickier, as unless sqlbrowser.exe is allowed to communicate through your external firewall, the remote client will not know what port to attempt communication on.</p>

<h1>On SQL Server</h1>

<p>Start SQL server configuration manager and open the correct instance name and 32/64 bit option (double check you are using the right section!)</p>

<p>Make sure TCP/IP is enabled and then look at the properties.</p>

<p><a href="https://www.esdm.co.uk/Data/Sites/1/media/wlw/image_90.png"><img alt="image" border="0" height="244" src="https://www.esdm.co.uk/Data/Sites/1/media/wlw/image_thumb_72.png" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-top-width: 0px" title="image" width="205" /></a></p>

<p>You will see various sections for each LAN card connected (and various virtual ones). Normally you would expect all these to be set as Enabled=No and Dynamic port = 0</p>

<p>The setting we are really interested in is at the bottom in the IPAll section where it gives us the dynamic port number (52056 in this example).&nbsp; If you have allowed sqlserver.exe and sqlbrowser.exe through the servers firewall there should be no configuration needed on the server itself – but any external firewall will need traffic on this port allowing and direct traffic to the SQL Server's IP address.</p>

<p>Once this is allowed – and the external machine can connect by specifying the port on the connection with a comma e.g.</p>

<p>mysqlserver.mydomain.com,52056\SQLEXPRESS</p>

<p>This will work in enterprise manager or in your connection string to SQL server</p>

<p>From the client you can run from the command line:&nbsp;</p>

<ul>
	<li>NetStat -o</li>
</ul>

<p>This will list all ports currently in use - so if you can connect to the SQL Server server from another machine on the LAN (or witha VPN up) this can also help identify port in use.</p>

<p><em>Note:&nbsp; Please add / edit above if incorrect / incomplete as its based on my best understanding to date !</em></p>

<h1>Useful links</h1>

<p><a href="http://dba.stackexchange.com/questions/47651/when-is-a-dynamic-port-dynamic" title="http://dba.stackexchange.com/questions/47651/when-is-a-dynamic-port-dynamic">http://dba.stackexchange.com/questions/47651/when-is-a-dynamic-port-dynamic</a></p>

<p><a href="http://support.microsoft.com/kb/823938" title="http://support.microsoft.com/kb/823938">http://support.microsoft.com/kb/823938</a></p>

<p><a href="http://blogs.msdn.com/b/bgroth/archive/2004/11/11/256190.aspx">http://blogs.msdn.com/b/bgroth/archive/2004/11/11/256190.aspx</a></p>

<p>&nbsp;</p>
<br /><a href='https://www.esdm.co.uk/remote-connection-to-sql-server-on-dynamic-ports'></a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/remote-connection-to-sql-server-on-dynamic-ports'>...</a>]]></description>
      <link>https://www.esdm.co.uk/remote-connection-to-sql-server-on-dynamic-ports</link>
      <author>()</author>
      <comments>https://www.esdm.co.uk/remote-connection-to-sql-server-on-dynamic-ports</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/remote-connection-to-sql-server-on-dynamic-ports</guid>
      <pubDate>Sun, 02 Mar 2014 14:22:00 GMT</pubDate>
    </item>
    <item>
      <title>Using R with spatial data</title>
      <description><![CDATA[<p>&nbsp;</p> <p>R is a cross platform statistical package which is becoming extremely widely used.&nbsp; It is modular and so there are all sorts of add ins available, including a number of sophisticated tools for spatial analysis some of which run considerably faster than Arc / MapInfo.&nbsp; Organisations are also starting to move to this for spatial analysis as its cheaper but more relevantly doesn’t suffer from the endless version changes that ArcGIS is particular forces on people.</p> <p>R is generally used for a wide range of statistics – but also has the option to generate publication quality graphs (pdfs or images)</p> <h1>Getting started</h1> <p>R can be downloaded here: <a href="http://www.r-project.org/">http://www.r-project.org/</a></p> <p>Its also suggested (on Windows) to use r studio - <a href="http://www.rstudio.com/">http://www.rstudio.com/</a> which gives a more friendly IDE</p> <p>R is a scripted tool – so it can be a steep learning curve but there are endless examples on the web to help get started.</p> <h1>Spatial example using OGR</h1> <p>This syntax is a little obscure – but potentially of considerable use for a wide range of spatial data.&nbsp; Reading from shapefiles (or any other OGR supported datasource is easy / possible)</p> <h2>Read data from SQL server</h2> <p>#download and load rgdal libraries<br>install.packages("rgdal")<br>library(rgdal)</p> <p>#Use ogrinfo to get information about a shape file called stations<br>ogrInfo("C:/ToFile/RNLI/data", "Stations")</p> <p>#List the spatial layers available in a SQL server database<br>#Note you must have the standard OGR tables geometry_columns and spatial_ref_sys present and populated in your database<br>#Some people say you need a DSN as well – not sure you do …<br>ogrListLayers("MSSQL:server=SQL2008;database=CMSI-NE;trusted_connection=yes") </p> <p>#Read a table of polygon objects into a new sitesPoly object<br>#Then plot them on a map<br>#N.B.&nbsp; You can’t have binary data in your table – so if you do create a view or somesuch<br>sitesPoly &lt;- readOGR(dsn='MSSQL:server=SQL2008;database=CMSI-NE;trusted_connection=true', layer='SitesGeom') <br>plot(sitesPoly) </p> <p><a href="https://www.esdm.co.uk/Data/Sites/1/media/wlw/image_84.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="https://www.esdm.co.uk/Data/Sites/1/media/wlw/image_thumb_70.png" width="244" height="171"></a></p> <p>#Select just one record from the layer<br>oneSite = subset(sitesPoly, sitesPoly$MI_PRINX == 420)</p> <p>#Make sure the layer is assigned the correct projection<br>proj4string(oneSite) = CRS("+init=epsg:27700")</p> <p>#Transform the layer to another projection<br>oneSite_latlong = spTransform(oneSite, CRS("+init=epsg:4326"))</p> <p>#Load another library which contains some world boundaries<br>#Load up coast and countries outlines<br>library(rworldmap)<br>data(coastsCoarse)<br>data(countriesLow)</p><pre>&nbsp;</pre>
<p>#plot countries outline limiting extent to Europe<br>plot(countriesLow, xlim = c(-10, 10), ylim = c(45, 60), legend = F)</p>
<p>#Add sites onto existing map setting colours</p>
<p>proj4string(sitesPoly_ll) = CRS("+init=epsg:27700")<br>sitesPoly_ll = spTransform(sitesPoly, CRS("+init=epsg:4326"))<br>plot(sitesPoly_ll, col = "red", border="red", Add=T)</p>
<p>&nbsp;</p>
<h2>Use a different library to do some plotting</h2>
<p>install.packages("maps")<br>install.packages("mapdata")<br>library(maps)<br>library(mapsdata)</p>
<p>#Select polygons making up UK and plot<br>#Then plot a point on top<br>map('worldHires',<br>&nbsp;&nbsp;&nbsp; c('UK', 'Ireland', 'Isle of Man','Isle of Wight','Wales:Anglesey'),<br>&nbsp;&nbsp;&nbsp; xlim=c(-11,3), ylim=c(49,60.9))<br>points(-1.615672,54.977768,col=2,pch=18)</p>
<p><a href="https://www.esdm.co.uk/Data/Sites/1/media/wlw/image_85.png"><img title="image" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; border-left: 0px; display: inline; padding-right: 0px" border="0" alt="image" src="https://www.esdm.co.uk/Data/Sites/1/media/wlw/image_thumb_71.png" width="244" height="170"></a></p><br /><a href='https://www.esdm.co.uk/using-r-with-spatial-data'></a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/using-r-with-spatial-data'>...</a>]]></description>
      <link>https://www.esdm.co.uk/using-r-with-spatial-data</link>
      <author>()</author>
      <comments>https://www.esdm.co.uk/using-r-with-spatial-data</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/using-r-with-spatial-data</guid>
      <pubDate>Sat, 28 Dec 2013 12:53:39 GMT</pubDate>
    </item>
    <item>
      <title>How to set up a MapInfo DBMS table from SQL Server without a DSN</title>
      <description><![CDATA[<p>A quick note to say that it is definitely possible to&nbsp;use a SQL Server spatial table in MapInfo Professional without an ODBC&nbsp;DSN. There's not much about this on the web, and the normal methods of opening SQL Server tables&nbsp;all seem to want a DSN. Here's a resulting .TAB file (this assumes you have the table or view configured in the MAPINFO.MAPINFO_MAPCATALOG table):</p>

<p>&nbsp;</p>

<p><code>!table<br />
!version 1000<br />
!charset WindowsLatin1</code></p>

<p><code>Definition Table<br />
&nbsp; Type ODBC<br />
begin_metadata<br />
"\IsReadOnly" = "FALSE"<br />
"\MapInfo" = ""<br />
"\MapInfo\TableID" = "2e88f9e5-7d4c-4645-b824-4ef6b5102c9e"<br />
"\DATALINK" = ""<br />
"\DATALINK\Query" = "Select *&nbsp; From ""myDatabase"".""dbo"".""myTableOrView"""<br />
"\DATALINK\ConnectionString" = "Description=aDescription;DRIVER=SQL Server;SERVER=myServer;Trusted_Connection=Yes;APP=MapInfo Professional®;WSID=blah;DATABASE=myDatabase"<br />
"\DATALINK\ToolKit" = "ODBC"<br />
"\CACHE" = "OFF"<br />
"\MBRSEARCH" = "ON"<br />
end_metadata</code></p>
<br /><a href='https://www.esdm.co.uk/how-to-set-up-a-mapinfo-dbms-table-from-sql-server-without-a-dsn'>Crispin Flower</a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/how-to-set-up-a-mapinfo-dbms-table-from-sql-server-without-a-dsn'>...</a>]]></description>
      <link>https://www.esdm.co.uk/how-to-set-up-a-mapinfo-dbms-table-from-sql-server-without-a-dsn</link>
      <author>crispin.flower@idoxgroup.com (Crispin Flower)</author>
      <comments>https://www.esdm.co.uk/how-to-set-up-a-mapinfo-dbms-table-from-sql-server-without-a-dsn</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/how-to-set-up-a-mapinfo-dbms-table-from-sql-server-without-a-dsn</guid>
      <pubDate>Thu, 14 Nov 2013 18:41:00 GMT</pubDate>
    </item>
    <item>
      <title>Optimising SQL Server spatial indexing - let sql do the work..</title>
      <description><![CDATA[<p>Note – this will take a LONG time to run – quite possibly many hours - on a big dataset as it drops and recreates the index using different parameters – sledgehammer approach, but given the permutations available in SQL server spatial indexing and the level of confusion around optimising – this is the empirical approach.</p>

<p>lifted from here: <a href="http://stackoverflow.com/questions/2920948/selecting-a-good-sql-server-2008-spatial-index-with-large-polygons">http://stackoverflow.com/questions/2920948/selecting-a-good-sql-server-2008-spatial-index-with-large-polygons</a></p>

<p>Basically crate the SPROC listed at the bottom, then setup some example calls (3 or 4 different ones to minimise caching artefacts)</p>

<p>Then set it running and go on holiday …</p>

<h2>Setup your parameters:</h2>

<p>DECLARE @g1 VARCHAR(MAX)<br />
SET @g1 = 'GEOMETRY::STGeomFromText(''POLYGON((252783.989267352 461095.507712082,260134.010732648 461095.507712082,260134.010732648 465068.492287918,252783.989267352 465068.492287918,252783.989267352 461095.507712082))'', 28992)'<br />
DECLARE @g2 VARCHAR(MAX)<br />
SET @g2 = 'GEOMETRY::STGeomFromText(''POLYGON((5580.146375 5340.100667,655613.186375 5340.100667,655613.186375 1219811.501845,5580.146375 1219811.501845,5580.146375 5340.100667))'',28992)'<br />
exec sp_tune_spatial_index 'OBSVEG.OBS_Locations' ,'sidx_OBS_Locations_geom',2,8,@g1,@g2</p>

<h2>Create Stored procedure:</h2>

<p><em>N.B. Assumes geometry field is called geom</em><br />
<em>N.B. You MUST modify the SPROC to use extents for your SRID</em></p>

<pre class="csharpcode">
<span class="kwrd">USE</span> [CMSI-OBSVEG]
<span class="kwrd">GO</span>
/****** <span class="kwrd">Object</span>:  StoredProcedure [dbo].[sp_tune_spatial_index]    Script <span class="kwrd">Date</span>: 10/01/2013 11:35:27 ******/
<span class="kwrd">SET</span> ANSI_NULLS <span class="kwrd">ON</span>
<span class="kwrd">GO</span>
<span class="kwrd">SET</span> QUOTED_IDENTIFIER <span class="kwrd">ON</span>
<span class="kwrd">GO</span>

<span class="kwrd">ALTER</span> <span class="kwrd">PROCEDURE</span> [dbo].[sp_tune_spatial_index]
(
  @tabnm                <span class="kwrd">VARCHAR</span>(<span class="kwrd">MAX</span>),    <span class="rem">-- This parameter stores the name of the spatial table for which you are tuning the index</span>
    @idxnm                <span class="kwrd">VARCHAR</span>(<span class="kwrd">MAX</span>),    <span class="rem">-- This parameter stores the name of the spatial index of the named table</span>
    @min_cells_per_obj    <span class="kwrd">INT</span>,            <span class="rem">-- Minimum Cells Per Object to test on. Suggested to start at 2.</span>
    @max_cells_per_obj    <span class="kwrd">INT</span>,            <span class="rem">-- Maximum Cells Per Object to test on.</span>
    
    /*    The test requires two geometry instances <span class="kwrd">to</span> <span class="kwrd">use</span> <span class="kwrd">in</span> test query 1 <span class="kwrd">and</span> 2.
        The <span class="kwrd">first</span> one should cover the area <span class="kwrd">of</span> <span class="kwrd">default</span> extent. The <span class="kwrd">second</span> should
        cover an area roughly the <span class="kwrd">size</span> <span class="kwrd">of</span> the area shown <span class="kwrd">when</span> zoomed <span class="kwrd">in</span>, panning
        around. It <span class="kwrd">is</span> required that the <span class="kwrd">variable</span> store a string that will <span class="kwrd">create</span>
        the geometry instance since this will be done within the <span class="kwrd">procedure</span> <span class="kwrd">and</span> 
        cannot be a <span class="kwrd">variable</span> <span class="kwrd">of</span> type: GEOMETRY. The SRID <span class="kwrd">of</span> these instances must
        <span class="kwrd">match</span> that <span class="kwrd">of</span> the <span class="kwrd">table</span> you <span class="kwrd">are</span> testing. */
    @testgeom1            <span class="kwrd">VARCHAR</span>(<span class="kwrd">MAX</span>),    <span class="rem">-- This parameter stores the first geometry instance creation string that will be used in the test</span>
    @testgeom2            <span class="kwrd">VARCHAR</span>(<span class="kwrd">MAX</span>)    <span class="rem">-- This parameter stores the second geometry instance creation string that will be used in the test</span>
    
)

<span class="kwrd">AS</span>

<span class="kwrd">SET</span> NOCOUNT <span class="kwrd">ON</span>;

/*    <span class="kwrd">Prior</span> <span class="kwrd">to</span> running this <span class="kwrd">procedure</span>, two tables <span class="kwrd">are</span> required. These tables <span class="kwrd">are</span> 
    created here <span class="kwrd">to</span> <span class="kwrd">prepare</span> <span class="kwrd">for</span> running the <span class="kwrd">procedure</span>.    */

<span class="kwrd">PRINT</span> <span class="str">'Checking for required tables...'</span>
<span class="kwrd">IF</span> <span class="kwrd">EXISTS</span>(<span class="kwrd">SELECT</span> 1 <span class="kwrd">FROM</span> sysobjects <span class="kwrd">WHERE</span> name <span class="kwrd">IN</span> (<span class="str">'cell_opt_perm'</span>, <span class="str">'spat_idx_test_result'</span>))
    <span class="kwrd">BEGIN</span>
        <span class="kwrd">PRINT</span> <span class="str">'... The "cell_opt_perm" and "spat_idx_test_result" tables exist.'</span>
    <span class="kwrd">END</span>
<span class="kwrd">ELSE</span>
<span class="kwrd">BEGIN</span>
    <span class="kwrd">PRINT</span> <span class="str">'... Creating "cell_opt_perm" and "spat_idx_test_result" tables.'</span>
    <span class="kwrd">CREATE</span> <span class="kwrd">TABLE</span> cell_opt_perm(
        [perm_id] [<span class="kwrd">smallint</span>] <span class="kwrd">NOT</span> <span class="kwrd">NULL</span>,
        [permutation] [nvarchar](4) <span class="kwrd">NOT</span> <span class="kwrd">NULL</span>,
        [level1] [nvarchar](6) <span class="kwrd">NOT</span> <span class="kwrd">NULL</span>,
        [level2] [nvarchar](6) <span class="kwrd">NOT</span> <span class="kwrd">NULL</span>,
        [level3] [nvarchar](6) <span class="kwrd">NOT</span> <span class="kwrd">NULL</span>,
        [level4] [nvarchar](6) <span class="kwrd">NOT</span> <span class="kwrd">NULL</span>
    )

    INSERT <span class="kwrd">INTO</span> cell_opt_perm ([perm_id], [permutation], [level1], [level2], [level3], [level4])
    <span class="kwrd">VALUES</span> (1,<span class="str">'LLLL'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>),
        (2,<span class="str">'LLLM'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>),
        (3,<span class="str">'LLLH'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>),
        (4,<span class="str">'LLML'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>),
        (5,<span class="str">'LLMM'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>),
        (6,<span class="str">'LLMH'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>),
        (7,<span class="str">'LLHL'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>),
        (8,<span class="str">'LLHM'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>),
        (9,<span class="str">'LLHH'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>),
        (10,<span class="str">'LMLL'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>),
        (11,<span class="str">'LMLM'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>),
        (12,<span class="str">'LMLH'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>),
        (13,<span class="str">'LMML'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>),
        (14,<span class="str">'LMMM'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>),
        (15,<span class="str">'LMMH'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>),
        (16,<span class="str">'LMHL'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>),
        (17,<span class="str">'LMHM'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>),
        (18,<span class="str">'LMHH'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>),
        (19,<span class="str">'LHLL'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>),
        (20,<span class="str">'LHLM'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>),
        (21,<span class="str">'LHLH'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>),
        (22,<span class="str">'LHML'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>),
        (23,<span class="str">'LHMM'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>),
        (24,<span class="str">'LHMH'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>),
        (25,<span class="str">'LHHL'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>),
        (26,<span class="str">'LHHM'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>),
        (27,<span class="str">'LHHH'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>),
        (28,<span class="str">'MLLL'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>),
        (29,<span class="str">'MLLM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>),
        (30,<span class="str">'MLLH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>),
        (31,<span class="str">'MLML'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>),
        (32,<span class="str">'MLMM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>),
        (33,<span class="str">'MLMH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>),
        (34,<span class="str">'MLHL'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>),
        (35,<span class="str">'MLHM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>),
        (36,<span class="str">'MLHH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>),
        (37,<span class="str">'MMLL'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>),
        (38,<span class="str">'MMLM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>),
        (39,<span class="str">'MMLH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>),
        (40,<span class="str">'MMML'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>),
        (41,<span class="str">'MMMM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>),
        (42,<span class="str">'MMMH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>),
        (43,<span class="str">'MMHL'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>),
        (44,<span class="str">'MMHM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>),
        (45,<span class="str">'MMHH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>),
        (46,<span class="str">'MHLL'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>),
        (47,<span class="str">'MHLM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>),
        (48,<span class="str">'MHLH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>),
        (49,<span class="str">'MHML'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>),
        (50,<span class="str">'MHMM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>),
        (51,<span class="str">'MHMH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>),
        (52,<span class="str">'MHHL'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>),
        (53,<span class="str">'MHHM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>),
        (54,<span class="str">'MHHH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>),
        (55,<span class="str">'HLLL'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>),
        (56,<span class="str">'HLLM'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>),
        (57,<span class="str">'HLLH'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>),
        (58,<span class="str">'HLML'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>),
        (59,<span class="str">'HLMM'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>),
        (60,<span class="str">'HLMH'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>),
        (61,<span class="str">'HLHL'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>),
        (62,<span class="str">'HLHM'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>),
        (63,<span class="str">'HLHH'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>),
        (64,<span class="str">'HMLL'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>),
        (65,<span class="str">'HMLM'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>),
        (66,<span class="str">'HMLH'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>),
        (67,<span class="str">'HMML'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>),
        (68,<span class="str">'HMMM'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>),
        (69,<span class="str">'HMMH'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>),
        (70,<span class="str">'HMHL'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>),
        (71,<span class="str">'HMHM'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>),
        (72,<span class="str">'HMHH'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>),
        (73,<span class="str">'HHLL'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>,<span class="str">'LOW'</span>),
        (74,<span class="str">'HHLM'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>,<span class="str">'MEDIUM'</span>),
        (75,<span class="str">'HHLH'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>,<span class="str">'HIGH'</span>),
        (76,<span class="str">'HHML'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'LOW'</span>),
        (77,<span class="str">'HHMM'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'MEDIUM'</span>),
        (78,<span class="str">'HHMH'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>,<span class="str">'HIGH'</span>),
        (79,<span class="str">'HHHL'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>,<span class="str">'LOW'</span>),
        (80,<span class="str">'HHHM'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>,<span class="str">'MEDIUM'</span>),
        (81,<span class="str">'HHHH'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>,<span class="str">'HIGH'</span>)
    
    <span class="kwrd">CREATE</span> <span class="kwrd">TABLE</span> spat_idx_test_result(
        [perm_id] [<span class="kwrd">int</span>] <span class="kwrd">NOT</span> <span class="kwrd">NULL</span>,
        [num_cells] [<span class="kwrd">int</span>] <span class="kwrd">NOT</span> <span class="kwrd">NULL</span>,
        [permut] [nvarchar](4) <span class="kwrd">NOT</span> <span class="kwrd">NULL</span>,
        [g1t1] [bigint] <span class="kwrd">NULL</span>,
        [g1t2] [bigint] <span class="kwrd">NULL</span>,
        [g1t3] [bigint] <span class="kwrd">NULL</span>,
        [g1t4] [bigint] <span class="kwrd">NULL</span>,
        [g2t1] [bigint] <span class="kwrd">NULL</span>,
        [g2t2] [bigint] <span class="kwrd">NULL</span>,
        [g2t3] [bigint] <span class="kwrd">NULL</span>,
        [g2t4] [bigint] <span class="kwrd">NULL</span>
    )
    
    INSERT <span class="kwrd">INTO</span> dbo.spat_idx_test_result
    <span class="kwrd">VALUES</span> (0,16,0,<span class="kwrd">NULL</span>,<span class="kwrd">NULL</span>,<span class="kwrd">NULL</span>,<span class="kwrd">NULL</span>,<span class="kwrd">NULL</span>,<span class="kwrd">NULL</span>,<span class="kwrd">NULL</span>,<span class="kwrd">NULL</span>)
<span class="kwrd">END</span>


/*    <span class="kwrd">delete</span> <span class="kwrd">all</span> <span class="kwrd">rows</span> <span class="kwrd">from</span> "spat_idx_test_result" <span class="kwrd">table</span>. This makes it ready <span class="kwrd">to</span> stuff <span class="kwrd">in</span> <span class="kwrd">new</span> results.
    !!!WARNING!!! <span class="kwrd">if</span> your test was interupted, the <span class="kwrd">table</span> will be cleared <span class="kwrd">out</span> <span class="kwrd">and</span> the test will
    <span class="kwrd">begin</span> <span class="kwrd">from</span> the beginning. You could try <span class="kwrd">to</span> <span class="kwrd">modify</span> this <span class="kwrd">to</span> <span class="kwrd">start</span> <span class="kwrd">where</span> you <span class="kwrd">left</span> <span class="kwrd">off</span> but
    I didn<span class="str">'t have time and this worked well enough for me. */
DELETE FROM spat_idx_test_result
    WHERE perm_id != 0

/* set up counters */
DECLARE @a1 INT
DECLARE @a2 INT
DECLARE @a3 INT
DECLARE @a4 INT

/* set up variables to hold high/medium/low values and permutation to use in rebuilding
   the spatial index and recording stats */
DECLARE @lev1 VARCHAR(6)
DECLARE @lev2 VARCHAR(6)
DECLARE @lev3 VARCHAR(6)
DECLARE @lev4 VARCHAR(6)
DECLARE @permut VARCHAR(6)
DECLARE @num_cell VARCHAR(4)
DECLARE @time_str VARCHAR(20)
DECLARE @perm_id VARCHAR(20)

/* create variables to hold timestamps for beginning and ending of test queries */
DECLARE @start_t DATETIME
DECLARE @end_t DATETIME
DECLARE @elapse_t INT

/* begin looping through cell option permutations */
SET @a1 = @min_cells_per_obj
WHILE @a1 &lt;= @max_cells_per_obj
    BEGIN
        SET @a2 = 1
        PRINT '</span>Started Testing <span class="kwrd">for</span> <span class="str">' +CAST(@a1 AS VARCHAR(10)) +'</span> cells per <span class="kwrd">object</span><span class="str">'
        WHILE @a2 &lt; 82
            BEGIN
                SELECT @lev1 = level1, @lev2 = level2, @lev3 = level3, @lev4 = level4 FROM cell_opt_perm WHERE perm_id = @a2
                SET @permut = '</span><span class="str">''</span><span class="str">' +(SELECT permutation FROM cell_opt_perm WHERE perm_id = @a2) +'</span><span class="str">''</span><span class="str">'
                EXEC
                    ('</span>
                        <span class="kwrd">CREATE</span> SPATIAL <span class="kwrd">INDEX</span> <span class="str">' +@idxnm +'</span> <span class="kwrd">ON</span> <span class="str">' +@tabnm +'</span> 
                        (
                            [geom]
                        )
                        <span class="kwrd">USING</span>  GEOMETRY_GRID 
                        <span class="kwrd">WITH</span>
                            (
                                BOUNDING_BOX =(-100, -100, 300000, 650000),
                                GRIDS =(LEVEL_1 = <span class="str">' +@lev1 +'</span> ,LEVEL_2 = <span class="str">' +@lev2 +'</span> ,LEVEL_3 = <span class="str">' +@lev3 +'</span> ,LEVEL_4 = <span class="str">' +@lev4 +'</span> ), 
                                CELLS_PER_OBJECT = <span class="str">' +@a1 +'</span> ,
                                PAD_INDEX  = <span class="kwrd">OFF</span>,
                                SORT_IN_TEMPDB = <span class="kwrd">OFF</span>,
                                DROP_EXISTING = <span class="kwrd">ON</span>,
                                ALLOW_ROW_LOCKS  = <span class="kwrd">ON</span>,
                                ALLOW_PAGE_LOCKS  = <span class="kwrd">ON</span>,
                                <span class="kwrd">FILLFACTOR</span> = 100
                            )
                        <span class="kwrd">ON</span> [<span class="kwrd">PRIMARY</span>]<span class="str">'
                    )
                PRINT '</span>Re-built <span class="kwrd">index</span> <span class="kwrd">to</span> <span class="str">' +@permut
                SET @a3 = 1
                SET @a4 = 1
                WHILE @a3 &lt; 5
                    BEGIN
                        SET @start_t = GETDATE()
                        EXEC
                            (
                                '</span><span class="kwrd">CREATE</span> <span class="kwrd">TABLE</span> #tmp_tab (shp GEOMETRY)
                                <span class="kwrd">DECLARE</span> @g1 GEOMETRY
                                <span class="kwrd">SET</span> @g1 = <span class="str">' +@testgeom1 +'</span>
                                INSERT #tmp_tab (shp)
                                    <span class="kwrd">SELECT</span>
                                        r.geom <span class="kwrd">AS</span> shp
                                    <span class="kwrd">FROM</span>
                                        <span class="str">' +@tabnm +'</span> r
                                    <span class="kwrd">WHERE</span>
                                        r.geom.STIntersects(@g1) = 1
                                <span class="kwrd">DROP</span> <span class="kwrd">TABLE</span> #tmp_tab<span class="str">'
                            )
                        SET @end_t = GETDATE()
                        SET @elapse_t = (SELECT DATEDIFF(MS, @start_t, @end_t))
                        SET @num_cell = CAST(@a1 AS VARCHAR(6))
                        SET @time_str = CAST(@elapse_t AS VARCHAR(20))
                        IF @a3 = 1
                            BEGIN
                                IF (SELECT TOP 1 perm_id FROM spat_idx_test_result) IS NULL
                                    BEGIN
                                        SET @perm_id = 1
                                    END
                                ELSE
                                    BEGIN
                                        SET @perm_id = CAST((SELECT MAX(perm_id+1) FROM spat_idx_test_result) AS VARCHAR(20))
                                    END
                                EXEC
                                    (
                                        '</span>INSERT <span class="kwrd">INTO</span> spat_idx_test_result (perm_id, num_cells, permut, g1t<span class="str">' +@a3 +'</span>)
                                        <span class="kwrd">VALUES</span> (<span class="str">' +@perm_id +'</span>, <span class="str">' +@num_cell +'</span>, <span class="str">' +@permut +'</span>, <span class="str">' +@time_str +'</span>)<span class="str">'
                                    )
                            END
                        ELSE
                            EXEC
                                (
                                    '</span><span class="kwrd">UPDATE</span> spat_idx_test_result
                                    <span class="kwrd">SET</span>
                                    num_cells = <span class="str">' +@num_cell +'</span>,
                                    permut = <span class="str">' +@permut +'</span>,
                                    g1t<span class="str">' +@a3 +'</span> = <span class="str">' +@time_str +'</span>
                                    <span class="kwrd">WHERE</span> perm_id = <span class="str">' +@perm_id
                                )
                        SET @a3 = @a3 + 1
                    END
                WHILE @a4 &lt; 5
                    BEGIN
                        SET @start_t = GETDATE()
                        EXEC
                            (
                                '</span><span class="kwrd">CREATE</span> <span class="kwrd">TABLE</span> #tmp_tab (shp GEOMETRY) 
                                <span class="kwrd">DECLARE</span> @g2 GEOMETRY
                                <span class="kwrd">SET</span> @g2 = <span class="str">' +@testgeom2 +'</span>
                                INSERT #tmp_tab (shp)
                                    <span class="kwrd">SELECT</span>
                                        r.geom <span class="kwrd">AS</span> shp
                                    <span class="kwrd">FROM</span>
                                        <span class="str">' +@tabnm +'</span> r
                                    <span class="kwrd">WHERE</span>
                                        r.geom.STIntersects(@g2) = 1
                                <span class="kwrd">DROP</span> <span class="kwrd">TABLE</span> #tmp_tab<span class="str">'
                            )
                        SET @end_t = GETDATE()
                        SET @elapse_t = (SELECT DATEDIFF(MS, @start_t, @end_t))
                        SET @num_cell = CAST(@a1 AS VARCHAR(6))
                        SET @time_str = CAST(@elapse_t AS VARCHAR(20))
                        EXEC
                            (
                                '</span><span class="kwrd">UPDATE</span> spat_idx_test_result
                                <span class="kwrd">SET</span>
                                num_cells = <span class="str">' +@num_cell +'</span>,
                                permut = <span class="str">' +@permut +'</span>,
                                g2t<span class="str">' +@a4 +'</span> = <span class="str">' +@time_str +'</span>
                                <span class="kwrd">WHERE</span> perm_id = <span class="str">' +@perm_id
                            )
                        SET @a4 = @a4 + 1
                    END
                SET @a2 = @a2 + 1
            END
        SET @a1 = @a1 + 1
    END
PRINT '</span>Testing <span class="kwrd">of</span> <span class="str">' +@tabnm +'</span> spatial <span class="kwrd">index</span>: <span class="str">' +@idxnm +'</span> <span class="kwrd">is</span> complete!'
</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p><a href="https://www.esdm.co.uk/Data/Sites/1/media/wlw/image_58.png"><img alt="image" border="0" height="170" src="https://www.esdm.co.uk/Data/Sites/1/media/wlw/image_thumb_47.png" style="margin: 0px; border: 0px currentColor; padding-top: 0px; padding-right: 0px; padding-left: 0px; display: inline; background-image: none;" title="image" width="244" /></a></p>
<br /><a href='https://www.esdm.co.uk/optimising-sql-server-spatial-indexing-let-sql-do-the-work'></a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/optimising-sql-server-spatial-indexing-let-sql-do-the-work'>...</a>]]></description>
      <link>https://www.esdm.co.uk/optimising-sql-server-spatial-indexing-let-sql-do-the-work</link>
      <author>()</author>
      <comments>https://www.esdm.co.uk/optimising-sql-server-spatial-indexing-let-sql-do-the-work</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/optimising-sql-server-spatial-indexing-let-sql-do-the-work</guid>
      <pubDate>Tue, 01 Oct 2013 09:11:00 GMT</pubDate>
    </item>
    <item>
      <title>SQL Server Manager Studio 2008 bug expanding database list</title>
      <description><![CDATA[<p>There is a bug within SSMS 2008 where if you connect to a db server using an account that does not have any rights to some of the database you can get an error when trying to expand the database list preventing you from accessing those databases that you do have rights to.</p>

<p>The error you receive looks something like this:</p>

<p><em>Failed to retrieve data for this request. (Microsoft.SqlServer.Management.Sdk.Sfc)</em></p>

<p><em>For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&amp;LinkId=20476</em></p>

<p><em>------------------------------<br />
ADDITIONAL INFORMATION:</em></p>

<p><em>An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)</em></p>

<p><em>------------------------------</em></p>

<p><em>The server principal "CMSi-NATBN-Admin" is not able to access the database "CAMS-CCW-WCP2010" under the current security context. (Microsoft SQL Server, Error: 916)</em></p>

<p>The error is caused because SSMS fails when trying to read some of the information about the databases, in oder to fix the problem you have to configure that specific SSMS installation to not read that data about that database server. You do this as follows:</p>

<ul>
	<li>Run SSMS and connect to required db server as sa or admin user account.</li>
	<li>Press F7 to open the "Object Explorer Details" window</li>
	<li>In the object explorer details window expand double click on "Databases"</li>
	<li>Right click on the header bar ("Name", "Recovery Model", etc) and deselect "Collation"</li>
	<li>Disconnect from the db server</li>
	<li>Reconnect to db server using desired account and test</li>
</ul>
<br /><a href='https://www.esdm.co.uk/sql-server-manager-studio-2008-bug-expanding-database-list'>Steve Ellwood</a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/sql-server-manager-studio-2008-bug-expanding-database-list'>...</a>]]></description>
      <link>https://www.esdm.co.uk/sql-server-manager-studio-2008-bug-expanding-database-list</link>
      <author>stevee@esdm.co.uk (Steve Ellwood)</author>
      <comments>https://www.esdm.co.uk/sql-server-manager-studio-2008-bug-expanding-database-list</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/sql-server-manager-studio-2008-bug-expanding-database-list</guid>
      <pubDate>Fri, 27 Sep 2013 11:27:00 GMT</pubDate>
    </item>
    <item>
      <title>Invalid column name problem with GeoServer 2.3 and SQL Server views</title>
      <description><![CDATA[<p>I have been getting this error with a WMS layer based on a SQL Server 2008 view, when using a GetFeatureInfo request:</p>

<pre>
<code><span style="font: small/normal Verdana, Geneva, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; float: none; display: inline !important; white-space: normal; font-size-adjust: none; font-stretch: normal; -webkit-text-stroke-width: 0px;">java.lang.RuntimeException: java.io.IOException java.io.IOException null Invalid column name 'VALI, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) AS _GT_ROW_NUMBER DFROM'.</span></code></pre>

<p>I eventually discovered that the cause is having a field name containing the string "FROM". Specifically, I had</p>

<p><font size="2">...t3</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2">VALID_FROM </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">AS</font></font><font size="2"> VALIDFROM </font><font color="#808080" size="2"><font color="#808080" size="2">,</font></font><font size="2"> t3</font><font color="#808080" size="2"><font color="#808080" size="2">.</font></font><font size="2">VALID_TO </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">AS</font></font><font size="2"> VALIDTO</font><font color="#808080" size="2"><font color="#808080" size="2">,...</font></font></p>

<p>This suggests some pretty sloppy SQL parsing in GeoServer, and for the moment I've resolved this by changing my alias to VALID_STARTDATE.</p>
<br /><a href='https://www.esdm.co.uk/invalid-column-name-problem-with-geoserver-23-and-sql-server-views'>Crispin Flower</a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/invalid-column-name-problem-with-geoserver-23-and-sql-server-views'>...</a>]]></description>
      <link>https://www.esdm.co.uk/invalid-column-name-problem-with-geoserver-23-and-sql-server-views</link>
      <author>crispin.flower@idoxgroup.com (Crispin Flower)</author>
      <comments>https://www.esdm.co.uk/invalid-column-name-problem-with-geoserver-23-and-sql-server-views</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/invalid-column-name-problem-with-geoserver-23-and-sql-server-views</guid>
      <pubDate>Thu, 13 Jun 2013 16:01:00 GMT</pubDate>
    </item>
    <item>
      <title>Transferring user accounts from ASP.NET to MojoPortal</title>
      <description><![CDATA[<p>Occasionally we need to transfer user accounts from existing ASP.NET membership based sites into MojoPortal</p>

<p><strong>Note :</strong> if the databases are on the same server, or can be linked, then it is possible to take the SQL of the selects in the ExportASPNETUserData.bat file and use them to insert into the MojoPortal database tables. Using the .bat files will work wherever the databases are, as long as your PC can connect to both.<br />
If you can't connect to both, run the XMLFormat and Export scripts on a machine that can connect to the ASP.NET membership database, then copy the files and run the Import script on a machine that can connect to the MojoPortal database</p>

<p><strong>Note: </strong> It is possible to do the format/export/import in one script, but being able to sanity check the data before inserting is useful. You could also use staging tables to test the scripts before using the real MojoPortal tables</p>

<p><strong>Note: </strong> The switches set in each file are those I found were best for the LHaR data. Change them if you feel it is appropriate for you data. See: <a href="http://msdn.microsoft.com/en-gb/library/ms162802.aspx" target="_blank">BCP Utility Technical Reference</a></p>

<p>&nbsp;</p>

<h2>How-to</h2>

<ul>
	<li>Set MojoPortal to use plain text passwords</li>
	<li>Create a folder on your PC to contain the scripts</li>
	<li>In this folder, create the following .bat files:
	<ul>
		<li>CreateMojoUserTablesXMLFormats.bat</li>
		<li>ExportASPNETUserData.bat</li>
		<li>ImportMojoPortalUserData.bat</li>
	</ul>
	</li>
	<li>In this folder create the following subdirectories:
	<ul>
		<li>data</li>
		<li>formats</li>
		<li>output</li>
	</ul>
	</li>
	<li>Create and run the CreateMojoUserTablesXMLFormats.bat file</li>
	<li>Create and run the ExportASPNETUserData.bat file
	<ul>
		<li>Note: add as many user properties as required. To do this, select out each property in a separate select and then UNION the results together</li>
		<li>Check the output directory for any errors</li>
		<li>Check the data files have been created and contain the data you expect</li>
	</ul>
	</li>
	<li>Create and run the ImportMojoPortalUserData.bat
	<ul>
		<li>Check the output directory for any errors</li>
		<li>Check the database tables have the data</li>
	</ul>
	</li>
	<li>Switch MojoPortal back to using encrypted passwords</li>
	<li>Test a few logins</li>
</ul>

<p>&nbsp;</p>

<p>&nbsp;</p>

<h2>CreateMojoUserTablesXMLFormats.bat</h2>

<p>set login=-U <strong>[Username]</strong> -P <strong>[Password]</strong> -S <strong>[SQL Server Instance]</strong><br />
set database=<strong>[Databasename].[Schema].</strong><br />
set switches= -c -x<br />
set formatDir=<strong>[Full path to formats directory with trailing slash]</strong></p>

<p>bcp %database%mp_Users format nul %login% %switches% -f %formatDir%mojoUsers.xml<br />
bcp %database%mp_UserProperties format nul %login% %switches% -f %formatDir%mojoUserProperties.xml<br />
bcp %database%mp_userRoles format nul %login% %switches% -f %formatDir%mp_userRoles.xml</p>

<p>&nbsp;</p>

<h2>ExportASPNETUserData.bat file</h2>

<p>set login=-U <strong>[Username]</strong> -P <strong>[Password]</strong> -S <strong>[SQL Server Instance]</strong><br />
set dataDir=<strong>[Full path to data directory with trailing slash]</strong><br />
set database=<strong>[Databasename].[Schema].</strong><br />
set switches= -k -c</p>

<p>bcp "SELECT 0 AS UserID, 1 AS SiteID, aspnet_Users.Username AS Name, aspnet_Users.UserName AS LoginName, COALESCE (aspnet_Membership.Email,aspnet_Users.UserName + '@dummyemail.co.uk' ) AS Email, aspnet_Membership.LoweredEmail AS LoweredEmail, NULL AS PasswordQuestion, NULL AS PasswordAnswer, NULL AS Gender, aspnet_Membership.IsApproved AS ProfileApproved, NULL AS RegisterConfirmGUID, aspnet_Membership.IsApproved AS ApprovedForForums, 0 AS Trusted, CASE aspnet_Roles.RoleName WHEN 'xg' THEN 0 ELSE 1 END AS DisplayInMemberList, NULL AS WebsiteURL, NULL AS Country, NULL AS [State], NULL AS Occupation, NULL AS Interests, NULL AS MSN, NULL AS Yahoo, NULL AS AIM, NULL AS ICQ, 0 AS TotalPosts, NULL AS AvatarURL, 0 AS TimeOffsetHours, NULL AS [Signature], aspnet_Membership.CreateDate AS DateCreated, aspnet_Membership.UserId AS userGUID, NULL AS Skin, 0 AS IsDeleted, aspnet_Users.LastActivityDate AS LastActivityDate, aspnet_Membership.LastLoginDate AS LastLoginDate, NULL AS LastPasswordChangedDate, NULL AS LastLockoutDate, 0 AS FailedPasswordAttemptCount, NULL AS FailedPwdAttemptWindowStart, 0 AS FailedPwdAttemptCount, NULL AS FailedPwdAnswerWindowStart, aspnet_Membership.IsLockedOut AS IsLockedOut, NULL AS MobilePin, NULL AS PasswordSalt, NULL AS Comment, NULL AS OpenIDURI, NULL AS WindowsLiveID, '77C33D82-D6F0-49ED-95A7-84C11919AD94' AS SiteGUID, NULL AS TotalRevenue, userInfo.ForeName AS FirstName, userInfo.Surname AS LastName, aspnet_Users.Username as Pwd, 1 AS MustChangePassword, NULL AS NewEmail, NULL AS EditorPreference, '00000000-0000-0000-0000-000000000000' AS EmailChangeGuid, NULL AS TimeZoneID, '00000000-0000-0000-0000-000000000000' AS PasswordResetGuid FROM %database%aspnet_Membership INNER JOIN %database %aspnet_Users ON aspnet_Membership.UserId=aspnet_Users.UserId INNER JOIN %database%userInfo on aspnet_Membership.UserId=userInfo.userId INNER JOIN %database%aspnet_UsersInRoles ON aspnet_Membership.UserId=aspnet_UsersInRoles.UserId INNER JOIN %database%aspnet_Roles ON aspnet_UsersInRoles.RoleId = aspnet_Roles.RoleId" queryout %dataDir%lharUsers.txt %switches% %login% -o output/usersOutput.txt</p>

<p>bcp "select RoleName,UserId from %database%aspnet_Roles INNER JOIN %database%aspnet_UsersInRoles on aspnet_Roles.RoleId=aspnet_UsersInRoles.RoleId" queryout %dataDir%lharUsersRoles.txt %switches% %login% -o output/userRolesOutput.txt</p>

<p>bcp "SELECT newid() AS PropertyID, UserId AS userGUID, <strong>[String to use as MojoPortal PropertyName]</strong> AS PropertyName, Title AS PropertyValueString, NULL AS PropertyValueBinary, GETDATE() AS LastUpdatedDate, 0 AS IsLazyLoaded FROM %database%UserInfo<br />
<strong>UNION ALL</strong><br />
SELECT newid() AS PropertyID, UserId AS userGUID, <strong>[String to use as MojoPortal PropertyName]</strong> AS PropertyName, Title AS PropertyValueString, NULL AS PropertyValueBinary, GETDATE() AS LastUpdatedDate, 0 AS IsLazyLoaded FROM %database%UserInfo" queryout %dataDir%lharUserProfiles.txt %switches% %login% -o output/userPropertiesOutput.txt</p>

<p>&nbsp;</p>

<h2>ImportMojoPortalUserData.bat</h2>

<p>set login=-U <strong>[Username]</strong> -P <strong>[Password]</strong> -S <strong>[SQL Server Instance]</strong><br />
set database=<strong>[Databasename].[Schema].</strong><br />
set dataDir=<strong>[Full path to data directory with trailing slash]</strong><br />
set switches= -k -R<br />
set formatDir=<strong>[Full path to outputs directory with trailing slash]</strong></p>

<p>bcp %database%mp_users IN %dataDir%lharUsers.txt %login% %switches% -f %formatDir%mojoUsers.xml -o output/importUsers.txt<br />
bcp %database%mp_userProperties IN %dataDir%lharUserProfiles.txt %login% %switches% -f %formatDir%mojoUserProperties.xml -o output/importUserProperties.txt<br />
bcp %database%mp_userRoles IN %dataDir%lharUsersRoles.txt %login% %switches% -f %formatDir%mp_userRoles.xml -o output/importUserRoles.txt</p>
<br /><a href='https://www.esdm.co.uk/transferring-user-accounts-from-aspnet-to-mojoportal'></a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/transferring-user-accounts-from-aspnet-to-mojoportal'>...</a>]]></description>
      <link>https://www.esdm.co.uk/transferring-user-accounts-from-aspnet-to-mojoportal</link>
      <author>()</author>
      <comments>https://www.esdm.co.uk/transferring-user-accounts-from-aspnet-to-mojoportal</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/transferring-user-accounts-from-aspnet-to-mojoportal</guid>
      <pubDate>Mon, 04 Mar 2013 13:32:00 GMT</pubDate>
    </item>
    <item>
      <title>How to take a SQL Server backup without breaking the backup sequence</title>
      <description><![CDATA[<p>When a SQL Server is configured to run scheduled full backups followed by a sequence of differential backups, taking an <em>ad hoc</em> backup will affect how backups can be restored, potentially breaking the ability to restore to particular points in the sequence before the <em>ad hoc</em> backup was taken. If a backup file is required, for example as a simple way of copying the database to another server, the solution is to take a “copy-only” backup.</p> <p>This is achieved by ticking the “Copy-only Backup” checkbox, and setting an appropriate path for your backup file, as shown here in SQL Server 2008 Management Studio:</p> <p><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SQL Server copy-only backup" border="0" alt="SQL Server copy-only backup" src="https://www.esdm.co.uk/Data/Sites/1/media/wlw/image_25.png" width="535" height="480"></p> <p>It can also be achieved using command-line T-SQL.</p> <p>More information and <a title="explanation of copy-only backups from Microsoft" href="http://msdn.microsoft.com/en-us/library/ms191495.aspx" target="_blank">explanation here from Microsoft</a>.</p><br /><a href='https://www.esdm.co.uk/how-to-take-a-sql-server-backup-without-breaking-the-backup-sequence'>Crispin Flower</a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/how-to-take-a-sql-server-backup-without-breaking-the-backup-sequence'>...</a>]]></description>
      <link>https://www.esdm.co.uk/how-to-take-a-sql-server-backup-without-breaking-the-backup-sequence</link>
      <author>crispin.flower@idoxgroup.com (Crispin Flower)</author>
      <comments>https://www.esdm.co.uk/how-to-take-a-sql-server-backup-without-breaking-the-backup-sequence</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/how-to-take-a-sql-server-backup-without-breaking-the-backup-sequence</guid>
      <pubDate>Sat, 06 Oct 2012 19:00:30 GMT</pubDate>
    </item>
    <item>
      <title>How to drop all connections to a SQL Server database</title>
      <description><![CDATA[<p>
	Mike S-G has passed me this useful tool for dropping all connections from a database. This is required before deleting or re-naming databases, for example.</p>
<p>
	This creates a stored procedure in the “master” database, which can then be called to operate on any one database.</p>
<div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);">
	<div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">
<span style="color: rgb(0, 0, 255);">USE</span> [master]</pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
<span style="color: rgb(0, 0, 255);">GO</span></pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">
<span style="color: rgb(0, 128, 0);">/****** Object:  StoredProcedure [dbo].[usp_killprocess]    Script Date: 09/18/2012 14:55:47 ******/</span></pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
<span style="color: rgb(0, 0, 255);">SET</span> ANSI_NULLS <span style="color: rgb(0, 0, 255);">ON</span></pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">
<span style="color: rgb(0, 0, 255);">GO</span></pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
<span style="color: rgb(0, 0, 255);">SET</span> QUOTED_IDENTIFIER <span style="color: rgb(0, 0, 255);">ON</span></pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">
<span style="color: rgb(0, 0, 255);">GO</span></pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
 </pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">
<span style="color: rgb(0, 0, 255);">CREATE</span> <span style="color: rgb(0, 0, 255);">PROCEDURE</span> [dbo].[usp_killprocess] @dbname <span style="color: rgb(0, 0, 255);">VARCHAR</span>(128)</pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
<span style="color: rgb(0, 0, 255);">AS</span> </pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">
      <span style="color: rgb(0, 0, 255);">SET</span> nocount <span style="color: rgb(0, 0, 255);">ON</span></pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
      <span style="color: rgb(0, 0, 255);">SET</span> quoted_identifier <span style="color: rgb(0, 0, 255);">OFF</span></pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">
      <span style="color: rgb(0, 0, 255);">DECLARE</span> @kill_id <span style="color: rgb(0, 0, 255);">INT</span></pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
      <span style="color: rgb(0, 0, 255);">DECLARE</span> @query <span style="color: rgb(0, 0, 255);">VARCHAR</span>(320)</pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">
      <span style="color: rgb(0, 0, 255);">DECLARE</span> killprocess_cursor <span style="color: rgb(0, 0, 255);">CURSOR</span></pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
      <span style="color: rgb(0, 0, 255);">FOR</span></pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">
              <span style="color: rgb(0, 0, 255);">SELECT</span>    a.spid</pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(0, 0, 255);">FROM</span>      sysprocesses a</pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">
                        <span style="color: rgb(0, 0, 255);">JOIN</span> sysdatabases b <span style="color: rgb(0, 0, 255);">ON</span> a.dbid = b.dbid</pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(0, 0, 255);">WHERE</span>     b.name = @dbname</pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">
 </pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
      <span style="color: rgb(0, 0, 255);">OPEN</span> killprocess_cursor</pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">
      <span style="color: rgb(0, 0, 255);">FETCH</span> <span style="color: rgb(0, 0, 255);">NEXT</span> <span style="color: rgb(0, 0, 255);">FROM</span> killprocess_cursor <span style="color: rgb(0, 0, 255);">INTO</span> @kill_id</pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
      <span style="color: rgb(0, 0, 255);">WHILE</span> ( <span style="color: rgb(204, 102, 51);">@@fetch_status</span> = 0 ) </pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">
            <span style="color: rgb(0, 0, 255);">BEGIN</span></pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
                  <span style="color: rgb(0, 0, 255);">SET</span> @query = <span style="color: rgb(0, 96, 128);">'kill '</span> + <span style="color: rgb(0, 0, 255);">CONVERT</span>(<span style="color: rgb(0, 0, 255);">VARCHAR</span>, @kill_id)</pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">
                  <span style="color: rgb(0, 0, 255);">EXEC</span> (@query)</pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
                  <span style="color: rgb(0, 0, 255);">FETCH</span> <span style="color: rgb(0, 0, 255);">NEXT</span> <span style="color: rgb(0, 0, 255);">FROM</span> killprocess_cursor <span style="color: rgb(0, 0, 255);">INTO</span> @kill_id</pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">
            <span style="color: rgb(0, 0, 255);">END</span></pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
      <span style="color: rgb(0, 0, 255);">CLOSE</span> killprocess_cursor</pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">
      <span style="color: rgb(0, 0, 255);">DEALLOCATE</span> killprocess_cursor</pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
 </pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;">
--<span style="color: rgb(0, 0, 255);">usage</span></pre>
		<!--CRLF-->
		<pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
--<span style="color: rgb(0, 0, 255);">exec</span> usp_killprocess "mydatabasename" </pre>
		<!--CRLF--></div>
</div>
<p>
	Example usage:</p>
<p>
	usp_killprocess&nbsp; myDatabaseName</p>
<br /><a href='https://www.esdm.co.uk/how-to-drop-all-connections-to-a-sql-server-database'>Crispin Flower</a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/how-to-drop-all-connections-to-a-sql-server-database'>...</a>]]></description>
      <link>https://www.esdm.co.uk/how-to-drop-all-connections-to-a-sql-server-database</link>
      <author>crispin.flower@idoxgroup.com (Crispin Flower)</author>
      <comments>https://www.esdm.co.uk/how-to-drop-all-connections-to-a-sql-server-database</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/how-to-drop-all-connections-to-a-sql-server-database</guid>
      <pubDate>Tue, 18 Sep 2012 14:05:00 GMT</pubDate>
    </item>
    <item>
      <title>Multiple SQL Server log-in failures caused by connection string error - HBSMRv3</title>
      <description><![CDATA[<p>
	A SQL Server DBA reported many login failures in his SQL logs - variously quoted as “hundreds per day” and “50+ in a minute”. These failures were not apparent to system users. Two user communities were accessing this data - one using trusted connections the other using SQL Server Authentication. Only the Trusted Connection group were affected by this issue. The connection string included the clause &lt;Trusted_Connections=Yes&gt;, this should have been &lt;Trusted_Connection=Yes&gt;. Once the connection string had been corrected the log-in failures stopped.</p>
<p>
	Example of repeated log-in failures from SQL logs:</p>
<p>
	2012-04-18 09:19:44.50 Logon&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Login failed for user 'smruser'. [CLIENT: 159.15.250.xxx]<br />
	2012-04-18 09:19:44.53 Logon&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Error: 18456, Severity: 14, State: 5.<br />
	2012-04-18 09:19:44.53 Logon&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Login failed for user ‘yyyy.xxxx’. [CLIENT: 159.15.250.xxx]<br />
	2012-04-18 09:19:44.54 Logon&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Error: 18456, Severity: 14, State: 5.<br />
	2012-04-18 09:19:44.54 Logon&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Login failed for user 'smruser'. [CLIENT: 159.15.250.xxx]<br />
	2012-04-18 09:19:46.87 Logon&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Error: 18456, Severity: 14, State: 5.<br />
	2012-04-18 09:19:46.87 Logon&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Login failed for user ‘zzzz.yyyy’. [CLIENT: 159.15.250.xxxx]<br />
	2012-04-18 09:19:46.90 Logon&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Error: 18456, Severity: 14, State: 5.</p>
<br /><a href='https://www.esdm.co.uk/multiple-sql-server-log-in-failures-caused-by-connection-string-error-hbsmrv3'></a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/multiple-sql-server-log-in-failures-caused-by-connection-string-error-hbsmrv3'>...</a>]]></description>
      <link>https://www.esdm.co.uk/multiple-sql-server-log-in-failures-caused-by-connection-string-error-hbsmrv3</link>
      <author>()</author>
      <comments>https://www.esdm.co.uk/multiple-sql-server-log-in-failures-caused-by-connection-string-error-hbsmrv3</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/multiple-sql-server-log-in-failures-caused-by-connection-string-error-hbsmrv3</guid>
      <pubDate>Mon, 23 Apr 2012 08:28:00 GMT</pubDate>
    </item>
    <item>
      <title>Accessing SQL Server 2008 Express (on Win 7 OS) over the network</title>
      <description><![CDATA[<p>
	I hit a problem where I needed to enable network access to SQL Server 2008 Express R2 which was on a Win7 64bit OS. the solution was previously posted at: <a href="http://www.sevenforums.com/system-security/58817-remote-access-sql-server-express-2008-windows-7-a.html">http://www.sevenforums.com/system-security/58817-remote-access-sql-server-express-2008-windows-7-a.html</a></p>
<p>
	&nbsp;</p>
<p>
	Here are some step by step details for getting this to work:</p>
<p>
	<br />
	1) <a href="http://www.linglom.com/2009/03/28/enable-remote-connection-on-sql-server-2008-express/"><font color="#000000">Enable remote connections to Sql Server</font></a><font color="#000000">. (SSMS, connect to DB, right-click and select properties and then Connections…make sure remote conenctions chkBox is ticked).</font></p>
<p>
	2) <a href="http://www.dummies.com/how-to/content/how-to-open-a-port-in-the-windows-7-firewall.html">Set up Inbound and Outbound rules for TCP port 1433</a><br />
	<br />
	3) <a href="http://www.dummies.com/how-to/content/how-to-open-a-port-in-the-windows-7-firewall.html">Set up Inbound and Outbound rules for UDP port 1434</a><br />
	<br />
	4)<a href="http://www.sevenforums.com/tutorials/542-windows-firewall-add-remove-exception.html"> Set up inbound and outbound exceptions for sqlservr.exe</a>. I am running a 64 bit machine so this file was located here: C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\Binn\sqlservr.exe<br />
	<br />
	5) <a href="http://www.sevenforums.com/tutorials/542-windows-firewall-add-remove-exception.html">Set up inbound and outbound exceptions for sqlbrowser.exe</a>. Again, I am running a 64 bit machine so the file was located here: C:\Program Files (x86)\Microsoft SQL Server\90\Shared\sqlbrowser.exe</p>
<p>
	&nbsp;</p>
<p>
	And thats it.</p>
<br /><a href='https://www.esdm.co.uk/accessing-sql-server-2008-express-on-win-7-os-over-the-network'>Laine Skinner</a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/accessing-sql-server-2008-express-on-win-7-os-over-the-network'>...</a>]]></description>
      <link>https://www.esdm.co.uk/accessing-sql-server-2008-express-on-win-7-os-over-the-network</link>
      <author>laines@esdm.co.uk (Laine Skinner)</author>
      <comments>https://www.esdm.co.uk/accessing-sql-server-2008-express-on-win-7-os-over-the-network</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/accessing-sql-server-2008-express-on-win-7-os-over-the-network</guid>
      <pubDate>Wed, 21 Mar 2012 15:47:00 GMT</pubDate>
    </item>
    <item>
      <title>Calculating the extent of the geometry in a SQL Server table</title>
      <description><![CDATA[<p>Andy Brewer passed me this, adapted from <a href="http://barendgehrels.blogspot.co.uk/2011/04/extent-of-sql-server-spatial-table.html">http://barendgehrels.blogspot.co.uk/2011/04/extent-of-sql-server-spatial-table.html</a> <p>This is a useful script, using CTEs (common table expressions) to calculate the extent of the geometry in a SQL Server table. Replace “geom” with the name of your geometry column and “MyTable” with the name of your table. <p>Note that this script depends on STEnvelope returning a rectangular extent with its first point at the SW corner and its third in the NE corner. Tests from the author of the blog above confirm the SQL Server currently does this.<pre>with
  cte_envelope as
  (
    select geom.STEnvelope() as envelope from MyTable
  ),
  cte_corner as
  (
    select envelope.STPointN(1) as point from cte_envelope
    union all
    select envelope.STPointN(3) from cte_envelope
  )
select min(point.STX) as min_x, min(point.STY) as min_y, max(point.STX) as max_x, max(point.STY) as max_y
from cte_corner</pre><br /><a href='https://www.esdm.co.uk/calculating-the-extent-of-the-geometry-in-a-sql-server-table'>Crispin Flower</a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/calculating-the-extent-of-the-geometry-in-a-sql-server-table'>...</a>]]></description>
      <link>https://www.esdm.co.uk/calculating-the-extent-of-the-geometry-in-a-sql-server-table</link>
      <author>crispin.flower@idoxgroup.com (Crispin Flower)</author>
      <comments>https://www.esdm.co.uk/calculating-the-extent-of-the-geometry-in-a-sql-server-table</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/calculating-the-extent-of-the-geometry-in-a-sql-server-table</guid>
      <pubDate>Tue, 20 Mar 2012 19:18:00 GMT</pubDate>
    </item>
  </channel>
</rss>