Thanks Jon,
It works well. I didn't create Sproc in the master. Instead I pass the 'restore ...' command with the SQLExec() call. But the idea is the same.
Thank you.
James
> Hi James,
> I have done this by creating an Stored Procedure in SQL and then call this SP from VFP.
> Run this in Query Analyser against Master.
> ----------------------------------------
> CREATE PROCEDURE resetdata
> @dbname varchar(20),
> @filename varchar(80)
> AS
> RESTORE DATABASE @dbname FROM DISK = @filename
> ----------------------------------------
> To call it form VFP do something similar to below;
> --------------------------------------------
> lcConnectString = "driver=SQL Server;server=ISC34;uid=sa;pwd=jon;Database=master;app='';Encrypt='';"
> lnConnectHandle = SQLSTRINGCONNECT(lcConnectString)
> cDatabase = "PPWin"
> cLocation = "c:\tmp\PPWin.Bak"
> lnresult = Sqlexec(lnConnectHandle, [EXEC resetdata ?cDatabase, ?cLocation])
> if lnresult < 0
> messagebox("Error Occurred with restore")
> else
> messagebox("Restore Complete")
> endif
> ----------------------------------------------
> You will need to change parts of this to make it work for you, but I hope it gives you an idea of how you can do it.
> I'm not sure if creating the SP against master is a good idea (my knowledge of SQL is limited) but this does work.
> Maybe somebody else can advise me on this?
> Hope this helps you.
> Jon
James Chan
ObjectMastery Pty Ltd