I’m writing some tests with web driver. Each 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  DB_NAME set offline with rollback immediate";
        String reconct = "alter  DB_NAME set online";
        String restodb = "RESTORE  DB_NAME FROM DISK = '"+backupfile+"' WITH REPLACE,RECOVERY "  ;
        Class.forName(DBClass);
        connection = DriverManager.getConnection(DB_URLMaster);
        System.out.println(connection.toString()+"***********************");
        if (connection == null) {
            System.out.println("Data Base connection failed");
        }
        statement = connection.createStatement();
        statement.execute(discont);
        statement.execute(reconct);
        statement.execute(restodb);
        Thread.sleep(20000);


        }

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



Source link https://sqa.stackexchange.com/questions/35361/not--database-in-selenium-test

LEAVE A REPLY

Please enter your comment!
Please enter your name here