﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Amriteshwar Singh  / Using SQL Management Objects to create and restore SQL Databases. / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Tue, 21 May 2013 16:59:48 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Using SQL Management Objects to create and restore SQL Databases.</title><link>http://www.sqlservercentral.com/Forums/Topic518770-1319-1.aspx</link><description>- Nice intro to SMO for this purpose.- Keep in mind, you have to inspect the .bak files content. They may contain more than one backup.- You can even perform point in time restores using smoIf you add default location registry keys for your SQLInstance, you can even extract this info to automate your procedure.[code]-- ALZDBA-- Add default Data- and LogFile locations--USE [master]GODeclare @DataPath NVarchar(2000)Declare @LogPath NVarchar(2000)	EXEC xp_instance_regread N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'DefaultData', @DataPath OUTPUT	EXEC xp_instance_regread N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'DefaultLog', @LogPath OUTPUTprint @DataPathprint @LogPath-- activate to installIf 0 = 1begin	-- Adjust !!!	Select @DataPath = N'D:\MSSQL.1\MSSQL\Data'	-- Aanpassen !		 , @LogPath = N'D:\MSSQL.1\MSSQL\Data'	-- Aanpassen !	/* SQL2005 always use xp_instance_regwrite */		EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'DefaultData', REG_SZ, @DataPath		EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'DefaultLog', REG_SZ, @LogPathend/*-- find default backup directory (elaborate to find datadirectory-- activate cmdshell if disabledEXEC sys.sp_configure N'show advanced options', N'1'RECONFIGURE WITH OVERRIDE	declare @CmdShellSettingBefore table (cfgname varchar(128), minimum varchar(128), maximum varchar(128), config_value varchar(128), runvalue varchar(128))insert into @CmdShellSettingBefore	EXEC sys.sp_configure N'xp_cmdshell'if exists(select * from @CmdShellSettingBefore where cfgname = 'xp_cmdshell' and runvalue = '0')begin	EXEC sys.sp_configure N'xp_cmdshell', N'1'	RECONFIGURE WITH OVERRIDE	end-- Get Default-path declare @DefaultBackupDirectory nvarchar(512)exec master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer',N'BackupDirectory', @DefaultBackupDirectory OUTPUTPrint 'Default BackupDirectory for instance [' + @@servername + '] = ' + @DefaultBackupDirectory-- disable cmdshell if it was originaly disabledif exists(select * from @CmdShellSettingBefore where cfgname = 'xp_cmdshell' and runvalue = '0')begin	EXEC sys.sp_configure N'xp_cmdshell', N'0'	RECONFIGURE WITH OVERRIDE	end*/[/code]</description><pubDate>Thu, 19 Jun 2008 02:21:25 GMT</pubDate><dc:creator>ALZDBA</dc:creator></item><item><title>RE: Using SQL Management Objects to create and restore SQL Databases.</title><link>http://www.sqlservercentral.com/Forums/Topic518770-1319-1.aspx</link><description>Nice article ........</description><pubDate>Thu, 19 Jun 2008 00:48:28 GMT</pubDate><dc:creator>Anipaul</dc:creator></item><item><title>RE: Using SQL Management Objects to create and restore SQL Databases.</title><link>http://www.sqlservercentral.com/Forums/Topic518770-1319-1.aspx</link><description>Good article.  Where can I get a list of all the objects, properties, and methods?We recently installed a new drive on one of our SQL boxes.  The boss was moving databases by detach, move file, reattach.  I showed him a trick for moving files to new  location using T-SQL in 4 lines (found it here).  He got out a text editor and whipped up a script to do the rest.  I was thinking about a "point-and-click" program to do the mundane sort of thing like that.  Maybe these SMO objects could be the answer rather than my usual trick of writing Dot Net code that generates T-SQL statements and shoving them at the server.</description><pubDate>Wed, 18 Jun 2008 15:41:22 GMT</pubDate><dc:creator>Charles Kincaid</dc:creator></item><item><title>Using SQL Management Objects to create and restore SQL Databases.</title><link>http://www.sqlservercentral.com/Forums/Topic518770-1319-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/articles/SMO/63126/"&gt;Using SQL Management Objects to create and restore SQL Databases.&lt;/A&gt;[/B]</description><pubDate>Wed, 18 Jun 2008 00:19:53 GMT</pubDate><dc:creator>Amriteshwar Singh</dc:creator></item></channel></rss>