Filter Diagnostic Trace Using Configuration

I often have situations when I want to have different levels of diagnostic trace in different environments, and want to configure this in web.config or app.config. Here is an example of how to do it. This example traces to the eventlog with information, warning and error levels.

  <system.diagnostics>
    <trace autoflush="true" indentsize="0">
      <listeners>
        <add initializeData="MyEventSource" type="System.Diagnostics.EventLogTraceListener" name="MyEventListener">
          <filter type="System.Diagnostics.EventTypeFilter" initializeData="Information" />
        </add>
      </listeners>
    </trace>
  </system.diagnostics>
Posted in Uncategorized | Leave a comment

Automatically Shut Down an Azure VM

Here is a self-documenting (I hope) PowerShell script. Windows Azure PowerShell is required.

Import-Module "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1"
# Importing publish settings only has to be done once.
# Download from <a href="https://windows.azure.com/download/publishprofile.aspx">https://windows.azure.com/download/publishprofile.aspx</a>
# Then, run the following line:
# Import-AzurePublishSettingsFile "Path\File.publishsettings"
# Test:
Get-AzureVM -ServiceName "MyService" > C:\Users\user\Documents\StopLog.txt 2>&1
# Stop the VM:
Stop-AzureVM -Name "MyName" -ServiceName "MyService" -Force >> C:\Users\user\Documents\StopLog.txt 2>&1
# Schedule a task (using Task Scheduler) with
# Action: Start a program
# Program/script: powershell.exe
# Parameters: C:\Users\user\Documents\StopVM.ps1
Posted in Computers and Internet | Tagged | Leave a comment

Deploying to SQL Server Analysis Services (SSAS) using PowerShell

My previous post was about configuring http access to SSAS. Here is a way to deploy a SSAS project using script (PowerShell) via http.

First, create a project configuration. I called mine “Test”. Then, edit the “.deploymenttargets” file located in the project configuration folder in the bin folder (MyProject\bin\Test in my case). Edit the server parameter to e.g.

https://myserver.cloudapp.net/OLAP/msmdpump.dll

Then, create a deployment script using the deployment utility:

“C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Microsoft.AnalysisServices.Deployment” MyProject\bin\Test\Model.asdatabase /s:ScriptLog.txt /o:Model.xmla /d

Then, deploy using the new PowerShell commandlets:

$credential = Get-Credential domain\user
Invoke-ASCmd -InputFile $fspath\Model.xmla -Server https://myserver.cloudapp.net/OLAP/msmdpump.dll -Credential $credential

Here is the entire script:

$fspath = (Get-Location).Path
Write-Host "Generating deployment script..."
& "C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Microsoft.AnalysisServices.Deployment" MyProjct\bin\Test\Model.asdatabase /s:ScriptLog.txt /o:Model.xmla /d
Start-Process $fspath\ScriptLog.txt
Write-Host "Importing SQL modules..."
Import-Module SQLPS -disablenamechecking
Import-Module sqlascmdlets
Write-Host "Invoking deployment script... This may take several minutes or even hours."
$credential = Get-Credential domain\user
Invoke-ASCmd -InputFile $fspath\Model.xmla -Server https://myserver.cloudapp.net/OLAP/msmdpump.dll -Credential $credential | Out-File $fspath\Result.xml
Start-Process $fspath\Result.xml
Write-Host "Done."
Posted in Uncategorized | Leave a comment

Accessing SQL Server Analysis Services via HTTP

I have set up HTTP access to SQL Server Analysis Server a couple of times. It is well documented here: http://technet.microsoft.com/en-us/library/gg492140.aspx

But each time, I seem to encounter the following error when I try to add the script map: “The specified module required by this handler is not in the modules list. If you are adding a script map handler mapping, the IsapiModule or the CgiModule must be in the modules list.”

image

Here is how to solve this: In Windows Server 2012, add the ISAPI Extension feature using the Add Roles and Features Wizard (which is accessible from Server Manager):

image

Posted in Computers and Internet | Tagged , , | 1 Comment

ASP.NET MVC Multiple Check-boxes

http://www.shawnmclean.com/blog/2011/04/asp-net-mvc-multiple-check-boxes-in-an-array-or-list/

Posted in Uncategorized | Leave a comment

ASP.NET MVC Date Validation

I had the following property in my view model:

        [Required(ErrorMessage = "Du måste fylla i från-datum och -tid")]
        public DateTime? From { get; set; }

When I entered “2014-01-01 00:00:00” I got the following validation error: “The field From must be a date.” So, it the built in validation somehow assumes a date without time.

My next attempt was to add a another attribute:

        [DataType(DataType.DateTime)]

This had no effect. My third attempt was to use a regular expression. I defined a new attribute that inherits RegularExpressionAttribute:

    public class DateTimeValidationAttribute : RegularExpressionAttribute
    {
        public DateTimeValidationAttribute()
            : base(@"^((20\d{2})-((0[1-9])|(1[0-2]))-(0[1-9]|1\d|2[0-8])|((20\d{2})-(((0[1,3-9]|1[0-2])-((29|30)))|((0[13578]|1[02])-31)))|(((20(([02468][048])|([13579][26]))))-02-29)) (([0-1]\d)|(2[0-3])):[0-5]\d$")
        {
            ErrorMessage = "Fyll i datum och tid på formatet YYYY-MM-DD HH:mm";
        }
    }

This had no effect either! Still the same validation error. I concluded my validation is not run, maybe because the property is of type DateTime. I changed this to string. This, time I got no client side validation, but at least I got correct server side validation. My last attempt was to skip DataTimeValidationAttribute and use RegularExpressionAttribute directly.

        [Required(ErrorMessage = "Du måste fylla i från-datum och -tid")]
        [DataType(DataType.DateTime)]
        [RegularExpression(DateTimeRegExp, ErrorMessage = DateTimeError)]
        public string From { get; set; }

This was the only solution that worked for me.

Posted in Uncategorized | Tagged , , , | Leave a comment

Error “The connection string is not valid” after upgrading to .slqproj

Today I upgraded a couple of projects from .dbproj to .sqlproj using Visual Studio 2010.

First problem: One of the new projects did not build, saying it lacked master.dacpac. So I had to copy that file from “C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\SQLDB\Extensions\SqlServer\100\SQLSchemas” to the “Master DB reference” folder within my project folder.

Second problem: When I checked in and the project was built using TFS/MSBuild, I got this error:

…\Binaries\Release\MyProjct.sql: The connection string is not valid

I didn’t want to publish directly to the database, because there is no network connection between our build server and the test server, but how do you turn that off? Unchecking Deploy for the project using solution configuration manager did not help.  After some binging, I found a clue. I opened up the project file using a text editor and changed

<Project DefaultTargets="Build;Deploy" xmlns="<a href="http://schemas.microsoft.com/developer/msbuild/2003">http://schemas.microsoft.com/developer/msbuild/2003</a>" ToolsVersion="4.0">

to

<Project DefaultTargets="Build" xmlns="<a href="http://schemas.microsoft.com/developer/msbuild/2003">http://schemas.microsoft.com/developer/msbuild/2003</a>" ToolsVersion="4.0">

That works. A file called MyProject_Create.sql is generated and I use that for deployment to the test server, where our application is reinstalled from scratch every night.

Posted in Uncategorized | Tagged , , , , | Leave a comment