Forum Discussion

DKumar04's avatar
DKumar04
Contributor
6 years ago

Unable to connect to my local db

Error thrown when I am trying to restore my local DB using ADO object available in Testcomplete

 

Here is my full script

(Written in Jscript)

var con,query,result;
  con=ADO.CreateADOConnection();
  
  con.ConnectionString = "Provider=SQLNCLI11;Server=mylocalserver;Database=MyLocalDB;Integrated Security=True;DataTypeCompatibility=80;Uid=sa;Pwd=123123;";
  
  con.Open();
  query=ADO.CreateADOQuery();
  query.SQL="RESTORE DATABASE MyLocalDB FROM DISK = 'C:\\Test\\TestsBackup\\Data\\DB\\MyLocalDB.bak' WITH REPLACE";
  query.Active=con;
  result=query.ExecSQL();
  con.Close();

 When executing throws an below error,

 

 

 

5 Replies

  • anupamchampati's avatar
    anupamchampati
    Frequent Contributor
    For restoring the database you must switch first to master db than only restore will work and current script seems to be trying to connect to same db
    best way you can use sqlcmd by creating sql file to restore database and run it from batch cmd
    add that batch file in the testcomplete.
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    a) The message does not say that ADO cannot connect to the database. It says that the system is out of resources. It's better to reboot.

    b) ADO Query object assumes that a recordset is returned, while your SQL will not return a recordset. Not sure about ADO wrapper in TestComplete, but in 'pure' ADO you should use Command object instead of Recordset in this case.

     

    • TanyaYatskovska's avatar
      TanyaYatskovska
      SmartBear Alumni (Retired)

      Thanks for sharing your suggestions, Alex.

      DKumar04, did Alex reply help you overcome the error message? If it did, please accept his reply as a solution.

      • DKumar04's avatar
        DKumar04
        Contributor

        Thanks for the post Alex. 

        Still issue not sorted out.

        Please post me the JScript for restoring my local db