Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get connect with DB in selenium MSTESTV2? #576

Closed
shirishnagarnz opened this issue Mar 5, 2019 · 3 comments
Closed

How to get connect with DB in selenium MSTESTV2? #576

shirishnagarnz opened this issue Mar 5, 2019 · 3 comments

Comments

@shirishnagarnz
Copy link

Description

As a part of my TCs, I want to get connect to DB and execute queries. Tried to find out references but didn't find much.
Is MSTESTV2 is supporting this? Is so, can someone please provide details to get connect DB while executing scripts in selenium?

For a defect specific to the MSTest V2 test framework, describe the issue you've observed.

@acesiddhu
Copy link
Contributor

@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

@parrainc
Copy link
Contributor

parrainc commented Mar 6, 2019

@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!

@acesiddhu
Copy link
Contributor

@shirishnagarnz I am closing the issue. If you have any other queries do open another issue

@microsoft microsoft locked as resolved and limited conversation to collaborators Apr 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants