This is my own notes on doing optimistic concurrency checks with Linq to SQL in an ASP.NET application.
For total newbies there's a short intro to concurrency problems here
The docs about how to actually do the checks are pretty good IMHO:
Data Retrieval and CUD Operations in N-Tier Applications (LINQ to SQL)
Of course the simplest way of actually telling which version a database row is is the "rowversion" column type:
SQLServer docs on rowversion
Digging deeper, Linq to SQL is integrated with Transactions in .NET (and Windows):
Transactions and Linq to SQL
Thursday, December 3, 2009
Firefox slowness when developing ASP.NET apps
When using Firefox as the default web browser, and developing apps with the built in webserver in Visual Studio 2008 / 2005, then Firefox loads your app fuggin' slow ..
This problem has been around for ages - or atleast back to to Firefox 2.x.x days. It is caused by some interplay between Firefox's ipv6 support and the Microsoft's development web server (codename Cassini I think). Anyhow the solution is easy: disable ipv6 in Firefox (since at the time of writing ipv6 isn't used at all really this is a safe thing to do).
This problem has been around for ages - or atleast back to to Firefox 2.x.x days. It is caused by some interplay between Firefox's ipv6 support and the Microsoft's development web server (codename Cassini I think). Anyhow the solution is easy: disable ipv6 in Firefox (since at the time of writing ipv6 isn't used at all really this is a safe thing to do).
- Type "about:config" in the address bar in FF and press Enter.
- Answer yes to void your warranty in FF3.5 (you know what you're doing right?)
- Search / filter for "ipv6", then click on the option "network.dns.disableIPv6" to disable it (value true).
- Restart FF.
Color Schemes, Color Pickers and more
More useful links..
Color pickers online
Web Colors
ColorPicker.com
Color scheme web apps
Color Schemer
Color pickers online
Web Colors
ColorPicker.com
Color scheme web apps
Color Schemer
CSS articles on Smashing Magazine
Smashing magazine is one of the websites I kind of follow up on developments in web design, CSS etc. Here are a couple of useful articles I keep going back to.
The Mystery Of The CSS Float Property explains a lot of the common problems with the CSS box model and getting layouts to work.
From table hell to div hell , well the title says it all but it is an interesting read about the kind of problems a big pile of nested divs can cause, as with deeply nested tables used for layout.
The Mystery Of The CSS Float Property explains a lot of the common problems with the CSS box model and getting layouts to work.
From table hell to div hell , well the title says it all but it is an interesting read about the kind of problems a big pile of nested divs can cause, as with deeply nested tables used for layout.
Tuesday, December 1, 2009
Strange chars when forwarding mail from Microsoft Outlook
Here's a really odd problem I got the other day.
The problem
An web application I have been maintaining sent some mail to people in different countries, hence the mails contained characters like ä, é, č and so on and so forth.
Sending and receiving the mails was no problem at all. However, when some users tried to forward the emails using their mail client (Microsoft Outlook in this case) strange things would indeed happen.
Outlook would (unintentionally) insert a lot of random bytes at the start of the forwarded message, so it would look something like this :
厣叵卬向 ... etc etc.
Dear Customer etc etc.
I had a single ascx (ASP.NET web control) for each mail in each language. I would then use LoadControl(..) to render the correct mail as a string, and then do a few string.Replace(..)'s to insert various data into the mail-strings. I did not use plain HTML files for the mail "templates" because the ASP.NET process ran in medium trust which prevents file IO, and I didn't want another dependency on special config for making this work.
The solution
The whole issue was of course caused by an encoding error.
To solve the problem I had to do a couple of things for each of the .ascx files:
A Poem, by Microsoft Outlook 2007
Outlook inserted quite a few chinese letters at the start of the badly encoded mails. So what did they mean? Well, the wonder of Google's translation engine gave me the following little gem:
Dan Shen Yu
Say nothing of Jiuxi Bian Wei Xun
Jiaoqianqixiao Xifangyunjie
King Wu Chung
"tick"
luster of gems tumultuous
an opposite wave of A Brighter Summer Day
Ke Xiatiguke retention
Tally Wei-Qiang Dong Mi
Mi Mi coconut coconut soup
Mei drive industry
Jiu Zhi Tang
The problem
An web application I have been maintaining sent some mail to people in different countries, hence the mails contained characters like ä, é, č and so on and so forth.
Sending and receiving the mails was no problem at all. However, when some users tried to forward the emails using their mail client (Microsoft Outlook in this case) strange things would indeed happen.
Outlook would (unintentionally) insert a lot of random bytes at the start of the forwarded message, so it would look something like this :
厣叵卬向 ... etc etc.
Dear Customer etc etc.
I had a single ascx (ASP.NET web control) for each mail in each language. I would then use LoadControl(..) to render the correct mail as a string, and then do a few string.Replace(..)'s to insert various data into the mail-strings. I did not use plain HTML files for the mail "templates" because the ASP.NET process ran in medium trust which prevents file IO, and I didn't want another dependency on special config for making this work.
The solution
The whole issue was of course caused by an encoding error.
To solve the problem I had to do a couple of things for each of the .ascx files:
- The <head> section had to contain a <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/> tag.
- The .ascx file itself had to be saved as signed UTF-8 in Visual Studio: File->Advanced Save Options and choose Encoding.
- Finally, the Encoding property had to be set UTF-8 on the SmtpClient object used to send the mails.
A Poem, by Microsoft Outlook 2007
Outlook inserted quite a few chinese letters at the start of the badly encoded mails. So what did they mean? Well, the wonder of Google's translation engine gave me the following little gem:
Dan Shen Yu
Say nothing of Jiuxi Bian Wei Xun
Jiaoqianqixiao Xifangyunjie
King Wu Chung
"tick"
luster of gems tumultuous
an opposite wave of A Brighter Summer Day
Ke Xiatiguke retention
Tally Wei-Qiang Dong Mi
Mi Mi coconut coconut soup
Mei drive industry
Jiu Zhi Tang
Tuesday, September 22, 2009
Unexpected error 0x8ffe2740 occured + A solution
When you try to start a website in IIS you get a popup with error code 0x8ffe2740.
Surprisingly this problem can be caused by Skype having bound to TCP port 443. If this is the case simply go offline in Skype, start your website (should work now), and go online again in Skype.
I experienced the problem on this developer box: Windows XP Pro SP3, IIS 5, running a DotNetNuke 4.* site.
Diagnostics (how to figure it out)
The "System" log in Windows Event Viewer shows the following info:
Event ID: 115
Source: W3SVC (the WWW publishing service)
Description starts with "The service could not bind to instance 1 ..".
According to www.gafvert.info event ID 115 indicates that IIS cannot bind port 443 (the SSL/https port). Similarily there is another event ID 113. One possible reason for this error is of course that another process has already bound port 443.
A quick look in the TCPView tool reveals that Skype is listening to the "https" port, in other words Skype has bound port 443 (you can verify that this is the same port by unselecting "resolve addresses" in the "options" menu in TCPView).
The next logical step is then to make Skype close the port (by changing status to "Offline" in Skype), and trying to start the website again in IIS manager / MMC. Similarily this procedure can be used when other applications have stolen port 443.
Legal note: Skype is a registered trademark of Skype Limited, USA.
Surprisingly this problem can be caused by Skype having bound to TCP port 443. If this is the case simply go offline in Skype, start your website (should work now), and go online again in Skype.
I experienced the problem on this developer box: Windows XP Pro SP3, IIS 5, running a DotNetNuke 4.* site.
Diagnostics (how to figure it out)
The "System" log in Windows Event Viewer shows the following info:
Event ID: 115
Source: W3SVC (the WWW publishing service)
Description starts with "The service could not bind to instance 1 ..".
According to www.gafvert.info event ID 115 indicates that IIS cannot bind port 443 (the SSL/https port). Similarily there is another event ID 113. One possible reason for this error is of course that another process has already bound port 443.
A quick look in the TCPView tool reveals that Skype is listening to the "https" port, in other words Skype has bound port 443 (you can verify that this is the same port by unselecting "resolve addresses" in the "options" menu in TCPView).
The next logical step is then to make Skype close the port (by changing status to "Offline" in Skype), and trying to start the website again in IIS manager / MMC. Similarily this procedure can be used when other applications have stolen port 443.
Legal note: Skype is a registered trademark of Skype Limited, USA.
Friday, September 18, 2009
C# to VB.NET and vice versa
In my current work I do a lot of development in VB.NET. But being a sworn C# guy I sometimes get lost trying to find the right syntax for how to do a special cast or somesorts in VB.NET. Luckily there are some great resources on the 'net which covers most differences in the languages syntax wise:
The VB.NET and C# Comparison covers a lot of territory and is a great reference if you already known C# or VB.NET well but have to do some work in the other language. An truly useful reference for me.
The .net code converter let's you type in syntactically correct statements in your 'own' language, then automatically convert them to equivalent VB.NET (or C# if you're a VB.NET developer by heart). Great stuff!
The VB.NET and C# Comparison covers a lot of territory and is a great reference if you already known C# or VB.NET well but have to do some work in the other language. An truly useful reference for me.
The .net code converter let's you type in syntactically correct statements in your 'own' language, then automatically convert them to equivalent VB.NET (or C# if you're a VB.NET developer by heart). Great stuff!
Thursday, September 17, 2009
Reset identity seed in SQLServer 2005/2008
Resetting a primary key's identity seed is something I do from time to time when testing out tables where the primary key is typically along the lines of
IMHO the most common way of doing this is the using the DBCC command:
This will ensure the next generated identity value is one. Personally is do this after deleting all the test data in the table:
Thanks to TakeNote... for refreshing my memory on this (there are lot's of other forum/blog posts on the 'net about this same issue of course).
Update 2009-09-18
Inserting explicit values for identity columns can also be very useful. Credits to Pinalkumar Dave's blog for this useful information:
Use this before the SQL statements which insert values into the identity column(s) of your table:
And then this statement to set things back to normal afterwards:
ID int primary key identity(1,1)
IMHO the most common way of doing this is the using the DBCC command:
DBCC CHECKIDENT('MyTableName', RESEED, 0)
This will ensure the next generated identity value is one. Personally is do this after deleting all the test data in the table:
delete from MyTableName
Thanks to TakeNote... for refreshing my memory on this (there are lot's of other forum/blog posts on the 'net about this same issue of course).
Update 2009-09-18
Inserting explicit values for identity columns can also be very useful. Credits to Pinalkumar Dave's blog for this useful information:
Use this before the SQL statements which insert values into the identity column(s) of your table:
set identity insert <table name> on
And then this statement to set things back to normal afterwards:
set identity insert <table name> off
Finding desktopmodules from tabid in DotNetNuke
This works in atleast DotNetNuke 4.*:
Here is a useful SQL query I made for finding which modules (in the DotNetNuke "DesktopModules" directory) are on a given tabID. Please note that I only ever run this query manually in SQL Server Management Studio, it's not used in code:
Simply change the "where" accordingly. Similarily by replacing the where-clause with ..
.. you find the tabdID's where said module is used.
Here is a useful SQL query I made for finding which modules (in the DotNetNuke "DesktopModules" directory) are on a given tabID. Please note that I only ever run this query manually in SQL Server Management Studio, it's not used in code:
select *
from dnn_TabModules tabmods INNER JOIN dnn_Tabs tabs ON tabmods.TabID = tabs.TabID
INNER JOIN dnn_Modules mods ON tabmods.ModuleID = mods.ModuleID
INNER JOIN dnn_ModuleDefinitions moddefs ON mods.ModuleDefID = moddefs.ModuleDefID
INNER JOIN dnn_DesktopModules dtmods ON moddefs.DesktopModuleID = dtmods.DesktopModuleID
where tabs.TabID = 123
Simply change the "where" accordingly. Similarily by replacing the where-clause with ..
where FolderName = 'SomeDesktopModule'
.. you find the tabdID's where said module is used.
Wednesday, September 9, 2009
ASP.NET CustomValidator not shown in ValidationSummary
The problem
This is a really annoying "feature" in ASP.NET 2.0 which thankfully has a simple solution. The problem is that a ValidationSummary control won't show error messages from CustomValidators on the page. All other validators display as they should in the validationsummary, but not the custom validators.
A solution
Ensure that you set the CustomValidator's ErrorMessage property. Other controls will display fine in the validation summary if only their Text property is set, but the in the case of the CustomValidator you have to set the ErrorMessage property. IMHO all validation controls should only have an ErrorMessage property and not the misleading Text property, but that of course is another matter entirely.
For some reason I can't seem to set the ErrorMessage properties using resourcekey attributes in aspx/ascx files only, I don't know why this is. So in the case of CustomValidators I set their ErrorMessage properties in code, eg in Page_Load.
Other comments
I'm assuming the validationsummary is ShowSummary="true" and DisplayMode="list". Using validationgroups is ok if necessary but not mandatory.
This is a really annoying "feature" in ASP.NET 2.0 which thankfully has a simple solution. The problem is that a ValidationSummary control won't show error messages from CustomValidators on the page. All other validators display as they should in the validationsummary, but not the custom validators.
A solution
Ensure that you set the CustomValidator's ErrorMessage property. Other controls will display fine in the validation summary if only their Text property is set, but the in the case of the CustomValidator you have to set the ErrorMessage property. IMHO all validation controls should only have an ErrorMessage property and not the misleading Text property, but that of course is another matter entirely.
For some reason I can't seem to set the ErrorMessage properties using resourcekey attributes in aspx/ascx files only, I don't know why this is. So in the case of CustomValidators I set their ErrorMessage properties in code, eg in Page_Load.
Other comments
I'm assuming the validationsummary is ShowSummary="true" and DisplayMode="list". Using validationgroups is ok if necessary but not mandatory.
Tuesday, September 8, 2009
ASP.NET Validation controls and RESX-files
When using ASP.NET validator controls together with .resx resource files you must set their Text property, not their ErrorMessage property. Atleast on my system.
E.g. if my aspx/ascx file contains a line like:
<asp:RequiredFieldValidator ID="myValidator" resourcekey="myValidator" ..etc.. />
Then the corresponding resource (.resx) values must be:
"myValidator.Text" "My failed validation message"
Using "myValidator.ErrorMessage" instead of "myValidator.Text" will not work.
E.g. if my aspx/ascx file contains a line like:
<asp:RequiredFieldValidator ID="myValidator" resourcekey="myValidator" ..etc.. />
Then the corresponding resource (.resx) values must be:
"myValidator.Text" "My failed validation message"
Using "myValidator.ErrorMessage" instead of "myValidator.Text" will not work.
Monday, June 29, 2009
Show validation summary only in ASP.NET 2.0 pages
How to show validation summary only in ASP.NET 2.0 pages (note to self):
and
<asp:ValidationSummary ID="myValidationSummary" ShowSummary="true" .. etc .. />
and
<asp:RegularExpressionValidator ID="someValidator" ErrorMessage="errmsg" Display="None" .. etc .. />
Subscribe to:
Posts (Atom)


