I'm running into an issue when I try to run a simple Selenium script which has field (SSN), and on every new run of the script SSN need to has bigger value (+1). Is it possible Selenium to connect with SQL Server database and check the SSN value from there, and what is the code to connect Selenium with SQL Server database? I am using Selenium with C#. Many Thanks.
1 Answer
public static int SSN_DB(IWebDriver session, string connString) {
//creating a db connection connection
var DBConnection = new SqlConnection(connString);
DBConnection.Open();
// Can execute a query or store procedure
var MemTable = new SqlCommand();
MemTable.CommandText = "Select top 1 SSN from dbo.member order by EMPL desc";
MemTable.Connection = DBConnection;
var dr = MemTable.ExecuteReader();
var Memberid = 0;
while (dr.Read()) {
Memberid = dr.GetInt32(0);
Console.WriteLine(Memberid);
}
return Memberid;
}
}
1 Comment
Maris
SqlConnection have to used in scope of using, otherwise you will endup with memory leak!!!