[Collapse]TestComplete How To
 [Expand]Microsoft Office
   Add records to an SQL table/viewarticle/9013/
   Call an SQL Stored Procedure/viewarticle/9014/
   Create an SQL Stored Procedure/viewarticle/9025/
   Create and drop SQL databases/viewarticle/8968/
   Create SQL tables/viewarticle/9007/
   Drop an SQL Stored Procedure/viewarticle/9026/
   Drop SQL tables/viewarticle/9008/
   Files in SQL tables (read and write)/viewarticle/8969/
   Get all databases' names /viewarticle/17636/
   Update records in SQL tables/viewarticle/18441/
 [Expand]TestComplete Utility Scripts
 [Expand]Third-party Controls
 [Expand]Web Utility Scripts
 [Expand]Windows Utility Scripts
Updated: 4/24/2012 Applies To: TestComplete Rating: GoodGoodGoodGoodGood 1 vote(s) Click to rate: PoorNot badAverageGoodExcellent
Create and drop SQL databases

The script demonstrates how to create or drop an SQL database from script.

VBScriptCopy Code

Sub Test
  Dim i, databaseName, commands, cmd
  databaseName = "TestDatabase"
  commands = Array("CREATE DATABASE " & databaseName,_
                   "DROP DATABASE " & databaseName) 
  commands(commands.length) = "CREATE DATABASE " + databaseName
  commands(commands.length) = "DROP DATABASE " + databaseName
  Set cmd = ADO.CreateADOCommand
  cmd.ConnectionString =_
        "Driver={SQL Server};Server=SERVER_NAME;Uid=USER_NAME;Pwd=PASSWORD"
  cmd.CommandType = cmdText
  i = 0
  While i < UBound(commands) + 1
    Cmd.CommandText = commands(i)
    Call Cmd.Execute
    i = i + 1
End Sub

JScriptCopy Code

function Test()
  var databaseName = "TestDatabase";
  var commands = new Array();
  commands[commands.length] = "CREATE DATABASE " + databaseName;
  commands[commands.length] = "DROP DATABASE " + databaseName;
  // Create a new object
  var Cmd = ADO.CreateADOCommand();
  // Specify the connection string
  Cmd.ConnectionString =_
        "Driver={SQL Server};Server=SERVER_NAME;Uid=USER_NAME;Pwd=PASSWORD";
  // Specify the command type
  Cmd.CommandType = cmdText;
  for(var i = 0; i < commands.length; i++) {
    // Specify the command text (an SQL expression)
    Cmd.CommandText = commands[i];
    // Execute the command

© 2020 SmartBear Software. All rights reserved.
Email Send feedback on this document