Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Backup SQL Server Database using FoxPro SQL Pass Through

Status
Not open for further replies.

carolx

Programmer
Jul 22, 2003
75
0
6
JM
Hi Forum good evening.

Please help me figure out what is happening here.

If I run the database backup Stored Procedure in the query window using: exec [Sundries].[MCRevenueBackupSP] "C:\Marshall\" it completes ok.

If I run the FoxPro SQL Pass Through it doesn't complete successfully. The return value is -1

See file attached with the code.
 
 https://files.engineering.com/getfile.aspx?folder=757e30bd-7b95-46b3-8011-f41501a1d68f&file=Backup_SQL_Database_using_FoxPro_SQL_Pass_Through.txt
Yo are correctly testing for a return value of -1 from SQLEXEC(). But you also need to check the actual error number returned from SQL Server. To do that, call AERROR() when lnReturn = -1. That will produce an error array. The array should contain 1526 in its first element, to indicate a remote data error. The third and fifth elements respectively will then contain the SQL Server error message and the SQL server error number. That information will help you identify the cause of the problem.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
You make me wonder whether SQLEXEC does not work here as it works synchronously and would hit a timeout, this returning -1 as the server didn't yet finish and reports back success, but the backup actually does not fail.

Anyway, I'd recommend not doing backups from within the application, as y backup only works nicely without any connection, the SSMS query window does work while it also has a connection, so I'm not 100% sure, but in your application triggered backup you'll usually have several connections, that differs. I have maintained application which did the backup as last step when quitting. That worked, but even in that case I changed it to doing backups from task schedulare programmed directly at the server, which works better. My 2 ¢.

Chriss
 
Do you have a good reason for initiating the backup from within your VFP code? Have you thought about doing the whole thing within SQL Server, perhaps by scheduling your backups via SQL Server Agent? That would be a matter of specifying your BACKUP DATABASE command as a job, and then setting a schedule for the job to be executed.

I've never actually done this, and there might be more to it than described here, but it would be worth considering.

(And it won't work if you are using SQL Server Express, as that doesn't support jobs.)

But, in any case, I think you should first try and identify the original error in your VFP code, using AERROR() as described above.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike Lewis said:
you should first try and identify the original error in your VFP code, using AERROR() as described above.
I second that. You might find a solution to keep the backup functionality within your application.

Anyway, as I already recommended using scheduled tasks or as Mike suggests SQL Server Agent, you get the advantage of doing a backup over night in a state without user connections, which surely is preferrable.

The reason I used and recommended scheduled tasks and not an SQL Server Agent job was for this being more than just a backup and being implemented in VFP, too, but true, SQL Server is a self contained solution that includes backup planning and other tasks. Also SQL Server Agent jobs can do more than backups, but are obviously limited to the database. Wait and see, the express versions gained a lot of the things that initially only were available in Enterprise versions. But you don't need to wait for BACKUPS in themselves, and Task Scheduler is free to use with any EXE or also batch file, which often is sufficient, too.

Chriss
 
It was a database permission problem. I included doing backups from task scheduling. Thanks for the suggestions. Carolx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top