Click here to Skip to main content
15,915,869 members
Home / Discussions / C#
   

C#

 
Questionbackup database [modified] Pin
farokhian13-Dec-09 18:36
farokhian13-Dec-09 18:36 
AnswerRe: backup database Pin
dan!sh 13-Dec-09 18:58
professional dan!sh 13-Dec-09 18:58 
GeneralRe: backup database Pin
farokhian13-Dec-09 19:17
farokhian13-Dec-09 19:17 
AnswerRe: backup database Pin
Vimalsoft(Pty) Ltd13-Dec-09 19:54
professionalVimalsoft(Pty) Ltd13-Dec-09 19:54 
GeneralRe: backup database Pin
farokhian13-Dec-09 22:15
farokhian13-Dec-09 22:15 
GeneralRe: backup database Pin
J4amieC13-Dec-09 22:27
J4amieC13-Dec-09 22:27 
GeneralRe: backup database Pin
farokhian13-Dec-09 22:49
farokhian13-Dec-09 22:49 
GeneralRe: backup database Pin
Vimalsoft(Pty) Ltd13-Dec-09 23:22
professionalVimalsoft(Pty) Ltd13-Dec-09 23:22 
Because there is no database with the name 'mydatabase' the syntax of the backup database is incorrect. Here are two Sp's use them

For Backup
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


-- backup a database
ALTER PROCEDURE [dbo].[sp_BackupDatabase]

	@databasename varchar(32),
	@path varchar(256),
	@filename varchar(64)

AS

set nocount on

declare @sql varchar(4000)

select @sql = 		'BACKUP DATABASE ' + ltrim(rtrim( @databasename ))
select @sql = @sql + 	'   TO DISK = ''' + ltrim(rtrim(@path)) + ltrim(rtrim(@filename)) + ''' '
select @sql = @sql + 	'   WITH INIT'
--print @sql
execute ( @sql )

select 'Database successfully backed up!' [Result]


and later you might want to Restore and you can use this

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go



ALTER PROCEDURE [dbo].[sp_RestoreDatabase] 

	@dbname char(32), 				-- the database name to restore as
	@filename char(64), @path char(256)		-- the location of the backuped up database file	(on the SQL Server)

AS

set nocount on

declare @sql nvarchar(3000)
 

-- Restore the database
select @sql = 			' RESTORE DATABASE ' + ltrim(rtrim( @dbname )) + ' FROM DISK = ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @filename )) + ''' ' 
select @sql = ltrim(rtrim(@sql)) + 	'    WITH '
select @sql = ltrim(rtrim(@sql)) + 	'    MOVE ''' + 'TNGoedit_Data' + ''' TO ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @dbname )) + '.mdf' + ''' , '	-- logical file name to physical name
select @sql = ltrim(rtrim(@sql)) + 	'    MOVE ''' + 'TNGoedit_Log' + ''' TO ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @dbname )) + '_log.ldf' + ''' '	-- logical file name to physical name
select @sql = ltrim(rtrim(@sql)) +  '    ,REPLACE,RECOVERY;'
--select @sql = ltrim(rtrim(@sql)) + 	'    MOVE ''' + ltrim(rtrim(@dbname)) + '_Data' + ''' TO ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @dbname )) + '.mdf' + ''' , '	-- logical file name to physical name
--select @sql = ltrim(rtrim(@sql)) + 	'    MOVE ''' + ltrim(rtrim(@dbname)) + '_Log' + ''' TO ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @dbname )) + '_log.ldf' + ''' '	-- logical file name to physical name
print @sql
execute ( @sql )

-- Was the command successful or was there a problem
if ( (select @@Error) = 0 ) begin
	-- Put an entry into oDirect.dbo.tbl_dbRef
	-- execute ( 'sp_DataSet_Save ''' + @xml + ''' ' ) 	

	-- TODO: restore the users

  select 'Restore Successful' [Result]
end
else begin
   select 'Restore Unsuccessful' [Result]
end


Vuyiswa Maseko,

Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.

C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/

Questionwhat is the diffrennce between String & string Pin
shabi uz zaman13-Dec-09 17:30
shabi uz zaman13-Dec-09 17:30 
AnswerRe: what is the diffrennce between String & string Pin
Abhinav S13-Dec-09 17:33
Abhinav S13-Dec-09 17:33 
AnswerRe: what is the diffrennce between String & string Pin
puri keemti13-Dec-09 21:07
puri keemti13-Dec-09 21:07 
QuestionWhat is the difference between static,readonly and constant ? Pin
md_azy13-Dec-09 16:16
md_azy13-Dec-09 16:16 
AnswerRe: What is the difference between static,readonly and constant ? Pin
EliottA13-Dec-09 17:22
EliottA13-Dec-09 17:22 
GeneralRe: What is the difference between static,readonly and constant ? Pin
Abhinav S13-Dec-09 17:28
Abhinav S13-Dec-09 17:28 
GeneralRe: What is the difference between static,readonly and constant ? Pin
dan!sh 13-Dec-09 17:33
professional dan!sh 13-Dec-09 17:33 
GeneralRe: What is the difference between static,readonly and constant ? Pin
Abhinav S13-Dec-09 17:35
Abhinav S13-Dec-09 17:35 
AnswerRe: What is the difference between static,readonly and constant ? Pin
puri keemti13-Dec-09 21:09
puri keemti13-Dec-09 21:09 
QuestionWhen we have to use abstract and when we have to use interface ? Pin
md_azy13-Dec-09 16:11
md_azy13-Dec-09 16:11 
AnswerRe: When we have to use abstract and when we have to use interface ? Pin
puri keemti13-Dec-09 21:15
puri keemti13-Dec-09 21:15 
AnswerRe: When we have to use abstract and when we have to use interface ? Pin
PIEBALDconsult14-Dec-09 6:24
mvePIEBALDconsult14-Dec-09 6:24 
QuestionHow to collect and download links with documents automatics? Pin
Member 216810313-Dec-09 11:15
Member 216810313-Dec-09 11:15 
AnswerRe: How to collect and download links with documents automatics? Pin
Mycroft Holmes13-Dec-09 13:50
professionalMycroft Holmes13-Dec-09 13:50 
GeneralRe: How to collect and download links with documents automatic? Pin
Member 216810311-Jan-10 23:04
Member 216810311-Jan-10 23:04 
QuestionMutiplication error? Pin
cgl3200013-Dec-09 6:45
cgl3200013-Dec-09 6:45 
AnswerRe: Mutiplication error? PinPopular
PIEBALDconsult13-Dec-09 6:47
mvePIEBALDconsult13-Dec-09 6:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.