Enums and SQL Server 2005


Author
Message
Peter Jones
Peter Jones
Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)Advanced StrataFrame User (718 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
Hi,

We have a Enums class that contains all enums for the solution and some of these enum values actually make their way into the application database. In some queries it would be much better to show the 'text value' of an enum rather than it's integer value. Does anyone know if there is any way of doing such a thing in SQL Server 2005 now that CLR/managed code is supported? If there is can you point me to a reference or two.

Cheers, Peter

Reply
Peter Denton
Peter Denton
StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)StrataFrame User (147 reputation)
Group: Forum Members
Posts: 77, Visits: 787
Trent,

I think I went off the rails a few steps back.

Because we already had a clsEnums project, I just extended that instead of starting with a new SQL CLR project. We don't use DDT, so I added the assembly and functions int SQL Server manually. The steps I used are as follows:

create assembly SystemWindowsForms from 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll' with PERMISSION_SET = UNSAFE

go

create assembly SystemWeb from 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Web.dll' with PERMISSION_SET = UNSAFE

go

create assembly MicroFourStrataFrameBase from 'C:\Program Files\MicroFour\StrataFrame\Assemblies\MicroFour StrataFrame Base.dll' with PERMISSION_SET = UNSAFE

go

create assembly MyEnumAssembly from 'C:\development\TMS Redevelopment\TMS\UtilEnums\bin\Debug\UtilEnums.dll' with PERMISSION_SET = UNSAFE

go

create Function GetEnumNameDeviceTypes(@value int) returns nvarchar(50) as external name [MyEnumAssembly].[UtilEnums.clsEnum].[GetEnumNameDeviceTypes]

go

At this point I was able to run the following in a query

SELECT [TMS201].[dbo].[GetEnumNameDeviceTypes] (1)

which gave the result "Scale" whereas the localised version should be "Scale." (notice period at the end to show the difference between the key and localised value).

Is this lack of localisation simply because runing the function in a Query window, there is no context that allows the function to know its language, and therefore it returns the key instead of the localisation? Would I have better luck if I called it from a stored procedure that was launched from a strataframe program?

At this point I re-read your advice and saw that I should have started with a SQL CLR project, so I started one of them and copied the code from earlier into it, and got errors about invalid references as expected. When I went to add references only the Projects Tab, which was empty, and an SQL Server Tab which had the message "The connection to the database failed for the following reason: There is no available SQL server connection. No server references can be added at this time, but you may continue to develop", were available. So how do I go about adding the references I need?

Thanks for your patience

Peter

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search