It appears that the only way around this MAJOR BUG (I know, they call it a
security feature) is to pre-load the data into a dataset and set it as the
reports datasource. The big problem with this is that you need a typed
Dataset in your project & a bit of extra code to connect & fill the dataset.
For example, you add a new dataset item to your project.
Then you drag the table(s) you want to have in the report from the server
explorer onto your dataset design screen. Save when finished.
Now you can create your new report based on the dataset, (or change the
location on an old one). Just look for you dataset under the Project
Data->ADO.NET Datasets entry in the connection list. Make your report as
normal.
When you have the report ready, you will need to fill an in-memory dataset
variable with the actual data from the database and assign it as the
datasource for the report. (ie, YOU handle the database, NOT Crystal Reports)
Now you just set the reportsource of the viewer as normal.
Something like the following:
SqlConnection conn = new SqlConnection("Integrated Security=SSPI;Data
Source=<mydbserver>;Initial Catalog=<mydatabase>");
SqlDataAdapter adap = new SqlDataAdapter("SELECT * FROM <sometable>", conn);
MyTypedDataSet data = new MyTypedDataSet();
adap.Fill(data);
MyReport rpt = new MyReport();
rpt.SetDataSource(data);
ReportViewer.ReportSource = rpt;
All Done!
I know the forgetting of database connection details is supposed to be a
security feature, but I find it weird that it 'forgets' the information even
when there is no information to forget. I have tried this with a few
databases (Access file, SQL Server, text file) in secure & unsecure formats
(ie, with & without passwords) on window & web forms.
My discovery is that the web forms version of the reports WILL NOT connect
to ANY database of ANY type/status/location AT ALL. Hence I call this a MAJOR
BUG.
If anyone has managed to get the Crystal Reports components working (as
intended by the documentation) in a web application (we'll try web services
later) please tell us how you did it!!!