Monday, May 31, 2010

Visual Studio 2010, Build error, Build (web): Object reference not set to an instance of an object

When upgrading a from previous version, Crystal report build provider will cause builder error, in ASP.NET 4 crystal reports are also pre-compiled using build provider for (.rpt), when compiler tries to pre-compile reports build in previous version, a build error "Object reference not set to an instance of an object" is thrown and build fails.

Possible work arround is to remove the build provider for (*.rpt) in your web.config:

There will be following construct under section:

<buildProviders>
<add extension=".rpt" type="CrystalDecisions.Web.Compilation.RptBuildProvider, CrystalDecisions.Web, Version=14.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
</buildProviders>

We can change this to:

<buildProviders>
<add extension=".rpt" type="CrystalDecisions.Web.Compilation.RptBuildProvider, CrystalDecisions.Web, Version=14.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<remove extension=".rpt"/>
</buildProviders>

What we have done is removed the build provider for (.rpt), in this way the crystal reports will remain as it is and no build error will show.

Thursday, May 27, 2010

Object Oriented Javascript (Part-1)

We can develop object oriented JavaScript using function method, in JavaScript functions are the main constructs that can be called or referenced. To write object oriented reusable JavaScript libraries we can utilize the similar function which use every day.

JavaScript function:
At this point i assume that we know what a function is, for quick example it is as follows:
<script type="text/javascript">
//Declare a JavaScript function
function helloWorld()
{
alert('This is my first function.');
}

//calling a JavaScript function
helloWorld();
</script>


JavaScript Class
There is no syntax to declare classes in javascript, but purpose of object class is to encapsulate data and provide some attributes or methods for outer world. This can still be achieved in JavaScript using the same function.
Functions in JavaScript can be instantiated, which means we can create multiple copies of a JavaScript function the same way as we can create instances of a class.

There are different ways to do that, the simplest way is as follows:

<script type="text/javascript">
//Declare a JavaScript Class
function Car(car_color)
{
//Initialize attributes with default values
this.Color = car_color;
this.Model = '';
this.Make = '';
//Methods
this.getModel = function() {
return this.Model;
}
this.setModel = function(car_model) {
this.Model = car_model;
}
}

//Instantiate
var car1 = new Car('Red');
var car2 = new Car('Black');
//Set attributes
//Car1
car1.Make = 'Honda';
car1.setModel('2009');
//Car2
car2.Make = 'Ford';
car2.setModel('2008');
//Call instance method
alert(car1.getModel());
alert(car2.getModel());
</script>


In the above example we can see how two instance of car were created, initialized and accessed in the JavaScript. This simple approach can help in creating reusable code which is encapsulated in a function, this way JavaScript is more manageable and help a lot when you are doing complex scripting.

Tuesday, March 23, 2010

WampServer 2.0 Port Configuration

Now that you have WampServer 2.0 installed, you'll want to use it along side with other servers such as IIS. This is easily done by changing the port that WampServer 2.0 listens to. I suggest changing the port from 80 to 81.

Use Notepad or WordPad to open the files below.

  1. Open the httpd.conf file for the Apache server. On my machine, it's located here:

    C:\wamp\bin\apache\apache2.2.6\conf\httpd.conf
    • Do a search for "Listen 80" and replace it with "Listen 81".
    • Save and close the file.

  2. Open the wampmanager.tpl file. On my machine, it's located here:

    C:\wamp\wampmanager.tpl
    • Do a search for "http://localhost/" and replace it with "http://localhost:81/" (There are three total).
    • Do a search for "${w_testPort80}" and replace it with "${w_testPort81}".
    • Save and close the file.

  3. Open the testPort.php file. On my machine, it's located here:

    C:\wamp\scripts\testPort.php
    • Do a search for "80" and replace it with "81" (There are three total).
    • Save and close the file.

  4. Open the english.lang file. On my machine, it's located here:

    C:\wamp\lang\english.lang
    • Do a search for "$w_testPort80 = 'Test Port 80';" and replace it with "$w_testPort81 = 'Test Port 81';".
    • Save and close the file.

  5. Right click on the WampServer icon and click on "Exit".

  6. Restart your WampServer.

Friday, March 12, 2010

SQL Server 2005 - Get Size of Databases

EXEC DATABASE.dbo.sp_spaceused

EXEC DATABASE.dbo.sp_spaceused 'TABLE_NAME'

EXEC DATABASE.dbo.sp_spaceused '?'