After spending the last 3 days riding my laptop of a really dodgy virus called Vundo. I decided to rebuild my machine. Why rebuild I hear you ask? The only reason for the rebuild is that Acronis True Image does not support Windows Server 2008 and seeing as that was my last operating system I have no base image :(

So now I am back on Vista Ultimate x64 and will be creating my base image in a minute. Normal service should resume soon.

Share/Save/Bookmark

Service Broker has a really good C# wrapper interface that comes part of the samples on Codeplex. If you need to work with service broker objects in the managed world then I would recommend using the interface from the .

Most samples I have seen demonstrate communicating within a single database, and hence use the SqlTransaction Class The code below is an example of sending a message to a SSB Service  in a SqlTransaction.

   1: private void SendMsgToSSB()
   2: {
   3:     SqlConnection conn = null;
   4:     SqlTransaction tran = null;
   5:     Conversation dialog = null;
   6:     Service client = null;
   7:     string connString = "Persist Security Info = False; Integrated Security = True; Initial Catalog = MyServiceBrokerDB; Data Source = .; Connect Timeout = 30;"
   8:     try
   9:     {
  10:         conn = new SqlConnection(connString);
  11:         conn.Open();
  12:  
  13:         // Begin a transaction
  14:         tran = conn.BeginTransaction();
  15:  
  16:         // Create a service object
  17:         client = new Service("MyCoolService", conn, tran);
  18:         client.FetchSize = 1;
  19:  
  20:         // Begin a dialog with the MyCoolService
  21:         dialog = client.BeginDialog(
  22:             "MyCoolServiceTarget", null, "DEFAULT",
  23:             TimeSpan.FromMinutes(1), false, conn, tran);
  24:  
  25:         // Create request message
  26:         string outgoingBody = "my really cool msg that broker understands";
  27:         Message request = new Message("DEFAULT",
  28:                                       new MemoryStream(Encoding.UTF8.GetBytes(outgoingBody)));
  29:  
  30:         // Send the message to the service
  31:         dialog.Send(request, conn, tran);
  32:  
  33:         dialog.End(conn, tran);
  34:         tran.Commit(); 
  35:     }
  36:     catch (ServiceException svcEx)
  37:     {//deal with this pesky service exceptions
  38:     }
  39:     finally
  40:     {//clean up here close connections etc.
  41:     }
  42: }

But in scenarios where the transaction needs to be elevated from a lightweight transaction to one that needs the aid of the DTC the SqlTransaction object is not going to cut it for you.

With a simple change (in bold and italicized) you can then support enlisting in a Distributed Transaction.

   1: public void SendMsgToSSB()
   2: {
   3:     SqlConnection conn = null;
   4:     Conversation dialog = null;
   5:     Service client = null;
   6:     string ConnectionString = "Persist Security Info = False; Integrated Security = True; Initial Catalog = MyServiceBrokerDB; Data Source = .; Connect Timeout = 30;";
   7:     try
   8:     {
   9:         conn = new SqlConnection(ConnectionString);
  10:         if (conn.State != ConnectionState.Open)
  11:         {
  12:             conn.Open();
  13:         }
  14:         conn.EnlistTransaction(Transaction.Current);
  15:  
  16:         // Create a service object
  17:         client = new Service("MyCoolService", conn, null);
  18:         client.FetchSize = 1;
  19:  
  20:         // Begin a dialog with the MyCoolService
  21:         dialog = client.BeginDialog(
  22:             "MyCoolServiceTarget", null, "DEFAULT",
  23:             TimeSpan.FromMinutes(1), false, conn, null);
  24:  
  25:         // Create request message
  26:         string outgoingBody = "my really cool msg that broker understands";
  27:         Message request = new Message("DEFAULT",
  28:                                       new MemoryStream(Encoding.UTF8.GetBytes(outgoingBody)));
  29:  
  30:         dialog.Send(request, conn, null);
  31:         dialog.End(conn, null);
  32:     }
  33:     catch (ServiceException ex)
  34:     { //deal with the exception
  35:     }
  36:     finally
  37:     { //clean up
  38:     }
  39: }

 

Again this code has a small issue what about if there is no Transaction available then sending a message without a transaction could be a bad thing. With one more change its ready to support both scenarios.

   1: public void SendMsgToSSB()
   2:   {   SqlTransaction tran = null;
   3:       SqlConnection conn = null;
   4:       Conversation dialog = null;
   5:       Service client = null;
   6:       string ConnectionString = "Persist Security Info = False; Integrated Security = True; Initial Catalog = MyServiceBrokerDB; Data Source = .; Connect Timeout = 30;";
   7:       try
   8:       {
   9:           conn = new SqlConnection(ConnectionString);
  10:           if (conn.State != ConnectionState.Open)
  11:           {
  12:               conn.Open();
  13:           }
  14:           if (Transaction.Current != null)
  15:           {
  16:               conn.EnlistTransaction(Transaction.Current);
  17:           }
  18:           else
  19:           {
  20:               tran = conn.BeginTransaction();
  21:           }
  22:  
  23:           // Create a service object
  24:           client = new Service("MyCoolService", conn, null);
  25:           client.FetchSize = 1;
  26:  
  27:           // Begin a dialog with the MyCoolService
  28:           dialog = client.BeginDialog(
  29:               "MyCoolServiceTarget", null, "DEFAULT",
  30:               TimeSpan.FromMinutes(1), false, conn, null);
  31:  
  32:           // Create request message
  33:           string outgoingBody = "my really cool msg that broker understands";
  34:           Message request = new Message("DEFAULT",
  35:                                         new MemoryStream(Encoding.UTF8.GetBytes(outgoingBody)));
  36:  
  37:           dialog.Send(request, conn, null);
  38:           dialog.End(conn, null);
  39:           if (tran != null)
  40:           {
  41:               tran.Commit();
  42:           }
  43:       }
  44:       catch (ServiceException ex)
  45:       { //deal with the exception
  46:       }
  47:       finally
  48:       { //clean up 
  49:       }
  50:   }

 

I have also been making a few changes to the interface that I intend to publish shortly.

Share/Save/Bookmark

, , , , ,

mh

nuff said

Technorati Tags:

Share/Save/Bookmark

As mentioned in my post of the long drop my intention of posting video footage of my jump at Nagambie for a while now, over the weekend I finally got around to encoding and uploading it. I also took the opportunity to play with the .

Let me know what you think.


The Version


The Version

Share/Save/Bookmark

,

While working on a client project earlier this year we used a free suite of controls from called Krypton Toolkit. This toolkit served us really well to provide a consistent UX. One of my favorite features of this toolkit was the ButtonSpecs which could be added to almost every other control so that we could have text boxes with embedded buttons etc. How does this help you ask or why does it matter. Well if your like me, totally clueless on how to deal with resizing docking and anchoring, you will love ButtonSpecs

 

The other benefits of ButtonSpecs are for context menus, validation, lookups and other such things.

So if your doing windows forms development and are in need of a consistent UX for nix you cant go past the Component Factory’s offerings.

Additionally if your a MVP or own a blog with significant subscribers then you will be able to get the Phil Wright is giving away the entire Component Factory suite for free for you.

 

Technorati Tags: ,,,

Share/Save/Bookmark

, , ,

As Simon mentioned in his last post he felt that it was time to get started on learning WPF, I have decided to join him on the quest. So as of today I will be assisting him in developing the Point Case Estimation application as an XBAP.

Having used XAML in my last project I am sure that seeing the following will not freak me out too much

   1: <Path x:Name="DiamondShape"
   2:       Data="F1 M 256,32L 352,32L 416,192L 352,352L 256,352L 192,192L 256,32 Z "
   3:       Opacity="0.9"  Stretch="Fill"
   4:       Stroke="#FF2A8117"
   5:       Fill="White" >
   6: </Path>

Can anyone actually tell me what “F1 M 256,32L 352,32L 416,192L 352,352L 256,352L 192,192L 256,32 Z “ actually means without a some sort of reference guide? Maybe Chris Sells might be able to help me much like he did with Scott Hanselman

I guess that is the ultimate challenge.

Technorati Tags: ,

Share/Save/Bookmark

,

Thoughts anyone on the new blog theme.

Share/Save/Bookmark

drivescope A while ago my external backup drive died. I tried everything short of sending it off to a place like Doctor Disk to get the data restored at exorbitant prices. So with little hope of getting all the data back I left the disk for another day.

Until recently when I found File Scavenger a great little program that is currently recovering all of the content of the disk. I have my fingers crossed hoping that i will have my precious data safe.

Anyone know of any other programs like File Scavenger that would do the same? Anyone have any experience with File Scavenger and the issues with it. What would you recommend?

 

Share/Save/Bookmark

, ,

A really good article in using on

Share/Save/Bookmark

,

First up Proper Case is really .  And if you ever need to convert text to Title Case in SQL you can use Vyas Kondreddi’s PROPERCASE SQL script or David Wiesman’s PROPERCASE SQL script

My only change to their scripts would be to use NVARCHAR(MAX) or VARCHAR(MAX) as compared to their use of VARCHAR(8000), if your using SQL Server 2005 or above.

   1: CREATE FUNCTION [dbo].[fProperCase]
   2: (
   3:     @Value VARCHAR(8000), 
   4:     @Exceptions VARCHAR(8000),
   5:     @UCASEWordLength TINYINT
   6: ) 
   7: RETURNS VARCHAR(8000) 
   8: AS
   9: BEGIN
  10: ...
  11: END

 

So I would covert the above syntax when using SQL Server 2000 to the T-SQL below when using SQL Server 2005

   1: CREATE FUNCTION [dbo].[fProperCase]
   2: (
   3:     @Value VARCHAR(MAX), 
   4:     @Exceptions VARCHAR(MAX),
   5:     @UCASEWordLength TINYINT
   6: ) 
   7: RETURNS VARCHAR(MAX) 
   8: AS
   9: BEGIN
  10: ...
  11: END

Share/Save/Bookmark

, , , , ,