I'm writing some tests with selenium web driver. Each test has to go through different data sets. Hence decided to re-install pre-defined databases for relevant tests.

Wrote a method as below

    private static String DBClass = "com.microsoft.sqlserver.jdbc.SQLServerDriver";

    public static void DB_restore(String backupfile) throws Exception {
        String discont = "alter database DB_NAME set offline with rollback immediate";
        String reconct = "alter database DB_NAME set online";
        String restodb = "RESTORE DATABASE DB_NAME FROM DISK = '"+backupfile+"' WITH REPLACE,RECOVERY "  ;
        connection = DriverManager.getConnection(DB_URLMaster);
        if (connection == null) {
            System.out.println("Data Base connection failed");
        statement = connection.createStatement();


But this did not worked. But further investigation found it actually installed database but still keeping old database some how.

When I manually restart IIS server, (after above code) everything works fine

but if I re-installed database using SQL_server management studio, web-driver connected to newly install database right-away.

What is the logic behind this?............. How can I avoid re-starting IIS?

I'm running on IIS 10.0.16299, SQLServer 2012, sqljdbc42.jar


Selenium doesn't work on databases. The below link describes selenium in extensive details. https://w3c.github.io/webdriver/

Coming to the problem you are facing, the solution lies in your problem statement itself. Please write a service/API to start the IIS server(that you are doing manually) and embed that in the beforeSuite method. Then proceed ahead with your tests.

Please share more insights on your work in case you want to find out the cause of the problem.

  • Agreed that selenium is not doing anything in database. .....still I don't get the answer. why it happens in test? not when I do manually. I do not think it is a rare case testers re-install databases for different data sets. So are rest of tester always restart web-server? or am I doing something wrong? – 1234 Aug 28 '18 at 0:09
  • reinstalling db for every data set is a terrific idea but restarting the web-server is a very common phenomenon. You might need re-install db only when it is required (for different release, when there is db schema change etc.). Please share more insight on your work so that we can dig further to investigate the root cause. – Kshetra Mohan Prusty Aug 28 '18 at 5:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.