【发布时间】:2020-09-28 05:50:17
【问题描述】:
我有一个 Visual Studio (2008) c# 应用程序,我注意到在使用数据表适配器时它会保持数据库连接打开,直到应用程序关闭或大约 5 分钟的空闲时间过去。
我创建了一个简单的测试应用程序,除了 TableAdapter.Fill 之外没有其他任何东西 然后我在我的填充命令周围添加了一个 connection.open 和一个 connection.close ,但没有任何区别。
如果我无法强制关闭连接,是否可以将此超时缩短为 30 秒?
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();
}
}
}
【问题讨论】:
-
@mahesh_b 我认为情况正好相反。他的查询运行时间过长,连接超时。在我用完之后,我的仍然保持打开状态。
-
我正在尝试检查您提出的关于缩短适配器超时的问题!
-
@manesh,我想你误解了我的问题,但没关系。感谢您对它的破解:)
标签: c# visual-studio