Wednesday, 6 August 2008

Don't forget this when installing MSDE 2000 if you need network connectivity

I've just come back from installing one of our systems at a customers office. I don't normally install these systems myself, normally their own IT stall do this. Nice to get out of the office though.

I needed to install MSDE 2000, this should have been simple enough. All appeared to go well, MSDE installed, set up the new application and installed the client locally on the machine to check functionality. All good so far. I then went to install the client on another machine and couldn't get it to connect to SQL server. I spent ages trying different connection strings and messing about with firewalls with no luck.

Then I remembered..

At some point Microsoft decided to disable network connections by default on MSDE installations, I'm sure they had their reasons. This can be overridden by specifying DISABLENETWORKPROTOCOLS=0 as one of the setup parameters. I'd totally forgotten about this, so I un-installed and reinstalled SQL Server and everything worked fine.

Rory dealing with corporate BS

Reading Rory's excellent blog. Rory finds that sitting at home being bored living on his savings isn't enough. He finds he needs to earn some serious money and starts doing the job hunting thing, but gets really annoyed at the BS corporates produce. The brilliantly titled post says it all.
Go read Are You Passionate About Utilizing Your Core Competencies To Effect Strategic Outcomes?

Link

Wednesday, 9 July 2008

ASP.NET MVC View Master Page Template bug

This is just a minor annoyance, easily sorted.


When you create an ASP.NET MVC View Master Page you probably go and change the content of the tag. This works when you first launch the website but as soon as you start to navigate around the title reverts to Untitled.

It appears to be an easy solution

Look at the following MVC View Master page snippet of the header

Simply remove the runat="server" attribute from the tag and the problem goes away.

I'm sure this bug will get sorted in an upcoming release.








Labels: ,


Friday, 14 March 2008

Restoring template settings after upgrading to ASP.NET Preview 2

I recently upgraded the systems I've been working on to use the ASP.NET MVC Preview 2 from the old December 2007 CTP version. I followed the very thorough explanation given here
http://www.asp.net/downloads/3.5-extensions/readme/Preview2.aspx

Fortunatly it didn't take too long and I soon had my projects up and running again. All was good until I tried to actually work with one of the projects, all the MVC templates were missing when I tried to add something new. I don't pretend to understand the detail of this but I think Preview 2 works with a new project type and VS2008 looks for this project type when filtering the templates. The old Preview 1 MVC projects will have a different project type so the MVC templetes will not be shown.

My solution, I created a new empty MVC project and opened up it's project file in notepad and copied the following line.

<ProjectTypeGuids>{603c0e0b-db56-11dc-be95-000d561079b0};{349c5851-65df-11da-9384-00065b846f21};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}</ProjectTypeGuids>

I then replaced the corresponding line in my old project file with the new line and all my templates returned.

Wednesday, 27 February 2008

Rob Conery » Creating IN Queries With Linq To Sql

I like it when someone explains a concept in terms I can understand.

Rob Conery » Creating IN Queries With Linq To Sql

LINQ can be very frustrating when you are used to writing SQL directly. I get the idea that it's probably a good thing not to worry too much about the SQL generated and to think in terms of what you actually need to find from the database. Let LINQ sort out the detail of the query, the developers have spent a lot of time optimising their LINQ queries, maybe we should just trust them.

Link

Wednesday, 6 February 2008

Left/Right Joins LINQ way too complicated in VB9

I was recently trying to use LINQ to join two tables using a Left Join, nothing complicated, in fact here's the SQL I was trying to replicate

select L.* from tbllocation L left join tblItem I on L.locationid = I.locationid where I.Locationid is null

I couldn't figure out how to do this, turning to Google I found this article

The Visual Basic Team : Converting SQL to LINQ, Part 8: Left/Right Outer Join (Bill Horst)

which is part of this excellent series or articles

Converting SQL to LINQ by Bill Horst

Bill states that "VB9 doesn't yet have smooth support for Left or Right Joins" and comes up with a solution using the group join. In my opinion this is far too complicated to me to use reliably. I'm sure I'd get it eventually but for now I've reverted back to using a simple stored procedure to return the information I want.

LINQ is good and I enjoy having my intellisensed database; sometimes however, LINQ can get in the way and I just need to get the job done.

Link

Thursday, 17 January 2008

Returning Values from Stored Procedures using Linq

Linq is Microsofts new way of accessing databases, for the first time you can write database queries directly within your code instead of within a string.

I use stored procedures a lot, in fact I rarely have even a select statement in my code. Other people far more qualified than me will give the pros and cons of this method. I used to use the Microsoft Enterprise Library and they had a very clean way of accessing the data

For a single value returned from a stored procedure the code would go something like this

Dim db as database = DatabaseFactory.CreateDatabase
Dim RetVal as integer= CType(db.ExecuteScalar("sel_DoesUserNameAlreadyExist", UserName), Integer)

Easy, job done.

I've been trying to do the same thing using Linq

Here's the Stored Procedure, about as basic as can be

Create Procedure sel_DoesUserNameAlreadyExist(@Username nvarchar(50))
as
select count(UserName) as CountOfUser from tblUser where UserName = @UserName



1st Job after you create the stored procedure is you drag and drop the stored procedure onto the DataClassDataContext. This very cleverly maps the StoredProcedure to Linq and sets up a
class for the returned data

_
Public Function sel_DoesUserAlreadyExist( ByVal forename As String, ByVal surname As String) As ISingleResult(Of sel_DoesUserAlreadyExistResult)
     Dim result As IExecuteResult = Me.ExecuteMethodCall(Me, CType MethodInfo.GetCurrentMethod,MethodInfo), forename, surname)
     Return CType(result.ReturnValue,ISingleResult(Of sel_DoesUserAlreadyExistResult))
End Function


Here's the Class definition

Partial Public Class sel_DoesUserNameAlreadyExistResult
Private _CountOfUser As System.Nullable(Of Integer)
     Public Sub New()
          MyBase.New
     End Sub
     _
     Public Property CountOfUser() As System.Nullable(Of Integer)
          Get
               Return Me._CountOfUser
          End Get
          Set
               If (Me._CountOfUser.Equals(value) = false) Then
                    Me._CountOfUser = value
               End If
          End Set
     End Property
End Class


Note how the CountOfUser field has been mapped to the class

My Linq code is now

Dim db As New My_DataClassDataContext
Dim RetVal as integer
For Each row In db.sel_DoesUserNameAlreadyExist(UserName)

     RetVal = row.CountOfUser
Next



This is the end result of my struggles, on the way I discovered a big gotcha

Here's my original Stored Procedure


Create Procedure sel_DoesUserNameAlreadyExist(@Username nvarchar(50))
as
select count(UserName) from tblUser where UserName = @UserName



Note there is no alias on field count(UserName)

When this was mapped to Linq there is no sensible field name so it gets mapped to Column1 instead of CountOfUser. This causes a problem when you try and run the stored procedure. The mapping fails, Column1 does not really exist and so the returned value does not get mapped, a row gets returned but Column1 has a value of Nothing.

Workaround, always alias your calculated fields when using Stored Procedures.





Labels: ,