I have a Visual Studio (2008) c# application and I have noticed that it leaves the database connection open when using data table adapters until the application is closed or until around 5 minutes of idle time has passed.
I have created a bare bones test application with nothing else in there except a TableAdapter.Fill I then added a connection.open and a connection.close around my fill command but it didn't make any difference.
If I can't force the connection to close can I shorten this timeout to say 30 seconds?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DatabaseConnectionTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
//This line of code loads data into the 'insurvalDataSet.Building' table.
this.buildingTableAdapter.Connection.Open();
this.buildingTableAdapter.Fill(this.insurvalDataSet.Building);
this.buildingTableAdapter.Connection.Close();
}
}
}