Here is my code:
public static string RexConnection = "Data Source=REX;" +
"user=mvois;password=" + Common.MVPass +
";database=AutoRex";
public static void ValidateSQL (string TC, string query, string field, string expected)
{
Report.Info ("Attemting to connect with: " + Common.RexConnection);
SqlConnection myConnection;
myConnection = new SqlConnection(Common.RexConnection);
try {
myConnection.Open();
SqlCommand myCommand = new SqlCommand(query, myConnection);
SqlDataReader myReader = myCommand.ExecuteReader();
if (myReader.Read()) {
string Actual = myReader[field].ToString();
if (Actual.Equals (expected))
Report.Success (TC + ": Actual value of " + field + ": " + Actual);
else
Report.Failure (TC + ": Actual value of " + field + ": " + Actual +". Expected: "+ expected);
}
myConnection.Close();
}
catch(Exception e)
{
Report.Warn (TC + ": DB access error: " + e.ToString());
}
}Check following link to see all details of Connection string:
http://msdn.microsoft.com/en-us/library ... tring.aspx