Wednesday, May 16, 2012

Javascript - Revealing Module pattern

Over the last couple of months I have grown to love structuring my JavaScript code using the "Revealing Module" pattern. I love the fact that it promotes the use of OO concepts in JS. With VS2011 adding more intellisense support to JS, it makes the use of this pattern so much better. Read more about it on Dan Wahlin's blog - http://weblogs.asp.net/dwahlin/archive/2011/08/02/techniques-strategies-and-patterns-for-structuring-javascript-code-revealing-module-pattern.aspx

Friday, May 11, 2012

Request for the permission of type 'System.Web.AspNetHostingPermission

I moved my asp.net app from a Win 2003 Server to a Win 2008 Server running IIS7 and I started getting Permission denied for "System.Web.AspNetHostingPermission" errors for my .ascx files.

Turns out that you have to set the "Load User Profile" for the specific application pool to True. That took care of the issue. 

Sql Express LocalDb

LocalDb - introduced around the Sql 2012 RC release is a geared toward developers and dev machines. Acting much like Sql Express simplifies development, without having to maintain a full blown Sql express instance. Localdb is spawned on demand via Visual studio without having to keep a SQL process/service running in the background all the time - adding a little more processing power to dev machines.

You can connect to the LocalDb instance like this - (LocalDb)\v11.0

Read more about LocalDb - http://blogs.msdn.com/b/sqlexpress/archive/2011/07/12/introducing-localdb-a-better-sql-express.aspx

Change default database name in EF 4.3 Code First

While using Code first in EF 4.3 the default generated db name will look like your namespace something.datacontext.

To change this behavior and use a custom name:

public class StockWatchDataContext:DbContext
    {
        public StockWatchDataContext(): base("StockWatch") //add your db name and override the base constructor
        { }

        public DbSet Security { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove();
        }
    }
Also make sure that you are not using localdb as the db server instance or you wont see that in SQL management studio.

Thursday, May 10, 2012

YQL + JSON issues

Tried almost everything to get some JSON from YQL and just could not loop through the items. What worked was to parse the JSON using JSON.parse(jsondata). No problems there after.

var getStockQuote = function () {
        var url = "/api/stockquote/sd";
       
        $.getJSON(url, function (data) {
            var json = JSON.parse(data);
            $.each(json.query.results, function (i, results) {
                formatting.updateSecurity(results);
            });
        });