What Was I Thinking?

Follies & Foils of .NET Development

  Home  |   Contact  |   Syndication    |   Login
  74 Posts | 0 Stories | 191 Comments | 0 Trackbacks

News

Archives

Post Categories

Check These Out

Gurus

Saturday, January 28, 2012 #

If your connection hangs while attempting to start sql server broker service, its likely caused by the system trying to gain exclusive access to your database.   Some people recommend stopping and restarting the sql server instance.  I find that a little heavy-handed, like swatting a fly with a sledge hammer.  Instead switch the database into single user mode, enable the broker service, and restore the database to multi-user mode.

 

1) Set the database to single user mode:

ALTER DATABASE [DBNAME] SET SINGLE_USER WITH ROLLBACK IMMEDIATE

 

2) Enable Broker Service on the database

ALTER DATABASE [DBNAME] SET ENABLE_BROKER;

 

3)Restore the database to multi-user mode

ALTER DATABASE [DBNAME] SET MULTI_USER

Of course you’ll need proper permissions, but enabling the service this way prevents interruption to any other databases running on your server.

 

Also make sure Broker Service is enabled:

SELECT is_broker_enabled FROM sys.databases WHERE name = ‘DBNAME’;It should return 1 if its enabled.
-- Enable Service Broker:
ALTER DATABASE [DBNAME] SET ENABLE_BROKER;

-- Disable Service Broker:
ALTER DATABASE [DBNAME] SET DISABLE_BROKER;
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Wednesday, October 26, 2011 #

Tired of ISP DNS service errors?  switch to use Google’s.  They are FAST and ALWAYS available.

Primary: 8.8.8.8

Secondary: 8.8.4.4

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

   1:   var daysOfWeek = new[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
   2:   var workDays = daysOfWeek.Except( new []{ "SUNDAY", "SaTURdaY"}); // Performs a case sensitive search and yields Sunday,Monday - Saturday. 
   3:  workDays = daysOfWeek.Except(new[] { "SUNDAY", "SaTURdaY" },StringComparer.OrdinalIgnoreCase); // Performs a case insensitive search and yields Monday-Friday

 

The except operator takes a comparer that tells it how to evaluate the two lists.  Nice one!

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Thursday, June 30, 2011 #

Sometimes working with the js Serializer is easy, sometimes its not.   When I attempt to serialize an object that is derived from a base, the serializer decided whether or not to include the type name.

When its present, the type name is represented by a ___type attribute in the serialized json like this:

{"d":{"__type":"Commerce.Integration.Surfaces.OrderCreationRequest","RepId":0}}

The missing type name is a problem if I intend to ship the object back into a web method that needs to deserialize the object.   Without the Type name, serialization will fail and result in a ugly web exception.

The solution, which feels more like a work-around, is to explicitly tell the serializer to ALWAYS generate the type name for each derived type.  You make this declaration by adding a [GenerateScriptType())] attribute for each derived type to the top of the web page declaration.

 

For example, assuming I had 3 derivations of OrderCreationRequest; PersonalOrderCreationRequest, CompanyOrderCreationRequest, InternalOrderCreationRequestion, the code-behind for my web page would be decorated as follows:

    [GenerateScriptType(typeof(PersonalOrderCreationRequest))]
    [GenerateScriptType(typeof(CompanyOrderCreationRequest))]
    [GenerateScriptType(typeof(InternalOrderCreationRequest))]
    public partial class OrderMethods : Page
{
...
}
With the type names generated in the serialized JSON, the serializer can successfully deserialize instances of any of these types passed into a web method.
Hope this helps you as much as it did me. 
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Thursday, April 28, 2011 #

I was working on a project that required a determination if the type was an IEnumerable collection of some type. 

 

Using a bit of reflection and the handy-dandy GetGenericTypeDefinition method, I arrive at this:

Code Snippet
  1. public static bool IsIEnumerableOfT(Type type)
  2.       {
  3.           return type.GetInterfaces().Any(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof (IEnumerable<>)) ;
  4.       }

Happy Coding!

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Wednesday, April 20, 2011 #

Ever wanted to re-order your Thunderbird accounts?

 

You can either modify the prefs.js manually

1. Exit Thunderbird if its running.

2. Locate your prefs.js file (default location is c:\users\[your account]AppData\Thunderbird\Profiles

3. create a backup , just in case.

4. Open the prefs.js in any text editor and look for: user_pref("mail.accountmanager.accounts", "account1,account2,account3,account4…"); line

5. Change the order of the accounts manually

6. Restart Thunderbird

 

OR

1. Download and install the FolderPane add-on.

2. From Thunderbird, select Tools->Add ons –> Folderpane and reorder the accounts using the “Move Up” and “Move Down” buttons.

3. Close and restart Thunderbird.

 

The choice is yours.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Tuesday, March 29, 2011 #

I’m posting this here because I keep forgetting the syntax, and thought others might benefit as well.

 

Given :

public class ParentItem

{

   IEnumerable<ChildItem> Children

}

 

Selecting all the childitem instances from an IEnumerable<ParentItem>:

var allChildren = ParentItems.SelectMany(parent=>parent.Children);

 

Selecting matching childItem instances from an IEnumerable<ParentItem>:

var selectedChildren = ParentItems.SelectMany(parent=>parent.Children).Where(child=><boolean expression for filtering children>)

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Saturday, March 19, 2011 #

Culture beats Strategy every time.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Tuesday, March 15, 2011 #

If your website uses the AppPoolIdentity and requires access to the private key of an x509Certficate, you’ll need to grant the read permissions to the iis application pool.

 

To grant permissions to the AppPoolIdentity:

  1. Run Certificates.MMC (or Start->run->mmc.exe, Add Certificate Snap-In for LocalMachine)
  2. Select the certificate (Personal node on the certificate tree) , right click and Manage Permissions.
  3. Add a new user to the permissions list.
  4. Enter "IIS AppPool\AppPoolName" on the local machine". Replace "AppPoolName" with the name of your application pool.
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Tuesday, February 15, 2011 #

I’ve read some posts regarding this error when using the First() or Single() command.   They suggest using FirstOrDefault() or SingleorDefault() instead.

But I recently encountered it when using a Sum() command in conjunction with a Where():

 

Code Snippet
  1. var effectiveFloor = policies.Where(p => p.PricingStrategy == PricingStrategy.EstablishFloor).Max(p => p.Amount);

 

When the Where() function eliminated all the items in the policies collection, the Sum() command threw the “Sequence contains no elements” exception.

 

Inserting the DefaultIfEmpty() command between the Where() and Sum(), prevents this error:

Code Snippet
  1. var effectiveFloor = policies.Where(p => p.PricingStrategy == PricingStrategy.EstablishFloor).DefaultIfEmpty().Max(p => p.Amount);

 

but now throws a Null Reference exception!

 

The Fix:

Using a combination of DefaultIfEmpty() and a null check in the Sum() command solves this problem entirely:

Code Snippet
  1. var effectiveFloor = policies.Where(p => p.PricingStrategy == PricingStrategy.EstablishFloor).DefaultIfEmpty().Max(p =>  p==null?0 :p.Amount);
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati