I'm perplexed, puzzled and pooped. I'm writing a class that is instantiated in Global.ASAX (FX 1.1) which needs to read in both a schema and an XML file when the application starts. Sounds easy enough, right?
Not so fast!
Consider this line of seemingly innocent code (where name = “d:\inetpub\***\rules.xsd”):
fileStream = New IO.FileStream(name, IO.FileMode.Open)
That line generates:
Access to the path "D:\inetpub\***\Rules.xsd" is denied
Okay, sure, I could buy that. So let's so see. I'm not running in an impersonation context, so the context for accessing the file is NT Authority\Network Service...
Problem: Network Service has read permissions on that file... Hrmmm, I say. Hrmmmm. We then, let's try that with Impersonation turned on even though for the scope of Global.ASAX it shouldn't make a difference. Well with that turned on, I don't get the exception even though I should have. Its as if Global.ASAX just said “duhhh...“ The OnStart event dies and default.aspx's page_load fires. Nice.
I'm doing this on IIS6 in an MS Virtual Server 2005 session. This works on IIS5.1, of course. That's gotta mean its CAS that for IIS6 that's given me the problem, right? FX 1.1 and 2.0 are installed, the site is setup for ASP.NET 1.1
Any thoughts on this one?
There's an adage in Japanese that “even Monkeys fall from trees,“ roughly meaning that even experts sometimes make mistakes. From a design point-of-view, I usually try to use NVARCHAR instead VARCHAR by default mostly because assuming everything will representable in English forever seems terribly short-sighted to me. Having to go back and retrofit a database to accomodate a simple business need like being able to enter non-English data seems like saving pennies and spending dollars.
That said, I forgot how to do it. When you're inserting two-byte character data into a table, be sure preface it with an upper case 'N.' To wit:
create table dbo.sayings(id tinyint identity(1,1), saying_en varchar(255), saying_jp nvarchar(512))
go
insert into sayings(saying_en,saying_jp) values ('Even mokeys fall from trees','猿も木から落ちる')
insert into sayings(saying_en,saying_jp) values ('Even mokeys fall from trees',N'猿も木から落ちる')
select * from sayings saying for xml auto,root('sayings')
go
Yields:
<sayings>
<saying id="1" saying_en="Even mokeys fall from trees" saying_jp="????????" />
<saying id="2" saying_en="Even mokeys fall from trees" saying_jp="猿も木から落ちる" />
</sayings>
'nuff said?