Forum Discussion

mnichola30's avatar
mnichola30
Occasional Contributor
14 years ago

SQL Database Validation

The sofware that I'm testing creates a new SQL database with a unique name everytime the software is run.  I would like to create a script that validates the tables within each new database.  Is it possible to validate a database with a dynmic name? 



Thanks,



Melissa

3 Replies

  • karkadil's avatar
    karkadil
    Valued Contributor
    The following code will list all existing databases on the server



    //[JScript]

    function Test1()

    {

      var cmd = ADO.CreateADOCommand();

      cmd.ConnectionString = "Provider=SQLOLEDB.1;Data Source=MY-PC\\SQLEXPRESS;user id=MY_LOGIN;pwd=MY_PASSWORD;Integrated Security=SSPI;";

      cmd.CommandText = "EXEC sp_databases";

      cmd.CommandType = cmdText;

      var rs = cmd.Execute();

      rs.MoveFirst();

      while(!rs.EOF)

      {

        Log.Message(rs.Fields("DATABASE_NAME").Value);

        rs.MoveNext();

      }



    }



    All you need to do is to get a list of all databases before your application create a new one, then once again after it and compare results :)

    The difference will be a new created database.



    And you need to use a correct command line to your server, of course
  • Hi all,


    We are also planning to publish a similar script in the How To section of our Support Portal.