/// <summary>
/// Integrated Security connection string
/// </summary>
public const string ConnectionString = "data source=localhost;initial catalog=DatabaseName;integrated security=SSPI;persist security info=False;packet size=4096";
/// <summary>
/// SQL Security connection string
/// </summary>
public const string ConnectionString2 = @"data source=localhost;initial catalog=DatabaseName;persist security info=False;user id=sa;packet size=4096";
private void Global_Load(object sender, System.EventArgs e)
{
try
{
//先采用windows认证方式(安全性高,适用于windows2000,xp),失败则执行catch{}
cnn.ConnectionString = ConnectionString;
cnn.Open();
}
catch
{
try
{
//采用SQL Server Security验证用户身份(适用于win98,2000,xp)
cnn.ConnectionString = ConnectionString2;
cnn.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}