So you want to add a Normal Class Library Project to a Silverlight application, you think to your self how hard could this be despite the Visual Studio Warnings. Well for the most part its fairly simple, however there are a number of problems that I faced when doing exactly that.

Thanks to Neil Mosafi’s post on converting class library project for Silverlight consumption, I found 2 methods of doing the conversion.

1.) Create a NEW Silverlight  Class Library Project and then ADD your EXISTING code files to the project

2.) Hack the csproj file to change its signature (details are courtesy of Neil Mosafi’s post) VS.NET 2008 believes that its a Silverlight Project (don’t forget the changes needs to be made to both the DEBUG as well as RELEASE sections)

Initially I went about making these changes using method 2 however I kept finding a number of issues relating to duplicate references , especially with the HttpWebRequest object and a few other things.

I also needed to change all non generic collections to use their generic equivalents as all non generic collections are not included  in Silverlight 2.0

The Serializable attribute is not part of the coreclr, therefore it has to go, XML Serialization is your friend. Rockford Lhotka has started work on an alternative to the Serializable attribute however its extremely limited at this stage, The Silverlight Serializer may suit your needs so do check it out.

The project I was playing with also used a little bit of XPath Navigation and some other System.XML namespace classes that are not part of the cut down version, so I have to change the code to use Linq to XML

There were a whole bunch of other things that I fixed up and was good to go when I realized that the project changes were not referencing the correct mscorlib and system.xml libraries, however the compiler did not seem to mind to much which baffled me. At this point I decided that the safer way was to go down option 1, simply because I thought it would give a much better jumping off point, lo and behold it has. I am pretty close to having it compile correctly for the Silverlight application which I intend to share.

At the end of this all my advice in converting is to go with method 1, as its just much more fool proof.

Share/Save/Bookmark

Over on the Ado.net blog they have just announced that Devart have just released new Ado.net Data Providers that support the Entity Framework v1.

This is great news for the Entity Framework team. This added support for multiple database vendors is another big plus for choosing the Entity Framework over Linq To Sql.

Just recently I was listening to Steven Forte and Dan Simmons on DNR talking about what the EF, the show revealed a lot of what the Entity Framework team are doing to make this a really great platform. I look forward to seeing what they have for us in the future.

At least for now if you want to use the EF you are no longer restricted to using SQL Server for your data store. Below is a list of Data Providers that will work with the EF as of the 6th of September 2008

Oracle

MySql

PostgresSql

SQLite

Sybase SQL Anywhere

UPDATE: 23-10-08 Added Sybase SQL Anywhere

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

, , , , ,

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

,

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

, , , , ,

For most people using SQL Server CLR is not an issue however when you have more that 4GB or more of memory, the CLR does not just work.

Enter the –g startup switch, You can read more about the SQL Server 2005 startup options to get the fine detail. In order to make the required changes follow these steps

1.) Launch SQL Server Configuration Manger

image

2.) Under Sql Server 2005 Services choose the instance of SQL Server that you are targeting for the change and right click on it and select Properties.

3.) Move to the Advanced Tab and locate the Startup Parameters

image

4.) Add the –g option to the end by first closing the previous parameter with a ‘;’ then –g, not adding the ‘;’ to the end of the previous parameter will cause SQL server to fail on restart

image

5.) Click Apply /OK and restart the service. When the service restarts you should now have SQL CLR on your machine. A simple Hello World CLR stored proc should do tell you if your in business or not.

 

Share/Save/Bookmark

,

How do you deploy SQL Server Management Objects (SMO) runtime?   Follow this 3 step process for success.

STEP 1:  

STEP 2:  

STEP 3:

The links above point to the X86 framework however at the time of writing the was the latest and had links to the various processor architectures that are supported by Microsoft

I guess the next logical step is to find out what the differences will be between SQL Server 2005 and SQL Server 2008 seeing as its release is imminent. That being said my total time invested in Microsoft’s latest database technology has been zero.

While I am deviating. Am I the only one not really concerned with SQL Server 2008’s launch?

Technorati Tags: ,,

Share/Save/Bookmark

, ,

Today one of my colleagues was working on piece of code that would turn a given mapped drive to full UNC path. The code to do implement the functionality is very simple and can be done in a variety of ways ranging from Win32 API to WMI (via System.Management) Below is a snippet of the code that was used.

   1: public static string GetUNCPath(string originalPath)
   2: {
   3:     string returnVal = originalPath;
   4:     foreach (DriveInfo drive in System.IO.DriveInfo.GetDrives())
   5:     {
   6:         if (Path.GetPathRoot(originalPath).ToLower().StartsWith(drive.RootDirectory.FullName.ToLower()))
   7:         {
   8:             if (drive.DriveType == DriveType.Network)
   9:             {
  10:                 System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(