Jump to content

SQL server restore database command


Recommended Posts

Hi friends,

I want to restore/replace a full database using restore command. The following code I use executes with no error.

But I can't see the restored database from SQL server management studio. Refreshing the databases,restaring the management studio and restarting the system didn't help.I use windows authentication to login to SQL Server.

The restore script is auto generated from Sql Server management studio and it is working correctly when executed from the management studio.

#RequireAdmin
$objSQLDMO = ObjCreate("SQLDMO.SQLServer")
If IsObj($objSQLDMO) Then
    $objSQLDMO.LoginSecure = True
    $objSQLDMO.Connect("(local)","","")
Else
    Msgbox(0,"Error","SQL Enterprise Manager has not been installed on this computer")
EndIf
$strSQLScript="RESTORE DATABASE [ERP] FROM  DISK = N'C:\backupfile.bak' WITH  FILE = 1,  MOVE N'DynamicST' TO N'c:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\ERP.mdf',  MOVE N'DynamicST_log' TO N'c:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\ERP_1.ldf',  NOUNLOAD,  REPLACE,  STATS = 10"
$objSQLDMO.ExecuteImmediate($strSQLScript,0)
$Restored =0
for $lDB in $objSQLDMO.Databases
    if $lDB.Name = "ERP" Then
        msgbox(0,"Done","Restored successfully")
        $Restored =1
        ExitLoop
    EndIf
Next
if $Restored =0 then msgbox(0,"failed","Restore failed.")

Please help.

Edited by PoojaKrishna
Link to comment
Share on other sites

I'm sorry to say I've no clue about what your actual issue is.

I'm still curious about what you say about the script generation: does Sql Server management studio (I guess is an MS product) really generate native AutoIt scripts or does it merely (more likely) generate the MSSQL restore statement?

Are you sure there isn't a registered COM error handler active in your application, which silently ignores some COM error in the course of actions?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Hi jchd,

Thanks for you reply. The Sql statement/script, I used to restore is generated with the MS product SQL Server Management studio.

There were no COM or any other error occured while executing the script. I get the restored database in the $objSQLDMO.Databases list, so I'm sure that it is restored. But I don't get the databases name in the management studio listing.

If I execute the sql script directly from the management studio, then the restored database is listed with the management studio also.

Regards,

Pooja.

Link to comment
Share on other sites

Thanks for clarifications. Sorry I'm unfamiliar with your context and see no clear relation with anything AutoIt can solve by itself, as the COM interface seems to be doing its job without problem. Maybe asking the question in a MsSQL centric forum would turn up more relevant answers.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...