Having trouble closing crystal reports connection
-
I don't know if this is the correct place to post this but I didn't see any Message Board for Crystal Reports. I am using the Crystal reports version that comes with Visual Studio 2002. I have my reports opening in a separate form. The reports work fine but when I close the form it seems like the connection used by crystal reports is still open because I cannot do anything to my database. Sometimes it times out and sometimes I need to restart my program to release the connection. How do I close the connection between crystal reports and the database? I've been searching online and haven't found very much on this. Thanks.
-
I don't know if this is the correct place to post this but I didn't see any Message Board for Crystal Reports. I am using the Crystal reports version that comes with Visual Studio 2002. I have my reports opening in a separate form. The reports work fine but when I close the form it seems like the connection used by crystal reports is still open because I cannot do anything to my database. Sometimes it times out and sometimes I need to restart my program to release the connection. How do I close the connection between crystal reports and the database? I've been searching online and haven't found very much on this. Thanks.
How are you filling your
ReportDocument
? If you're using aDataSet
then you're responsible for closing your connections. TheDataAdater
derivatives likeOleDbDataAdapter
andSqlDataAdapter
do this manually but with connections you have to close them (or dispose them using theusing
block statement in C#). This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Customer Product-lifecycle Experience Microsoft [My Articles] [My Blog] -
How are you filling your
ReportDocument
? If you're using aDataSet
then you're responsible for closing your connections. TheDataAdater
derivatives likeOleDbDataAdapter
andSqlDataAdapter
do this manually but with connections you have to close them (or dispose them using theusing
block statement in C#). This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Customer Product-lifecycle Experience Microsoft [My Articles] [My Blog] -
I'm not using a dataset I made the connection using the Report Expert using the OleDb Connection. I am connecting to an access database.
So then the other thing I mentioned is still valid: dispose your connection. The C#
using
block statement is handy for that:using (OleDbConnection conn = new OleDbConnection("..."))
{
OleDbCommand cmd = conn.CreateCommand("...");
// ...
}This will make sure the connection is closed. If you don't want to close and re-open the connection all the time, defined your
OleDbConnection
as a field and in yourForm
'sDispose
override callDispose
on your connection field inside theif
block (that's where you free mananaged objects; outside the condition - so that it always runs - you free native resources like window and file handles). This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Customer Product-lifecycle Experience Microsoft [My Articles] [My Blog]