110,534
社区成员
发帖
与我相关
我的任务
分享
string Connectionstring="Data Source={0};Initial Catalog={1};Persist Security Info=True;User ID={2};Password={3};Connection Timeout=5";
SqlConnection conn = new SqlConnection();
conn.ConnectionString = Connectionstring;
try
{
conn.Open();
MessageBox.Show("Connection Successful!", "Title", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (InvalidOperationException ex)
{ MessageBox.Show(ex.Message, "Title", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
catch (SqlException ex)
{ MessageBox.Show(ex.Message, "Title", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
finally
{ conn.Close(); }