Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The code is working in Win Forms and not in ASPX.NET

Status
Not open for further replies.

majkinetor

Programmer
Feb 21, 2006
88
RS
I have this code
Code:
XmlValidatingReader	xvr = new XmlValidatingReader(reader);
xvr.ValidationType = ValidationType.Schema;
xvr.Schemas.Add(null, schemaName);

xvr.ValidationEventHandler += new ValidationEventHandler(xvr_ValidationEventHandler);

XmlDocument xdoc = new XmlDocument();
xdoc.Load(xvr);
And this code works in Win Forms app, but not in ASPX.NET. Also, the code worked yesterday in ASPX but not today.. I know what you think now... but this is one of those things that should work, but still doesn't for some strange reason.

I have this kind of code in my ASPX server code:

- verify xml (above code)
- open connection to database

Yesterday it worked, but not today.
Any comments ?
 
Did I mentioned that code is not changed ? No ?
Ok, here it is: "The code is not changed"

 
Are you opening any files, either from the local filesystem, or over a network?

Because the ASP.NET worker process has reduced permissions vs. something that runs as the logged-on user.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
2 all

First, I want to tell you that I am in programming more then 10 years and that I finished faculty of Math & Computer Science. I am tellilng you this so to know that I excellent understanding of most IT stuff, so to avoid trivial sugesstions, answers, propositions etc...

2 chiph
Yes, I am opeining files.
1. I upload xml file to server's Data Folder.
2. I open this file to find out its root element so to know which schema to load for validation
3. I use above code to load xml and validate it.

When I copy paste this part of code to Win Forms xvr_ValidationEventHandler is called for every error rised by validation process according to schema. I didn't use this procedure originaly but DataSet ability to load and check xml. But this didn't work in ASPX so I thought that there is some reason which I don't understant so I did find alternative code for this on CodeGuru. This code worked yesterday in both WinForms and ASPX.NET. I tested it with various non-valid xml inputs and all errors were detected. I had to restart my computer. After that, I got a message from VS that I don't have access to debug this project (but Conf->Debug->Debug ASPX is TRUE, serverl is localhost, IIS). The message was something like "You don't have privilegies or SQL Server is not alive". I searched MSDN for this error and it displayed bunch of things that can cause this, non of them to be common, like problem with some ports etc.... I didn't have time to anylise this and connection to database was in latter part of the code so I tried to find some workaround to be able to debug (restarting, changing some options back & forth, that kind of stuff, basicly nothing intellegent). I started to hit F11 on random and finally it passed ?!

From that momment it allow me to debug but every now and then it returns to previous behavior and "unfreeze" without me doing anything except hitting F11 over and over.. ?! Anyway, I suspect that this has to do something with XML validation passing without rising errors, don't ask me why. I also guess that somehow ASPX user account has to something with my debug problems but what is the trigger for this behavior I don't know.

The strange thing I noticed is this: first time when SqlConnection.Open rised error that I don't have debug privilegies I noticed that XML validation didn't work correctly. Since I first validate and then open connection to transmit this data do database, I didn't figure out why is XML validation affected with this error, because when it did allow me to connect to database without debuging errors XML suddenly started to work like it should (no code is ever changed here). Then, after system was reset, everything is not working again.... after some time VS allows me to debug but XML validation is still not working.

That is all, explained step by step.

I can captiure my debug session to video if you can obtain more information that way.

2NeilTrain
No errors... non valid XML pass validation and in latter code when I acces its elements and write info in database everything seems normal... except that I have problems with invalid XML fields.

Thank you all very much if you are willing to investigate this with me, I am really confused with this.

Info about my system:

- Dell 2x3GHz Intel CPU, 1GB RAM
- Windows XP SP1 + hotfixes up to date
- IIS 5.1
- VS 2003
- SQL Sever 2000
- Loged as domain user
 
Very interesting thing people...

When I comment this line

xvr.ValidationEventHandler += new ValidationEventHandler(xvr_ValidationEventHandler);

unhandled exception is rised witch report problems found using schema !!

So, the solution to my problem is merely to use
try
xdoc.Load(xvr);
catch ...

instead using handler to catch validation errors.

But, the question still remains... why first code works in Win Forms and doesn't in ASPX.NET (counting the fact that it worked before). Why do I have to use try catch in ASPX instead handler...

This is the code for handler:
Code:
private void xvr_ValidationEventHandler (object sender, ValidationEventArgs args)
{
			
   lblStatus.Text = "\r\n\tValidation error: " + args.Message ;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top