在插入之前验证(Sql)TableAdapter连接

时间:2014-04-19 16:31:04

标签: c# sql-server-2008-r2 .net-4.5 tableadapter

我的应用程序从仪器收集数据(用于测试试验)并将其存储到数据库中。

在允许数据采集之前,如何确认我的(Sql)TableAdapter可以连接到数据库?

private void ARM_btn_Click(object sender, EventArgs e)
{
    try
    {
        /* ??? */
        this.trialTableAdapter.CHECK_FOR_VALID_CONNECTION();
        /* ??? */

        this.myInstr.Setup(/*trial params, triggers, etc*/);
        this.myInstr.StartAcqNoWait();

    }
    catch
    {
        this.systemStatus_lbl.Text = "Error"; //TODO: more specific
        return;
    }

    this.systemStatus_lbl.Text = this.MSG_SYSTEM_READY_STR;
    return;

}

1 个答案:

答案 0 :(得分:0)

我最终使用了以下内容。随意提出一个“更好”的方法。

try
{
    this.trialTableAdapter.Connection.Open();
}

catch (System.Data.SqlClient.SqlException e)
{
    // TODO: Handle no DB connection
}
相关问题