Thursday, July 24, 2008

Billy Joel - Again

While looking for something completely different I just stumbled across this old post - http://itstu.blogspot.com/2006/07/billy-joel-tickets-but-events-were.html - and it reminded me, we just bought tickets for the latest Billy Joel concert. Last time my ticket purchasing efforts were a bit of a fiasco but this time, I let Rachel do it, we spent about $280 extra, but it's going to be worth it! Directly in front of stage, lower level - perfect!

 

RodLaverArena_0

Iritis

Iritis cleared up quickly as usual last week, but the short sightedness is hanging around much longer than I remembered. It's very annoying, but Ive resorted to cranking the fonts on my computer up to "Extra Large" and you should see the size of the fonts in my Visual Studio editor. (Courier New 14 point! I think I like it...)

Internal Classes!

I wanted to make a class available to only other classes within the assembly - not outside it. I stuff around for twenty minutes, the "Joel" to the rescue - http://discuss.joelonsoftware.com/default.asp?dotnet.12.355095.3.

 

(May need to remember this again someday.)

Tuesday, July 15, 2008

Iritis

Just for the record - Iritis flared up again this week. Back on the Predeferin Forte eye drops causing annoying short sightedness for awhile. I've got the font size etc cranked right up to ExtraLarge and still find I'm dragging the monitors forward on the desk. Drops usually clean it up pretty quick smart though.

The eye actually started aching a bit last weekend, but I lived in hope it would just go away...it didn't.

It's a almost as painful as the Iritis, trying to organise a reference from my GP, so that I can see the eye specialist, so that he can prescribe exactly what I know I need. That's part of the medical ripoff here though isn't - a few people are making pretty good money for doing very little. Not the eye specialist though - he is amazingly thorough, dedicated and caring. He always goes out of his way to make sure I get in to see him the day I call, and always follows up very diligently.

The middlemen though, are making their money pretty easy.

Anyway, thought I ought to start noting the flare-ups and look for a pattern. It was far worse at night when I was tired. I've been doing quite a bit of "in the zone" development hours (at the computer lately too), and plenty of reading! It's got to be related - tired eyes and so on...

"Unable to load the specified metadata resource"

Being fairly new to LINQ I have struggled for a bit to set up connections to databases other than the default one against which the Model was built. Anyway, after a bit of hunting I found some useful stuff on MSDN describing how to build firstly, an SQL string, then build an EntityConnection string based on that SQL string. I then use that EntityConnectionString to build an EntityConnection object which is used to create ObjectContext objects - connections to my Model.

private string buildConnectString(string ServerName)
        {
            SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder();
            sqlBuilder.DataSource = ServerName;
            sqlBuilder.IntegratedSecurity = true;
            sqlBuilder.InitialCatalog = "MyDatabaseName";
            sqlBuilder.MultipleActiveResultSets = true;
            string sqlConnectString = sqlBuilder.ToString();

            EntityConnectionStringBuilder entBuilder = new EntityConnectionStringBuilder();
            entBuilder.Provider = "System.Data.SqlClient";
            entBuilder.ProviderConnectionString = sqlConnectString;
            entBuilder.Metadata = @"res://*/ConstructorModel.csdl|res://*/ConstructorModel.ssdl|res://*/ConstructorModel.msl";

            return entBuilder.ToString();

This had a couple of problems - initially around problems with open datareaders when doing some nested reads on various tables. For the time being I get around that by opening the ObjectContext objects with my EntityConnection object's connection string, instead of the object itself.

It looks a bit backwards, but I need to revisit this part:

EntityConnections con = new EntityConnection(buildConnectString("myServerName")

MyContext model = new MyContext(con.ConnectionString)

instead of;

MyContext model = new MyContext(con)

seems to do the trick.

There was still a big problem when attempting to use this setup, in a multi-tiered project though.

In my UnitTest project (Visual Studio Team Suite Unit testing) this worked fine. The Unit Test project has a reference directly to my Data Model assembly.

Once of go to the multi-tiered WinForms app though, which references a business component assembly, which in turn references a Data Access component, which is what references the Data Model assembly, the "Unabled to load specified metadata resource" error was thrown when attempting to instantiate the ObjectContext object, in the Data Access Components class.

Turns out, as described in this post - http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3030997&SiteID=1 - referencing my ObjectContext object works in a two tier scenario of the Unit Tests project, but when the ObjectContext object doesn't get referenced directly but rather in an assembly a tier or so down the chain, you need to explicitly state the name of the assembly in the connection string, as follows;

private string buildConnectString(string ServerName)
        {
            SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder();
            sqlBuilder.DataSource = ServerName;
            sqlBuilder.IntegratedSecurity = true;
            sqlBuilder.InitialCatalog = "MyDatabaseName";
            sqlBuilder.MultipleActiveResultSets = true;
            string sqlConnectString = sqlBuilder.ToString();

            EntityConnectionStringBuilder entBuilder = new EntityConnectionStringBuilder();
            entBuilder.Provider = "System.Data.SqlClient";
            entBuilder.ProviderConnectionString = sqlConnectString;
            entBuilder.Metadata = @"res://MyObjectContextAssemblyName/ConstructorModel.csdl|res://MyObjectContextAssemblyName/ConstructorModel.ssdl|res://MyObjectContextAssemblyName/ConstructorModel.msl";

            return entBuilder.ToString();

No asterix (*) in the connectionstring for you EntityConnection object.