本文整理汇总了C#中SqlDatabase.TestConnection方法的典型用法代码示例。如果您正苦于以下问题:C# SqlDatabase.TestConnection方法的具体用法?C# SqlDatabase.TestConnection怎么用?C# SqlDatabase.TestConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SqlDatabase
的用法示例。
在下文中一共展示了SqlDatabase.TestConnection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnTest_Click
/// <summary>
/// Click event for Test button
/// </summary>
/// <param name="sender">sender</param>
/// <param name="e">e</param>
protected override void btnTest_Click(object sender, EventArgs e)
{
string database = this.cmbServerName.Text;
Epi.Data.SqlServer.SqlDatabase db = new SqlDatabase();
//db.ConnectionString = this.DbConnectionStringBuilder.ToString();
dbConnectionStringBuilder = new System.Data.SqlClient.SqlConnectionStringBuilder();
dbConnectionStringBuilder.DataSource = cmbServerName.Text;
dbConnectionStringBuilder.InitialCatalog = cmbDatabaseName.Text;
dbConnectionStringBuilder.UserID = txtUserName.Text;
if (rdbWindowsAuthentication.Checked)
{
dbConnectionStringBuilder.IntegratedSecurity = true;
}
else
{
dbConnectionStringBuilder.UserID = txtUserName.Text;
dbConnectionStringBuilder.Password = txtPassword.Text;
}
db.ConnectionString = this.DbConnectionStringBuilder.ToString();
try
{
if (db.TestConnection())
{
MessageBox.Show("Connection OK!"); // TODO: hard coded string.
}
else
{
MessageBox.Show("Connection failed."); // TODO: hard coded string.
}
}
catch (Exception ex)
{
MessageBox.Show("Connection failed: " + ex.Message); // TODO: hard coded string
}
}