Tim Huffam

Dotting the I and crossing the T of I.T.

  Home  |   Contact  |   Syndication    |   Login
  116 Posts | 0 Stories | 625 Comments | 677 Trackbacks

News

Archives

Post Categories

Interesting Blogs/Links

Wednesday, July 09, 2008 #

The following javascript error occurs when trying to use the Telerik controls and you haven't updated your ASP.NET (2.0) web.config file correctly.

Error: 'Telerik' is undefined

To fix make sure the following lines are within the <system.web> section of your web.config file:

<httpHandlers>
  <
add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />
  <
add path="ChartImage.axd" verb="*" type="Telerik.Web.UI.ChartHttpHandler, Telerik.Web.UI, Version=2008.1.515.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4" validate="false" />
  <
add path="Telerik.Web.UI.WebResource.axd" verb="*" type="Telerik.Web.UI.WebResource, Telerik.Web.UI, Version=2008.1.515.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4" validate="false" />
</
httpHandlers>

In my case I was missing the ScriptResource.axd line.   Also, you only need the ChartImage.axd line if you're using the chart control.

HTH
Tim


Friday, July 04, 2008 #

With a clean install of Scuttle I found that both the import bookmarks pages (importNetscape.php and import.php) do not work - instead the both display the source of the PHP files.

This is caused by both files not having the correct php declaration at the beginning of the file eg -both of these files first line was:

<?

However they should have been:

<?php

So just simply update these files.

HTH
Tim

 


I got the following error on a fresh install of Scuttle (0.7.2) on a newly created Windows Server 2003 with PHP (5.2.6),  MySQL5.0.51b) and IIS 6:

Warning: setlocale() [function.setlocale]: Passing locale category name as string is deprecated. Use the LC_* -constants instead in C:\Inetpub\Scuttle\includes\php-gettext\gettext.inc on line 131

Warning: setlocale() [function.setlocale]: Invalid locale category name LC_MESSAGES, must be one of LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, or LC_TIME in C:\Inetpub\Scuttle\includes\php-gettext\gettext.inc on line 131

After googling for a while I found this simple solution (here: http://www.hermann-uwe.de/blog/server-client-bookmarks-a-la-del-icio-us#comment-52097 posted by CharlesW):
Add the line: if (!defined('LC_MESSAGES')) define('LC_MESSAGES', 5);
to the top of functions.inc.php.


Thanks a million CharlesW!!!


Wednesday, July 02, 2008 #

It seems every time I try to install PHP and MySQL something doesn't work - usually there's either a file missing from the PHP distro or something in the install notes is missing or incorrect.  This time it was both.

I first tried the PHP msi install - first mistake.  As it does not include the MySQL extensions - neither does the 5.2.6 PECL zip file (I mistakenly thought this would include all the extensions).  So if you've installed PHP using the MSI installer - uninstall it (via Control Panel - Add/Remove Programs).  Also - you may need to manually remove any remants of this PHP installation manually - I had to manually delete the php directory.

Now with a clean slate do the following:

  1. Download the PHP zip package from here.
  2. Extract the zip - in my case into D:\php-5.2.6-Win32
  3. Copy php.ini-recommended and rename it to php.ini (within this same dir).
  4. Edit php.ini and make the following changes:
    1. Set the extension dir eg:
      extension_dir = "D:\php-5.2.6-Win32\ext"
    2. Uncomment the extension setting for mysql eg remove the ';' from the beginning of the line:
      extension=php_mysql.dll
  5. Within IIS admin tool:
    1. Within Application Configuration (within 'Home Directory' of a site) add the php extension - mapping 'php' to php5isapi.dll (eg D:\php-5.2.6-Win32\php5isapi.dll).
    2. Within Web Service Extensions add one for php5isapi.dll (eg D:\php-5.2.6-Win32\php5isapi.dll) setting it to 'Allowed'.
  6. Update the PATH environment variable to include the php dir eg D:\php-5.2.6-Win32.
  7. Add a new environment variable called PHPRC and set to the php dir eg D:\php-5.2.6-Win32  (this part was missing from the install docs for IIS).
  8. Restart iis (eg run iisreset from the command prompt).

Bingo - that's it. To test create a file called phpinfo.php (and place in the web root) with the following:
<?php
phpinfo();
?>

The critical part to check here is that the output of this phpinfo shows the 'Loaded Configuration File' is set to the php.ini file you created above.  If PHP is configured correctly to use mysql it this (phpinfo output) will have a MySQL section - if this is missing - then something is wrong.

HTH
Tim


Thursday, June 12, 2008 #

VSTS2008 has, on occasion, lost it's source control settings - specifically, the bindings to TFS server for a given solution and it's projects.

This seems to be because the solution and project files are not being updated when you use the TFS Source Control Explorer to do a 'Get Latest'  - a 'feature' of VS2008 which allows you to work disconnected/offline - however it seems to have an issue trying to reconnect itself.

To resolve we simply removed the local source directory and did a 'Get Specific Version - get latest'.

RickSW had a similar experience.

Tim


The following error can occur when executing the .DataBind() method on a Dundas chart object within an ASP.Net page (.Net 3.0):

Series data points do not support values of type "myclass", only values of these types can be used: Double, Decimal, Single, int, long, uint, ulong, String, DateTime, short, ushort.

I had set the DataSource property to a generics List of myclass objects (List<myclass>).

It turns out that this error is caused by a mismatch between the type of objects within the list passed to DataSource and the series defined for the chart.

In my case I had create 4 series but the objects within the list only had 3.  I'm guessing the same error would also occur if the property names of these objects to not match the series .ValueMembersY/ValueMemberX property settings.

HTH
Tim


Friday, June 06, 2008 #

Using the VS2008 unit testing framework, if you want to check for an expected exception, sometimes your test will pass because the exception was raised by another line of code - after the line you were specifically trying to test.

To resolve this you have to manually check for the expected exception - using a try-catch block. 

However there is a catch (excuse the pun)....

Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsInstanceOfType() will not fail when types are different as long as the actual value is of a type within the inheritance hierarchy of the expected type. 

Eg the following assertion will not fail if ex is of type ArgumentNullException - as it inherts from ArgumentException.

Assert.IsInstanceOfType(ex, typeof(ArgumentException));

One solution is to create your own assertion method eg:

 

public static void ExpectedExceptionThrownByType(Type expectedExceptionType, Exception actualException, Type expectedThrownByType)
{
    Assert.AreEqual(expectedExceptionType, actualException.GetType());
    Assert.AreEqual(actualException.TargetSite.DeclaringType, expectedThrownByType, "Expected exception to be thrown by type " + expectedThrownByType.ToString() + " but was " + actualException.TargetSite.DeclaringType.ToString());
}
Note the first assertion uses AreEqual instead of IsInstanceOf() - this makes sure the exception is of a specific type (rather than any one up the inheritance heirarchy).

Tuesday, June 03, 2008 #

Exception: System.ObjectDisposedException: Cannot access a disposed object. 
Object name: 'DataContext accessed after Dispose.'.
 
This can occur when using Linq to SQL to retrieve data from a database - and when you try to access data after the data context object has been disposed.  More specifically, the exception occurs when trying to access an item that has not yet been retrieved from the database and the data context object has been disposed. 
 
This often occurs when using a variable, that was populated within a using(...datacontext) block, after the using() block.  This works fine when accessing data explicitly retrieved within the using() block - but the exception occurs when you try to access other items that were not retrieved eg a related item such as a foreign key or child table.
 
To reproduce this error, comment out lines 6 and 9 in the sample code below.  This will raise the exception on line 11.
We can be solve this by telling the data context to explicitly retrieve the items you'll need.  This can be done a number of ways while the datacontext is still in scope.
  1. Access the items directly eg with a linq expression eg something followed by .ToList(), .Single() or .First().  Line 9 does this in the sample below.
  2. Use the DataLoadOptions class  - this is a way of telling the datacontext what additional data to retrieve.  Lines 4, 5 and 6 do this in the sample below (6 is commented out just while testing line 9).
* Note that you only need one of these - so either include lines 4-6 (all uncommented) or line 9.
 
The following code shows how to do both.  This is based on a database using a table called Parent and a table called Child.  The Child table has a ParentId field that is a foreign key to the Parent table.  The DataClasses1DataContext was generated using Linq to SQL.

1.  Parent outerParent;
2.  using (var db = new DataClasses1DataContext
())
3.  {
4.   DataLoadOptions dlo = new DataLoadOptions
();
5.   dlo.LoadWith<Parent
>(p => p.Childs);
6.  
//db.LoadOptions = dlo;
7.  
var outerParent = (from parent in
db.Parents
8.                     select
parent).First();
9.   List<Child
> children = outerParent.Childs.ToList(); 
10. }
11. int i = outerParent.Childs.Count;

HTH
Tim

Thursday, May 29, 2008 #

When modifying a table SQL Server (2005) and unchecking a column's 'Allow Nulls' (ie trying to make the column Not Null) the following error may occur:
'<tablename>' table
- Unable to modify table. 
Cannot insert the value NULL into column '<columnname>', table '<dbname>.dbo.Tmp_<tablename>'; column does not allow nulls. INSERT fails.
The statement has been terminated.
This occurs if there is already data in this table and this column contains nulls.
 
The solution is to simply update the data in this table so that this column does not contain nulls then change the column to not null.  eg if this column was of type int you could do this:

UPDATE [<dbname>].[dbo].[<tablename>]
    SET [<integercolumnname] = -1


Tuesday, May 27, 2008 #

There is a known problem with MSBuild whereby it does not cater for database project types as these project types (database projects) are not buildable.  This is only an issue when specifying a solution file (as the item to build) within the MSBuild script.
Because these are not buildable projects VS does not show them in the solution configuration manager.  Unfortunately this means they cannot be manually configured not to build (as a work around to this problem). 
When using solution files within MSBuild, it does not allow you to exclude specific projects.  There are a few options to work around this - as mentioned in this article:  http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=640825&SiteID=1
Another simple solution is to just remove the database project from the solution - and if you really want it still within the solution - just create another project of type class library and just reuse the original project's files.  By using another project type (like class library) you can use the configuration manager to explicitly flag this project not to build (remember to update each configuration).
This issue affects TFS continuous integration builds.
 

Wednesday, April 16, 2008 #

When creating a new document and in Print Layout, Word sometimes places the cursor right at the top of the page - not catering for the top margin.

I'm not sure why - can only presume this is a bug.

The workaround, to make it display the cursor where it should be (below the margin) seems to be to view the Header then hide the header:

  1. Select menu item 'View' - 'Header and Footer' (this shows the header)
  2. Do the same thing to hide it (Select menu item 'View' - 'Header and Footer').

That's it - the cursor should now be placed where it should be - so you can start typing text and see it in the correct position on the page.

HTH

Tim


Wednesday, April 02, 2008 #

Had a strange occurance today...

In between writing unit tests in VSTS (Visual Studio Team System 2008 Developer Edition), for some reason VSTS stopped recognising the test classes as tests - so all context sensitive test actions, buttons, context menu etc for unit tests were disabled.

Still have no idea why - but I have a sneaking suspicion that some solution files may have been delete.

To get this working again I simply added another Test project:

  1. Right click on the solution and select Add - New Project...
  2. Select the 'Test Project' template then click OK.
    This sorts out visual studio - by adding in the solution items:
      - LocalTestRun.testrunconfig
      - <projectname>.vsmdi
  3. Remove the newly added project.

This fixed it for me.

 

 


Wednesday, March 12, 2008 #

When trying to use sqlcmd.exe - and not specifying the server and instance name I got the following error:

C:\Program Files\Microsoft SQL Server\90\Tools\Binn>sqlcmd -E -d master
HResult 0x7E, Level 16, State 1
VIA Provider: The specified module could not be found.
Sqlcmd: Error: Microsoft SQL Native Client : An error has occurred while establi
shing a connection to the server. When connecting to SQL Server 2005, this failu
re may be caused by the fact that under the default settings SQL Server does not
 allow remote connections..
Sqlcmd: Error: Microsoft SQL Native Client : Login timeout expired.

 The solution is to simply specify the server (and instance) name eg:

C:\Program Files\Microsoft SQL Server\90\Tools\Binn>sqlcmd -S localhost\SQLEXPRESS -E -d master


Sunday, February 17, 2008 #

Note this article is primarily based on Microsoft/.Net technologies, although the principle apply to any technology.

Before development of any reasonable business software project begins the following areas need to be nailed down:

  • Application Architecture (application structure)
  • ORM (Object/Relational Mapping - data source access and translation to/from business objects)
  • Base framework (system framework, helper classes, base classes, etc)
  • UI.

There are many tools available that will dictate or guide the architecture and generate ORM and base framework.  Most of them do a very good job and fulfil their base requirement: to facilitate and speed up development.

Unfortunately there is no silver bullet - so the difficulty is choosing the right one.  The definition of 'the right one' will vary based on the application's requirements.  However there are some basic guidelines that will make this decision easier (listed in order of weight).

  1. Policy.  Does your company (or customer) have specific policy that will dictate what you use eg 'We are only a Microsoft shop' - allowing no 3rd party tools.  This may also include things like 'only source compiled by us', which means you must have access to the source code of whatever products you use (this is also useful if you need to sign assemblies using your company's own key).
  2. Security and scalability requirements.  If the application has to scale well, then it should be able to be deployed using an n-tier architecture.  Likewise for security purposes you should not be accessing your data source from your publicly exposed interface eg web apps or web services located in a DMZ should use another tier (an app server), located behind a firewall, to perform data source access.  The caviate to this, is to have your web app/service located behind a firewall, and exposed publicly via ISA Server (which sits in the DMZ and acts as a proxy to your app).
  3. Application requirements and developer preference.
  4. Ease of use - ie how long it takes developers new to the project to get up to speed with using the framework.  This can have significant impact on initial development and ongoing maintenance costs.  Frameworks that use industry standard patterns and underlying system framework code are good for this.

Often the underlying system frameworks are very similar - as most applications require a similar set of core functionality (eg validation, security/authorisation/authentication, string manipulation, logging, etc).  The Microsoft Enterprise Library provides a lot of this out the box and is a good start and some frameworks are based on this eg .netTiers

ORM and UI are large subjects on their own - and everyone has their own oppinion of what to do/what not to do.

ORM's

Most ORM frameworks will generate code either at design time or runtime.  You will have to determine which is more appropriate to your application - flexibility and performance will be considerations.

Two of the main issues around ORMS are:

  1. Table/data model centric vs domain/business object centric, ie does the ORM generate code based on the data model or the domain model.  This is becoming a more controversial topic these days as traditionally frameworks reverse engineered from the datamodel, generating a class for every table.  This made the code easy to understand - but didn't always match the business/domain model.  The current trend is to model your domain first then generate top-down (this is actually nothing new - it's been around a long time in some of the original OO environments).
  2. For database data sources, is the SQL run in stored procedures or dynamic/inline SQL in your code.  This may be dictated to by policy - eg most DBA's will insist on spocs - however LINQ introduces a, much debated, alternative to this.

UI's

How a UI is implemented will be greatly dictated to by functional and deployment requirements - however one must also consider the future of the app.  If it's likely that the app will be around for a long time then you should do your best to split out the UI from any business logic.  This is a long-known best-practice as it will give you flexibility and portability.

Knowing what type of UI's (simple web, rich internet app, winforms, commandline, etc) your app supports is a fairly trivial task.  Choosing a pattern to implement it is not so easy.   One of the most popular patterns for this is the Model/View/Controller (MVC) pattern.  This splits out the core components of any UI.  A more recent pattern is the Model/View/Presenter (MPV) pattern - this is similar to MVC, and is better for unit testing and TDD style development.

A popular approach these days is the 'convention over configuration' style framework.  Spurred on by the success of the RubyOnRails framework there have been some developments in this area in the Microsoft camps - initially by the Castle Project's MonoRail project, and now Microsoft themselves have got on the band wagon with their ASP.Net MVC Framework.  All these implement the MVC pattern. 

A really good article on UI patterns can be found here, and a good comparison of both MVC and MVP can be found here.

I hope this brief overview has helped shine a little light on this, sometimes overwelming, subject and, if nothing else, raise more questions - which I'll endevour to dive deeper into in future posts.

Tim

 


Monday, February 11, 2008 #

This error (Cannot Open User Default Database, Login Failed Microsoft SQL Server, Error 4064), occurs when you try to connect to a SQL Server 2005 server where the default database for your user has been dropped.  Unfortuntely this occurs in Microsoft SQL Server Studio too - which means you cannot use it to resolve the issue (ie change the default database assigned to your login).
 
However you can resolve this using ye-olde command prompt...
 
1) At the command prompt enter:
  sqlcmd -E -d master
This command  logs you onto the db server using specifying master as your default db.
2) Within the SQL command prompt enter:
  alter login [MYDOMAIN\UserName] with default_database = master
This changes the default database setting against your login.
3) Then enter:
  go
This executes the command.
4) Then enter:
  quit
This quit's you out of the sqlcmd tool/prompt.
 
You screen will look something like:
C:\>sqlcmd -E -d master
1> alter login [MYDOMAIN\UserName] with default_database = master
2> go
3> quit