SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[adminAddNodeGrande]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[adminAddNodeGrande]
GO

create procedure dbo.adminAddNodeGrande
        @pProjectName varchar(30),
        @pEnvironment varchar(30),
        @pServerName varchar(60),
        @pDatabaseName varchar(30),
        @pVssShare varchar(255),
        @pWorkingFolderRoot varchar(255)
as
declare	@procedureName varchar(100),
	@returncode int

set nocount on

begin transaction

set @procedureName = db_name() + '.' 
		+ user_name(objectproperty(@@procid,'OwnerId')) 
		+ '.' + object_name(@@procid)


-- Add project to the control database
exec @returncode = Admin.dbo.adminAddProject @pProjectName, @pVssShare
if @@error <> 0 or @returncode <> 0
	goto ErrorHandler

-- Make sure all the environments are there
exec @returncode = Admin.dbo.adminAddAllEnvironments
if @@error <> 0 or @returncode <> 0
	goto ErrorHandler

-- Add server to the control database
exec @returncode = Admin.dbo.adminAddServer @pServerName,@pWorkingFolderRoot
if @@error <> 0 or @returncode <> 0
	goto ErrorHandler

-- Add database to the control database
exec @returncode = Admin.dbo.adminAddDatabase @pDatabaseName
if @@error <> 0 or @returncode <> 0
	goto ErrorHandler

-- Add SourceSafe project node for this server
exec @returncode = Admin.dbo.adminAddProjectNode @pProjectName, @pEnvironment, @pServerName, @pDatabaseName
if @@error <> 0 or @returncode <> 0
	goto ErrorHandler

commit transaction
return

ErrorHandler:
select * from activitylog
where activityDate > dateadd(mm,-10,getdate())
rollback transaction
raiserror(59000,16,1,@procedureName)
return -1

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

