Closed shirishnagarnz closed 5 years ago
@shirishnagarnz mstest v2 doesn't restrict you from connecting to a DB. you can connect to DB in the same way as you will do in a normal console app. The connection of DB code will vary from DB engine to engine. Search for samples on how to connect to DB via c# and you should find something
@shirishnagarnz as mentioned above, mstest v2 doesn't restrict you from doing that. Depending on the db you're planning to connect to it, you would have to use a specific library that help you doing that. There's a ton of example on the internet if you look for "how to connect to a sql database from c#".
Below is a short snippet that you could use right away to get connected to a SQL Server db:
var connectionString = "data source=YOUR_SQL_SERVER_NAME;initial catalog=YOUR_DB_NAME;persist security info=True;user id=USER_ID;password=PASS;MultipleActiveResultSets=True;";
using (SqlConnection con = new SqlConnection(this.ConnectionString))
{
using (SqlCommand command = new SqlCommand(queryStatement, connection)
{
connection.Open();
result = command.ExecuteReader();
connection.Close();
}
}
Of course, for the above code to work, you should have a SQL Server with a database on it. And the user/password part is optional, but you have to specify in the connectionString that you'd like to use WindowsAuth.
Hope it helps getting this resolved!
@shirishnagarnz I am closing the issue. If you have any other queries do open another issue
Description