SyntaxHighlighter

Friday 24 June 2011

How To Enumerate / Iterate an Enum

I often find myself needing to iterate/enumerate an enum. It's dead easy, but seem to always forget! What a fool ;)

Anyway, here ya go...

Public Enum MyEnum
    Jim = 0
    Bob = 1
End Enum

For Each e As MyEnum in [Enum].GetValues(GetType(MyEnum))
    Console.Write(String.Concat(e.ToString(), "=", Int32.Parse(e)))
Next

The GetValues method is quite useful as you can also get stuff like the length from it:
[Enum].GetValues(GetType(MyEnum)).Length.

The C# is pretty much the same just that [Enum] has no square brackets around it.

Wednesday 22 June 2011

Auto Trimming - Whitespace Removal in SQL Server/MSSQL

I got really angry about this one yesterday as I can't see one possible reason why this "feature" would be required.

If you run this script, the whitespace padded string is also returned along with the unpadded string.

CREATE TABLE #t ([col1] varchar(100))

INSERT INTO #t ([col1]) VALUES ('hello')
INSERT INTO #t ([col1]) VALUES ('hello     ')

SELECT '''' + [col1] + '''', LEN([col1]), DATALENGTH([col1])
FROM #t

SELECT * FROM #t WHERE [col1] = 'hello'
SELECT * FROM #t WHERE [col1] = 'hello     '

DROP TABLE #t


How can this possibly be right? If I want 'hello     ' to be returned, then return 'hello     ' not 'hello'. These are two very different strings!

Peoples arguments are why would want to save that and other such silly statements. My philosophy is, if I can think of it, it will happen! I can think of many cases where it would be beneficial to have the padding - dealing with old systems or external systems over which control is not possible.

Now I know that SQL Server does this stupid thing, I can account for it - but seriously - why?? It's stupid!

Oh and ANSI_PADDING - makes no odds!

Thursday 16 June 2011

Clear / Remove Recent Projects in Visual Studio

For those of you still unlucky enough to be using Visual Studio 6 out there this is how to clear the recent Visual Basic projects from the recent projects list:

  1. Run regedit from Start > Run
  2. Go to KEY_CURRENT_USER\Software\Microsoft\VisualBasic\6.0\RecentFiles
  3. Delete or change the paths as necessary

For more recent versions of Visual Studio, clear the recent project list by doing this.

Tuesday 14 June 2011

MSSQL Saving Change is not Permitted (Prevent)

This was a cheeky one I came across today. Where I was getting the following message from SQL Server 2008 in the table designer:
Saving change is not permitted. the changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that cant be re-created or enabled the option Prevent Saving changes that require the table to be re-created.
The solution is to change the setting by using the menu: Tools > Options > Designers, then unchecking the "Prevent saving changes that require table re-creation" box.


 Guessing it's not a problem and more like a feature. Little bit odd, but I can understand why...

Thursday 9 June 2011

Website Availability Monitoring

I was looking for a tool that would easily monitor the availability of a website that I work on. This particular site has a tendency to become unavailable. Usually some kind of network related issue.

Anyway...
After some hunting around I came across www.siteuptime.com. They have a range of packages, but I used the free one as that gave me enough for this site. It's checking every 30 minutes and the reporting seems pretty much spot on. The service will email me if the site becomes unavailable, so hopefully I'll spot it much sooner now!


Tuesday 7 June 2011

System.Web.Services.Protocols.SoapException: The permissions granted to user 'IIS APPPOOL\MyUser' are insufficient for performing this operation

I had this error (System.Web.Services.Protocols.SoapException: The permissions granted to user 'IIS APPPOOL\MyUser' are insufficient for performing this operation) and took me a while to work out what to do to fix it. All the references I found  to it were relating to SharePoint.

In my instance I had added a web reference to my application to make use the reporting services (SSRS) web service (http://localhost/ReportServer/ReportExecution2005.asmx). Although it was working locally, it was not working when I deployed it to the dev or live server.

Turns out the account that is used by the reporting services service account needed to be the same as the account that the application pool was using.

So check the service account in the reporting services configuration tool:


Then from within the IIS, change the identity that the application pool is using (right click the pool and choose Advanced Settings...):


FYI, here's the full error message:
System.Web.Services.Protocols.SoapException: The permissions granted to user 'IIS APPPOOL\MyUser' are insufficient for performing this operation. ---> Microsoft.ReportingServices.Diagnostics.Utilities.AccessDeniedException: The permissions granted to user 'IIS APPPOOL\MyUser' are insufficient for performing this operation. at Microsoft.ReportingServices.WebServer.ReportExecution2005Impl.LoadReport(String Report, String HistoryID, ExecutionInfo2& executionInfo) at Microsoft.ReportingServices.WebServer.ReportExecutionService.LoadReport(String Report, String HistoryID, ExecutionInfo& executionInfo)


Monday 6 June 2011

Remove Importance Markers from GMail

GMail recently introduced the importance marker as part of their priority inbox feature. I accepted the setting to see how it worked. It wasn't for me so I wanted to turn it off. So this is how to do it...

Go to Mail Settings and choose the Priority Inbox tab. Then set the Importance markers option to No markers and click Save - Happy days :)


Labels

.net (7) ajax (1) android (7) apache (1) asp.net (3) asus (2) blogger (2) blogspot (3) c# (16) compact framework (2) cron (1) css (1) data (1) data recovery (2) dns (1) eclipse (1) encryption (1) excel (1) font (1) ftp (1) gmail (5) google (4) gopro (1) html (1) iis (3) internet explorer IE (1) iphone (1) javascript (3) kinect (1) linux (1) macro (1) mail (9) mercurial (1) microsoft (3) microsoft office (3) monitoring (1) mootools (1) ms access (1) mssql (13) mysql (2) open source (1) openvpn (1) pear (2) permissions (1) php (12) plesk (4) proxy (1) qr codes (1) rant (4) reflection (3) regex (1) replication (1) reporting services (5) security (2) signalr (1) sql (11) sqlce (1) sqlexpress (1) ssis (1) ssl (1) stuff (1) svn (2) syntax (1) tablet (2) telnet (3) tools (1) twitter (1) unix (3) vb script (3) vb.net (9) vba (1) visual studio (2) vpc (2) vpn (1) windows (4) woff (1) xbox 360 (1)