在远程 SQL Server Express 上备份数据库
我需要创建一个 TSQL 脚本来备份远程 SQL Server Express (2005) 上的数据库。我的另一个盒子上有一个 SQL Server 2005。不知道如何从 SQL Server 2005 运行脚本来完成备份作业。
该脚本是这样的:
RESTORE DATABASE [myDB] FROM DISK = N'C:\Tmp\myDB.bak' WITH FILE = 1,
NOUNLOAD, STATS = 10
实际上,我使用 SQL Server Management Studio Express 在远程 SQL Server Express 上尝试了此 SQL 脚本,并且运行正常。我问这个问题的原因是我可以在 SQL Server 2005 上调度作业,但无法在远程 SQL Server Express 上创建调度作业。
我认为另一种方法是首先在 SQL Server Express 上创建 SQL SP。然后,我将编写一个简单的控制台应用程序来连接到 SQL 并将 SP 作为 Windows 计划作业运行。
I need to create a TSQL script to backup a db on a remote SQL Server Express (2005). I have a SQL Server 2005 on another box. Not sure how I can run the script from this SQL Server 2005 to do the backup job.
The script is something like this:
RESTORE DATABASE [myDB] FROM DISK = N'C:\Tmp\myDB.bak' WITH FILE = 1,
NOUNLOAD, STATS = 10
Actually, I tried this SQL script on the remote SQL Server Express by using SQL Server Management Studio Express and it runs OK. The reason I ask this question is that I can schedule a job on SQL Server 2005, but I cannot create a schedule job on the remote SQL Server Express.
Another way, I think, is to create a SQL SP on the SQL Server Express first. Then I'll write a simple console application to connect to the SQL and run the SP as a Windows Scheduled job.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TSQL 不需要这样做。 SQL Server(也称为 Express)包含一个名为 sqlmaint.exe 的实用程序,它允许您在本地或远程 SQL Server 上执行备份操作。只需编写一个使用正确命令行参数调用 sqlmaint 的批处理文件 (文档)并将此批处理文件放入 Windows Scheduler 中。
如果你仍然想通过TSQL来完成,SQL Server还包含osql.exe,它允许你在本地或远程服务器上执行任意SQL语句。同样,您可以使用简单的批处理文件将其自动化。
编辑:如果您想使用自己的应用程序调用 TSQL 脚本,了解您选择的编程语言或数据访问技术可能会有所帮助。
There is no need to do this by TSQL. SQL Server (also Express) includes a utility called sqlmaint.exe, which allows you to perform backup operations on a local or remote SQL server. Simply write a batch file calling sqlmaint with the correct command line parameters (documentation) and put this batch file in Windows Scheduler.
If you still want to do it by TSQL, SQL Server also contains osql.exe, which allows you to execute arbitrary SQL statements on a local or remote server. Again, you can automate it using simple batch files.
EDIT: If you want to call the TSQL script using your own application, it might be helpful to know about your programming language or data access technology of choice.