I installed SQL Server 2014, but from within Visual Studio 2013 I could not connect to the newly installed instance.

 

image

 

 

image

 

 

This was caused by the missing Microsoft Visual Studio update: “Microsoft SQL Server 2014 Update for database tooling”:

 

 

image

 

After installing the update, I was able to connect to a SQL Server 2014 instance from within Microsoft Visual Studio 2013.

 

image

After the installation of SQL Server 2014 was almost completed on a Windows 8.1 workstation, I got the error: "Could not find the Database Engine startup handle".

 

This was caused by the fact, that I used all standard settings during installation. When you choose all to install SQL Server 2014 with all default options, the SQL Server windows service will run under the NT Service\MSSQL$V2014 account, after changing this login to a correct login (a local admin account on the box) the service started correctly and I could login to the SQL Server 2014 instance.

 

image

Tags: ,

Roel van Lisdonk on April 3rd, 2014

Be aware, that dates with different daylight saving times, don’t differ by 24 hours per day, but 24 * days + 1 hour or 24 * days – 1 hour:

 

var app = (function ()
{
    var self = this;

    // The "main" entry point for this application.
    self.start = function ()
    {
        console.log("Document ready!");
        self.daylightSavingsTest();
    };

    self.daylightSavingsTest = function ()
    {
        // Notes (in the netherlands):
        // "Winter time" refers to "standard time".
        // "Summer time" refers to "standard time" + 1 hour.
        // Time changes at sunday [2014-03-30: 02:00:00.000]. Changes to [2014-03-30: 03:00:00.000]. 
        
        
        var d1 = new Date(2014, 1, 1, 0, 0, 0, 0); // '2014-02-01: 00:00:00.000';
        var d2 = new Date(2014, 1, 3, 0, 0, 0, 0); // '2014-02-03: 00:00:00.000';

        // [getTime()], returns the number of milliseconds since [1970-01-01 00:00:00] (winter / standard time).
        var t1 = d1.getTime();
        var t2 = d2.getTime();

        // When all daylight saving times of 2 dates are the same, 
        // you can calculate the difference in days between 2 dates with parseInt((t2 - t1) / (24 * 60 * 60 * 1000)):
        var days = parseInt((t2 - t1) / (24 * 60 * 60 * 1000));
        console.log(days); // Outputs: 2

        // When all daylight saving times of 2 dates are NOT the same, 
        // you can't calculate the difference in days between 2 dates with parseInt((t2 - t1) / (24 * 60 * 60 * 1000)):
        d1 = new Date(2014, 2, 30, 0, 0, 0, 0); // '2014-03-30: 00:00:00.000';
        d2 = new Date(2014, 3, 1, 0, 0, 0, 0);  // '2014-04-01: 00:00:00.000';
        t1 = d1.getTime();
        t2 = d2.getTime();
        days = parseInt((t2 - t1) / (24 * 60 * 60 * 1000));
        console.log(days); // Outputs: 1

        // You can fix this by using Math.round:
        days = Math.round((t2 - t1) / (24 * 60 * 60 * 1000));
        console.log(days); // Outputs: 2


        // Or just use moment.js!!!!

    };

    return self;
})();

// Start the application.
app.start();

 

image

Tags:

The following code will update a column to varchar(max) only, when it does not already have the varchar(max) length.

-- Update column 'Name' length, it should be varchar(max).
-- Note: varchar(max) has length '-1'.
if (    
        (
            select character_maximum_length
            from information_schema.columns
            where table_name=object_name(object_id('dbo.Table1'))
            and COLUMN_NAME = 'Name'
        ) <> -1
    )
begin
    alter table dbo.Table1 alter column Name varchar(max) not null
end

Tags:

Roel van Lisdonk on March 27th, 2014

If you want to know the amount of elapsed minutes in the current quarter, you can use the following T-SQL code:

declare @CurrentDateTime datetime = '2014-03-27 10:56:10'
declare @MinutesPassedInHour int = convert(int, datepart(minute, @CurrentDateTime))
declare @quarterCount int = @MinutesPassedInHour / 15
declare @MinutesPassedInQuarter int = (@MinutesPassedInHour - (@quarterCount * 15))
select @MinutesPassedInQuarter

-- Result: 11

Tags:

Roel van Lisdonk on March 26th, 2014

If you want to clear the appCache for a site in Google Chrome, browse to:

chrome://appcache-internals

 

image

 

Then click on the remove button for the specific site.

When mapping a collection to a local folder in Microsoft Visual Studio 2013, I was getting the error:

The working folder … is already in use by the workspace … on computer …

 

image

 

To solve this problem I had to delete the workspace:

  1. Close Microsoft Visual Studio 2013.
  2. Open en command prompt in Administrator mode.
  3. cd "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE"
  4. tf workspace /delete /server:http://1.1.1.1:8080/tfs/MyCollection MyComputerName;MyDomain\MyUserName
  5. Open Microsoft Visual Studio 2013. Mapping to local folder should now work.

 

For more information:

http://blogs.msdn.com/b/rob/archive/2012/10/13/solved-the-working-folder-source-path-is-already-in-use-by-the-workspace-workspace-name-owner-on-computer-tfs-server.aspx

http://stackoverflow.com/questions/8435135/change-computer-name-for-a-tfs-workspace

 

To list all workspace use:

tf workspaces /owner:* /computer:* /server:http://1.1.1.1:8080/tfs/MyCollection

Tags:

Roel van Lisdonk on March 24th, 2014

In production we use Application Cache, to distribute a new version of a Single Page Application.

In development I immediately want to see my CSS, JavaScript and HTML code changes, without changing the “*.appcache” on every save. This is why I disable de Application Cache in development by “not serving” the “*.appcache” file:

<system.webServer>
    <staticContent>
      <remove fileExtension=".woff" />
      <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
      <mimeMap fileExtension=".appcache" mimeType="text/cache-manifest" />
      <!-- To disable appCache during development, comment line above and uncomment line below. -->
      <!--<mimeMap fileExtension=".wrongAppcache" mimeType="text/cache-manifest" />-->
    </staticContent>

Tags: ,

 

 

When the user clicks on the "Execute" button for the first time, the data will be retrieved from a REST service.

The second time the data will be retrieved from the cache.

 

The comments in the code will explain, how the we can return a manual promise, when data is retrieved from cache and a Ajax promise, when the data is retrieved from a REST service.

 

<!DOCTYPE html>
<html>
<head>
    <title>Research page for jQuery.</title>
    <style type="text/css">
    
    </style>
</head>
<body>
    <div id="page">
        <button id="executeButton" type="button">Execute</button>
</div>
    <script type="text/javascript" src="../../Libraries/jQuery/jquery-1.10.2.min.js"></script>
    <script type="text/javascript">
        "use strict";


        var cacheFactory = (function ()
        {
            var CacheComponent = function ()
            {
                var self = this;
                var _cache = {};

                // Returns a promise.
                // De ".done" function of this promise can be used to get to the data.
                self.getItem = function (key)
                {
                    // Check if key exists in de cache.
                    if (_cache.hasOwnProperty(key))
                    {
                        // Get value from cache.
                        var value = _cache[key];

                        // Create a manual promise.
                        var deferred = $.Deferred();

                        // Imediatly set the manual promise to "completed", any done functions added to the resulting promise, will be called immediately.
                        deferred.resolve(value);

                        // Data in cache, so return a manual promise.
                        return deferred.promise();
                    }
                    else
                    {
                        // No data in cache, so return ajax promise.
                        return $.ajax({
                            url: key,
                            type: "GET"
                        }).done(function (data)
                        {
                            // Put the data from the service in the cache and for the purpose of demonstration add some text, 
                            // to show the difference between data from the service and data from the cache.
                            _cache[key] = data + " Data from cache!";
                        });
                    }
                };
            };

            var _factory = {};
            _factory.create = function ()
            {
                // Create a new cache object.
                return new CacheComponent();
            };

            return _factory;
        })();



        var app = (function ()
        {
            var self = {};
            var _serviceUrl = "/Api/Service";

            // Create a new cache object by calling the "create" function on the "cacheFactory".
            var _serviceCache = cacheFactory.create();
            
            // Click eventhandler.
            self.handleExecuteButtonClick = function (event)
            {
                
                _serviceCache
                    .getItem(_serviceUrl) // Get data.
                    .done(function (data)
                    {
                        // Show data.
                        console.log(data);
                    });
            };

            // Fires when the application starts.
            self.start = function ()
            {
                console.log("Document ready!");

                // Wire up a "click" evenhandler.
                var $executeButton = $("#executeButton");
                $executeButton.on("click", self.handleExecuteButtonClick);
            };

            return self;
        })();

        // Start the application.
        app.start();

    </script>
</body>
</html>

 

 

 

The Web API 2 routes used:

image

 

The Web API 2 controller:

image

 

Result

 

image

Tags:

Roel van Lisdonk on January 31st, 2014

When I want to load a html fragment I prefer the contents of the container div in the page and the HTML fragment to have the same ID, like:

 

Master page

<!DOCTYPE html>
<html>
<head>
    <title>Master page</title>
</head>
<body>
    <!--Placeholder container. -->
    <div id="page"></div>
</body>
</html>

Page (html fragment)

<!DOCTYPE html>
<html>
<head>
    <title>Page (html fragment)</title>
</head>
<body>
    <!-- Page (html fragment to load). -->
    <div id="page"></div>
</body>
</html>

 

Then the following code can be used to replace the contents of the "placeholder" div, by the contents of the ”html fragment" div:

 

Code

// Loads a html fragment.
// It replaces the content of the given DOM element, with the html fragment contents.
// It expects both the current page and the html fragment to contain the same "id" as the given id.
//
// Parameters:
// [id] example ["#page"].
// [url] example ["Features/Login/LoginView.html"].
function loadHtmlFragment (id, url)
{
    // Use jQuery "ajax" instead of jQuery "load", because "load" will get the whole div, 
    // when used with selector "#page" and not the contents.
    // You can get only the contents with "load", by using "url #page > *", 
    // but that will only get the child elements of the div, 
    // stripping out any direct child text.
    $.ajax({
        url: url,
        type: 'GET',
        dataType: "html",
        success: function (data)
        {
            // Strip out any javascript by using "parseHtml".
            // Only use the contents of the html fragment by using "html()".
            var dom = $("<div>").append($.parseHTML(data)).find(id).html();

            // Adjust UI.
            $(id).html(dom);
        }
    });
};

Tags: