SCOPE_IDENTITY across Linked Servers

You see…there’s this thing called “scope” and it apparently only applies to the server you’re calling SCOPE_IDENTITY from. Which does make sense in a “I just spent 3 hours fixing my code” kinda way. Wrote a few new stored procedures on the linked server that returned the identity as an output parameter, easy. Pain in the ass to figure out what was wrong to begin with.

Only thing it really teaches me: make sure to test the app the same way it’s going to be setup in the production environment.

10 Easy Arithmetic Tricks

From The List Universe. Where were these when I was in grade school! The first is by far my favorite:

1. The 11 Times Trick

We all know the trick when multiplying by ten – add 0 to the end of the number, but did you know there is an equally easy trick for multiplying a two digit number by 11? This is it:

Take the original number and imagine a space between the two digits (in this example we will use 52:

5_2

Now add the two numbers together and put them in the middle:

5_(5+2)_2

That is it – you have the answer: 572.

.NET 1.1 browserCaps

I’ve been working with a series of Panel controls to hide and show various sections of a page. Since I’m actively trying to validate the pages, fix errors, and make sure it looks the same between IE and Firefox I happened to notice that the Panel control rendered as a table in Firefox instead of div, which it does in IE. This, of course, pissed me off to no end. So I had to find out why.

It is all because of the wonderful machine.config browserCaps section…which has never been updated since the 1.1 framework was released. It controls if .Net uses the HtmlTextWriter (HTML 4.0) or the Html32TextWriter (HTML 3.2) based on the browsers user agent and some regex magic. Of course Firefox, pretty much all Gecko based browsers, and Apple’s Safari (AppleWebKit) are not included in any of the definitions so by default it uses the Html32TextWriter.

Through a little web searching I’ve found a good section to add into the web.config that adds support for Firefox.

Big thanks to Rob Eberhardt and Chris Maunder, Owen Brady and others

Code below just for my sanity.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<browsercaps>
 
	<!-- GECKO Based Browsers (Netscape 6+, Mozilla/Firefox, ...) //-->
	<!-- Edited by Owen Brady:6-12-05 -->
	<!-- Edited by Owen Brady:10-07-05 -->
	<case match="(Gecko/[-d]+)">
		browser="Mozilla"
		cookies="true"
		ecmascriptversion="0.0"
		frames="true"
		isColor="true"
		javaapplets="true"
		javascript="true"
		majorversion="${major}"
		maximumRenderedPageSize="20000"
		minorversion="${minor}"
		preferredImageMime="image/jpeg"
		screenBitDepth="32"
		supportsDivNoWrap="false"
		supportsFileUpload="true"
		tables="true"
		type="desktop"
		version="${version}"
		<filter>
			<case match="Gecko/(?'Gecko'd+)">
				BrowserBuild=${Gecko}
			</case>
		</filter>
		<filter>
			<case match="rv:(?'version'(?'major'd+)(?'minor'.[.|w]*))">
				majorversion="${major}"
				minorversion="${minor}"
				type="Mozilla${major}"
				version="${version}"
				ecmascriptversion="1.4"
				maximumRenderedPageSize="300000"
				preferredImageMime="image/gif"
				supportsCallback="true"
				supportsDivNoWrap="false"
				tagwriter="System.Web.UI.HtmlTextWriter"
				w3cdomversion="1.0"
				<filter>
					<case with="%{version}" match="^1.[4-9]">
						backgroundsounds="true"
						css1="true"
						css2="true"
						javaapplets="true"
						maximumRenderedPageSize="2000000"
						preferredImageMime="image/jpeg"
						screenBitDepth="32"
						supportsMultilineTextBoxDisplay="true"
						type="Mozilla${version}"
						xml="true"
					</case>
				</filter>
				<filter>
					<case match="Gecko/d+ Firebird/(?'version'(?'major'd+)(?'minor'.d+))|Gecko/d+ Firefox/(?'version'(?'major'd+)(?'minor'.d+))">
						backgroundsounds="true"
						css1="true"
						css2="true"
						javaapplets="true"
						maximumRenderedPageSize="2000000"
						preferredImageMime="image/jpeg"
						screenBitDepth="32"
						supportsMultilineTextBoxDisplay="true"
						xml="true"
						version=${version}
						majorversion=${major}
						minorversion=${minor}
					</case>
				</filter>
			</case>
			<case match="m(?'version'd+))">
				version=0.${version}
				majorversion=0
				minorversion=${version}
			</case>
		</filter>
		<filter>
			<case match="^Mozilla/5.0 Galeon/(?'version'(?'major'd+).(?'minor'd+).(?'revision'd+))">
				browser=Galeon
				version=${version}
				majorversion=${major}
				minorversion=${minor}
				revisionversion=${revision}
			</case>
			<case match="(Gecko/[-d]+)(?'VendorProductToken' (?'browser'[^/d]*)([d]*)/(?'version'(?'major'd+)(?'minor'.d+)(?'revision'.d+)(?'letters'w*)))">
				browser=${browser}
				version=${version}
				majorversion=0${major}
				minorversion=0${minor}
				revisionversion=0${revision}
			</case>
			<case match="(Gecko/[-d]+)(?'VendorProductToken' (?'browser'[^/d]*)([d]*)/(?'version'(?'major'd+)(?'minor'.d+)(?'letters'w*)))">
				browser=${browser}
				version=${version}
				majorversion=0${major}
				minorversion=0${minor}
			</case>
		</filter>
		<filter>
			<case match="Phoenix" with="%{browser}">
				browser="Firefox"
			</case>
			<case match="Firebird" with="%{browser}">
				browser="Firefox"
			</case>
			<case match="Mozilla Firebird">
				browser="Firefox"
			</case>
			<case match="(No IDN) Firefox">
				browser="Firefox"
			</case>
			<case match="Netscape6" with="%{browser}">
				browser="Netscape"
			</case>
			<case match="CS 2000 7.0" with="%{browser}">
				browser="CS 2000 7.0"
				version=7.0
				majorversion=7
				minorversion=0
			</case>
		</filter>
	</case>
 
</browsercaps>

ASP.Net DataGrid Sort Indicator

Talk about a pain. You’d think this would be easier….

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
private void Grid_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
	DataGrid grid = (DataGrid)source;
	grid.DataSource = CurrentView;
	bool isAsc;
	if (((DataView)grid.DataSource).Sort != e.SortExpression)
	{
		((DataView)grid.DataSource).Sort = e.SortExpression;
		isAsc = true;
	}
	else
	{
		((DataView)grid.DataSource).Sort += " DESC";
		isAsc = false;
	}
 
	//Loop columns to find sort
	foreach(DataGridColumn col in grid.Columns)
	{
		//Clear header of previous images
		col.HeaderText = col.HeaderText.Replace("<img src="http://john.rozeske.com/wp-admin/Images/SortDsc.gif" alt="Desc" class="sort" />","").Replace("<img src="http://john.rozeske.com/wp-admin/Images/SortAsc.gif" alt="Asc" class="sort" />","");
		// Find the right column
		if(e.SortExpression.ToLower().CompareTo(col.SortExpression.ToLower()) == 0)
		{
			if(isAsc)
			{
				col.HeaderText = col.HeaderText + "<img src="http://john.rozeske.com/wp-admin/Images/SortAsc.gif" alt="Asc" class="sort" />";
			}
			else
			{
				col.HeaderText = col.HeaderText + "<img src="http://john.rozeske.com/wp-admin/Images/SortDsc.gif" alt="Desc" class="sort" />";
			}
		}
	}
 
	//Bind the grid data
	grid.DataBind();
}

Digg & Reddit: Create and Submit Your Content. It’s Necessary

“I wrote recently about learning to differentiate between blogspam and self-submitted content on meritocracy-based sites like Digg and Reddit. My goal was to try and reverse the negative programming we all have towards reading self-submitted material. But this is not spamming.” dmiesler.com

A good counter point to self submitting articles. I’ll still wait until I write something worthwhile before submitting it myself…or I’ll just ask a friend to do it.

read more | digg story