Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > How to close database after using reportviewer? (C#)
 

How to close database after using reportviewer? (C#)

I create a report using ReportViewer tool and everything works fine until I close the form. When I do that and
choose another option of my main menu that involve the database I always received an error message that
the database cannot be opened.

Error Message says "System.Data.SqlClient.SqlException, Cannot open database..."

But if first I open a choice that do some work with the database and then call the form of my report everything works
fine.

I have this code on my report form:

namespace SACK
{
public partial class repProductos : Form
{
public repProductos()
{
InitializeComponent();
}

private void repProFecMov_Load(object sender, EventArgs e)
{
this.tProductosTableAdapter.Fill(this.PrintProductsDBDataSet.tProductos);

this.reportViewer1.RefreshReport();

this.tProductosTableAdapter.Connection.Close(); // ----> I TRY WITH THIS TO CLOSE THE CONNECTION BUT IT NOT WORKS.
}
}
}

thank you for any help!
Think left and think right and think low and think high. Oh, the things you can think up if only you try!
dgoldfeder  Sunday, August 09, 2009 6:41 PM
Just Found:

I found another post with some code on how to do this without the reportviewer code and here is the link

http://social.msdn.microsoft.com/Forums/en-US/vsreportcontrols/thread/c6524b68-bdfd-4f10-848f-355bc9445323

Think left and think right and think low and think high. Oh, the things you can think up if only you try!
  • Marked As Answer bydgoldfeder Monday, August 10, 2009 1:52 PM
  •  
dgoldfeder  Monday, August 10, 2009 1:52 PM
Just Found:

I found another post with some code on how to do this without the reportviewer code and here is the link

http://social.msdn.microsoft.com/Forums/en-US/vsreportcontrols/thread/c6524b68-bdfd-4f10-848f-355bc9445323

Think left and think right and think low and think high. Oh, the things you can think up if only you try!
  • Marked As Answer bydgoldfeder Monday, August 10, 2009 1:52 PM
  •  
dgoldfeder  Monday, August 10, 2009 1:52 PM

You can use google to search for other answers

Custom Search

More Threads

• DataGrid Paing
• Have I accidentally created multiple currency managers?
• How to retrieve auto-generated uniqueidentifier primary key after an insert
• How to store the database connection string?
• DataGridView Refresh issue
• Set the Default value for Combox present in DataGridview
• Nested dataGridView control with C#
• Datagridview and DefaultCellStyle precedence
• binding dataset to a datagrid
• DataGridBind to a BindingSource which contains custom class