Using the SSDT and SSDT Power Tools in Microsoft Visual Studio 2010

If you are developing an application that has a SQL Server database as backend, then during development you probably will have Microsoft Visual Studio 2010 and Microsoft SQL Server Management Studio open. The free SSDT Power Tools Microsoft Visual Studio 2010 extension enables me to do most of the tasks I did using Microsoft SQL Server Management Studio by using the SQL Server Object Explorer in Microsoft Visual Studio 2010.

First make sure the SQL Server Data Tools are installed: http://msdn.microsoft.com/en-us/data/hh297027 

To install the SSDT Power Tools, open Microsoft Visual Studio 2010 > Tools > Extension Manager > Online Gallery

 

image

 

This includes showing execution plans:

 

image

Managing Server logins and Database users:

image

 

Executing, debugging and showing the code of stored procedures on my SQL Server LocalDb instance:

image

Shifting to express products like Microsoft IIS Express 8 and Microsoft SQL Server 2012 LocalDb for development.

Most express products have some things in common:

– Contain the same features as the full product (except for some limitations like, no more then 4GB memory or no more then 10 users etc.)

– Free of charge

– Lightweight

– User profile specific (multiple users on one machine have independent product configuration and processes)

These products are created mainly for development purposes.

 

Advantages

More and more I am shifting to these express products for the O in OTAP and for the build servers, because these products have the following advantages:

– Free of charge.

– No configuration.

– Fast and lightweight installation.

– Performance improvements for DEV en build server machines.

– Build servers can use clean instances to run integration tests.

– Easily to restore to new instance.
When a per user instance is corrupted it’s very easy to restore it.

Multiple users can work on one virtual machine, without interfering with each other.
So each developer can change all the things he or she wants to research some new code, without breaking a shared instance of IIS or SQL Server.

 

Of course for the T, the A and P in OTAP, I use the full products.

How to dynamically switch between IIS Express and full IIS in Microsoft Visual Studio 2010 by using a csproj.user file.

If you want to give every developer the choice to use IIS Express or full IIS during development in Microsoft Visual Studio 2010 sp1, you can use a csproj.user file for you project. This file can be used to overwrite settings in the *.csproj file.

This file will by default not be added to TFS, so every developer can use it’s own configuration, without interfering with other developers.

First uncheck "Apply server settings to all users (store in project file)"

Then check "Use IIS Express" on the Web tab from the Microsoft Visual Studio 2010 sp1 project.

image

 

Change the generated *.csproj.user, like:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ShowAllFiles</ProjectView>
<UseIISExpress>true</UseIISExpress>
</PropertyGroup>
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<StartPageUrl>Default.aspx</StartPageUrl>
<StartAction>SpecificPage</StartAction>
<AspNetDebugging>True</AspNetDebugging>
<SilverlightDebugging>False</SilverlightDebugging>
<NativeDebugging>False</NativeDebugging>
<SQLDebugging>False</SQLDebugging>
<ExternalProgram>
</ExternalProgram>
<StartExternalURL>
</StartExternalURL>
<StartCmdLineArguments>
</StartCmdLineArguments>
<StartWorkingDirectory>
</StartWorkingDirectory>
<EnableENC>False</EnableENC>
<AlwaysStartWebServerOnDebug>True</AlwaysStartWebServerOnDebug>
<UseIIS>True</UseIIS>
<AutoAssignPort>False</AutoAssignPort>
<DevelopmentServerPort>1000</DevelopmentServerPort>
<DevelopmentServerVPath>/Test</DevelopmentServerVPath>
<IISUrl>http://localhost:1000/Test</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
</CustomServerUrl>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
</Project>

Now your build server can use the settings in the csproj file and you, as a developer, have the choice to use these settings or overwrite them with the *.csproj.user file.

Simplest way to add forms authentication to you Web.config in ASP .NET, when using AspNetSqlMembershipProvider

If you’ve got a website and this website contains a Login.aspx and a Default.aspx page in the root.

The simplest way to deny all unauthenticated user access to the website is adding the following to you’re Web.config:

 <system.web>
<authentication mode="Forms">
<forms loginUrl="Login.aspx"
protection="All"
timeout="30"
name=".ASPXAUTH"
path="/"
requireSSL="false"
slidingExpiration="true"
defaultUrl="Default.aspx"
cookieless="UseDeviceProfile"
enableCrossAppRedirects="false" />
</authentication>
<authorization>
<deny users="?" />
</authorization>
<membership>
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
</system.web>

 

This ensures that unauthenticated user can only access the Login.aspx and no other resources, accept the resources needed by the Login.aspx. So if the Login.aspx uses a /Images/Logo.png this images will show on the Login.aspx. Accessing the image directly by an unauthenticated user will redirect this user back to the Login.aspx page.

How to delete and reseed all data in a SQL Server database

If you want to delete all data in a SQL Server database and reseed the tables that contain a identity column, you can use the following code:

exec sp_msforeachtable "alter table ? nocheck constraint all";
exec sp_msforeachtable "delete from ?";
exec sp_msforeachtable "if exists(select 1 from sys.identity_columns where object_name(object_id) = '?') begin dbcc checkident ( '?', reseed, 0) end";
exec sp_msforeachtable "alter table ? with check check constraint all";

Solution for: Microsoft Lync keeps asking me to sign in after update

After some updates today Microsoft Lync kept on asking me  to sing in. If I canceled the dialog an Exchange server error was displayed:

Error

Lync cannot connect to the Exchange server. To restore this connection, please try signing out and signing back in. Until the connection is restored, history, voice mail and Outlook-related features will be unavailable.

 

 

image

 

image

 

Solution

After the update the system clock was set to the wrong time. Restoring the system time to the correct time and restarting Microsoft Lync en Microsoft Outlook the problem was resolved.

How to do JavaScript unit testing from C# with MSTest and JSTest

I wanted to run regular MSTest unit test written in C# to assert JavaScript code. There are several ways to accomplish this, but in this case I use JSTest.

Just add JSTest to your C# testproject with NuGet, now you can write tests like:

 

Test class

using JSTest;
using JSTest.ScriptLibraries;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestProject1.Helpers;
namespace TestProject1
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
var script = new TestScript();
// Arrange: Append the JavaScript code to test.
string scriptContents = (new AssemblyHelper().GetContentsEmbededResourceFile("TestProject1.MvcApplication1.Scripts.Person.js"));
script.AppendBlock(scriptContents);
// Arrange: Append the JSTest asser library, so we can assert the test code.
script.AppendBlock(new JsAssertLibrary());
// Append "Act" JavaScript code.
script.AppendBlock("var person1 = new Person('John Do', 32, 'Software Engineer');");
// Assert.
script.RunTest(@"assert.equal('Jonh Do test', person1.sayName());");
}
}
}

Running this test within Microsoft Visual Studio 2010 will result in a passed test.

 

JavaScript code to test

function Person(name, age, job)
{
var privateField1 = 'test';
this.name = name;
this.age = age;
this.job = job;
this.privilegedMethod = function () { return privateField1; }
};
Person.prototype.sayName = function ()
{
return this.name + ' ' + this.privilegedMethod();
};

Notes

– The privilegedMethod is used to access private fields on the Person class.

– You can set breakpoints in the JavaScript code!!

C# helper class

using System;
using System.IO;
using System.Reflection;
namespace TestProject1.Helpers
{
public class AssemblyHelper
{
/// <summary>
/// Read the contents of an embededresourcefile with the given name.
/// </summary>
/// <param name="resourceName">Name of the resource.</param>
/// <returns></returns>
public string GetContentsEmbededResourceFile(string resourceName)
{
if (string.IsNullOrWhiteSpace(resourceName)) { throw new ArgumentNullException("resourceName"); }
string contents = string.Empty;
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
using (var reader = new StreamReader(stream))
{
contents = reader.ReadToEnd();
}
return contents;
}
}
}

Microsoft Visual Studio 2010

image