473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Saving to XML file; something locks the file after first use; Any ideas?

I'm new to Crystal Reports, so this may be a dumb problem, but I just
can't figure it out.

Basically, I want to control the selected data in the C# code as
opposed to Crystal Reports (since SQL is truly for querying, and
Crystal Reports is more a reporting tool). The only way I've found to
do this so far is to execute my select in C#, then store to an XML
file, and then have the Crystal Report read the XSD and XML files.

However, I have a HUGE problem. I can only do this once (which works,
by the way), but then, something is locking the file, and I can no
longer access it. I can't delete it, and I can't write to it in my
code again. I close the document, but I'm not sure what else to do.
Even if I close out all applications (Visual Studio, Crystal Reports
XI, etc.), the file remains locked. The only way around it that I've
found is logging out and logging back in. Obviously, this is
unacceptable.

Ok, so here is my code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. CrystalDecisions.CrystalReports.Engine.ReportDocument doc = new
  3. CrystalDecisions.CrystalReports.Engine.ReportDocument() ;
  4.  
  5. doc.Load( @"C:\Development\CrystalReports\App1\CustomerProfile.rpt" ) ;
  6.  
  7. doc.SetDataSource( ds ) ;
  8.  
  9. string xsdFile =
  10. @"C:\Development\CrystalReports\App1\CustomerProfile.xsd" ;
  11. string xmlFile =
  12. @"C:\Development\CrystalReports\App1\CustomerProfile.xml" ;
  13.  
  14. ds.WriteXmlSchema( xsdFile ) ;
  15. ds.WriteXml( xmlFile ) ;
  16.  
  17. crystalReportViewer1.ReportSource = doc ;
  18. crystalReportViewer1.RefreshReport() ;
  19. crystalReportViewer1.Visible = true ;
  20.  
  21. doc.Close() ;
  22.  
  23.  
Does anyone have any idea what would be locking the XML file and why??
The XSD file can be written and rewritten, and it never becomes locked.
But the XML file does after running just once.

Any help is GREATLY APPRECIATED!!!

Feb 28 '06 #1
4 1832
On 28 Feb 2006 07:57:08 -0800, ch***********@gmail.com wrote:
I'm new to Crystal Reports, so this may be a dumb problem, but I just
can't figure it out.

Basically, I want to control the selected data in the C# code as
opposed to Crystal Reports (since SQL is truly for querying, and
Crystal Reports is more a reporting tool). The only way I've found to
do this so far is to execute my select in C#, then store to an XML
file, and then have the Crystal Report read the XSD and XML files.

However, I have a HUGE problem. I can only do this once (which works,
by the way), but then, something is locking the file, and I can no
longer access it. I can't delete it, and I can't write to it in my
code again. I close the document, but I'm not sure what else to do.
Even if I close out all applications (Visual Studio, Crystal Reports
XI, etc.), the file remains locked. The only way around it that I've
found is logging out and logging back in. Obviously, this is
unacceptable.

Ok, so here is my code:
[CODE SNIPPET]
Does anyone have any idea what would be locking the XML file and why??
The XSD file can be written and rewritten, and it never becomes locked.
But the XML file does after running just once.

Any help is GREATLY APPRECIATED!!!


Is the data you retrieve always in the same format?
If so, you could create an XSD within your project, create a class
instance of this XSD with the class which belongs to it, let the
adapter fill that class with data and only set the datasource for the
report:
Example:

DataSet oSet1 = null;
oSet1 = new RptTotalsQ(); // RptTotalsQ == XSD class
oAdap.Fill(oSet1,"RptTotalsQ"); // oAdap = SqlAdapter
oDoc = new MyReport(); // Report class
axCrystalActiveXReportViewer1.ReportSource = oDoc;

Hope it helps --> the Crystal KB contains some of these samples in
full BTW

greetz, Leon
Feb 28 '06 #2
I don't know how to create a class instance of an XSD (I've never
really used XSDs before). I'm assuming you mean to add the XSD file to
the VS solution, and then create a class instance, correct? How do I
create the class instance?

And thanks for the info. As soon as I figure out how to create the
class, I'll give this a try. It sounds like exactly what I want to do.

Thanks!

- thephatp

Feb 28 '06 #3
On 28 Feb 2006 08:44:30 -0800, "thephatp" <ch***********@gmail.com>
wrote:
I don't know how to create a class instance of an XSD (I've never
really used XSDs before). I'm assuming you mean to add the XSD file to
the VS solution, and then create a class instance, correct? How do I
create the class instance?

And thanks for the info. As soon as I figure out how to create the
class, I'll give this a try. It sounds like exactly what I want to do.

Thanks!

- thephatp

Explanation:
http://msdn.microsoft.com/library/de...netdataset.asp

greetz.
Leon
Feb 28 '06 #4
I'm not sure why the file remains locked like that, but you are doing
one step more than you need to.

If you design your report using the data source "More Data Sources" ->
ADO.NET (XML), and then point it to the XSD that you already have, then
there's no need to dump the data into an XML file. You can feed the
data to Crystal directly from your ADO.NET DataSet, using the
SetDataSource exactly as you did.

Of course, you have to get the XSD from somewhere, so that
WriteXmlSchema() line is useful the first time you run the program.
However, after that you don't need it any more.

The only hitch with doing it this way (with no XML file) is that in the
report designer you see only the field names, not sample data.

Feb 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: simon place | last post by:
is the code below meant to produce rubbish?, i had expected an exception. f=file('readme.txt','w') f.write(' ') f.read() ( PythonWin 2.3 (#46, Jul 29 2003, 18:54:32) on win32. ) I got...
138
by: theodp | last post by:
--> From http://www.techdirt.com/articles/20040406/1349225.shtml Microsoft Patents Saving The Name Of A Game Contributed by Mike on Tuesday, April 6th, 2004 @ 01:49PM from the...
13
by: Stuart McGraw | last post by:
I haven't been able to figure this out and would appreciate some help... I have two tables, both with autonumber primary keys, and linked in a conventional master-child relationship. I've...
5
by: Thaynann | last post by:
I have an app that (at the moment) moves through files that are on a web site, and deletes them, wat i want to do for the next stage, is to be able to download each file before i delete it. i...
9
by: Tim_Mac | last post by:
hi, i'm not sure if i have chosen the best approach, but it seemed quite good to me. i have a collection class, containing business objects. the collection class is static and remains in-memory...
1
by: ABCL | last post by:
Hi All, I am working on the situation where 2 different Process/Application(.net) tries to open file at the same time....Or one process is updating the file and another process tries to access...
4
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my...
6
by: Jeff | last post by:
Hey (and thank you for reading my post) In visual web developer 2005 express edition I've created a simple website project.. At this website I want users who register to be able to upload a...
3
by: fperri | last post by:
I have a DB in Access 2002 that when it is ran on a few users computers in the company, they get the error that the file sharing lock count has been exceeded and to increase the max locks per file in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.