tags:

views:

66

answers:

3

I get the following error when I execute SP in SQL Server 2008 Management Studio:

Msg 208, Level 16, State 6, Procedure BackupDB, Line 36

Invalid object name 'dbo.BackupDB'.

use [Master];
go
alter procedure dbo.BackupDB
    @dbName varchar(128),
    @path varchar(256)
as
begin
    declare @device1 varchar(256);
    declare @device2 varchar(256);
    declare @path1 varchar(256);
    declare @path2 varchar(256);
    declare @sql varchar(500);
    if @dbName is null or @path is null
     raiserror('Error: Database name and/or Path missing', 10, 1);
    if not exists(select * from sys.databases where name = @dbName)
     raiserror('Database %s does not exist', 10, 1, @dbName);
    begin
     set @sql = 'ALTER DATABASE ' + @dbName + '; SET RECOVERY FULL;';
     exec(@sql);
     set @device1 = @dbName + '_Data';
     set @device2 = @dbname + '_Log';
     set @path1 = @path + '\' + @dbname + '_Data.bak';
     set @path2 = @path + '\' + @dbname + '_Log.bak';
     print 'path :' + @path1;
     print 'path :' + @path2;
     exec sp_addumpdevice 'disk', @device1, @path1;
     exec sp_addumpdevice 'disk', @device2, @path2;

     backup database @dbName TO @device1;
     backup log @dbName TO @device2;
    end
end
go
A: 

It means that you haven't created the procedure. Run it again as CREATE PROCEDURE

erikkallen
Thanks, it works now. But I had created this SP and it did show up in the explorer in the studio, hen why does it throw this message?
DRags
Probably because you are not running the command in the same database as you are looking at (at at least that's why I get these all the time).
erikkallen
Also possibly it was not created as dbo. but some_other_schema.
Aaron Bertrand
A: 

Change:

alter procedure dbo.BackupDB

to:

create procedure dbo.BackupDB as
Blake Blackwell
Thank you. It works now.
DRags
A: 

Hey Now DRags,

The SP needs to be created. The top of the sp could be such as:

use [Master];
go
CREATE procedure dbo.BackupDB
--alter procedure dbo.BackupDB
@dbName varchar(128),
@path varchar(256)
as
begin

The Alter line is commented out. Then after your execute the procedure & create it you may comment out the create line & uncomment the alter line such as

use [Master];
go
--CREATE procedure dbo.BackupDB
alter procedure dbo.BackupDB

@dbName varchar(128),<br>
@path varchar(256)<br>

as
begin

Hope this helps,

Catto

Catto
Thank you. It works now.
DRags