Showing posts with label restore. Show all posts
Showing posts with label restore. Show all posts

Wednesday, March 7, 2012

Close existing connection before deleting/restore database

I want to be able to force a restore or a delete on a database even if there still have some active connections. In SQL Server management studio there is a checkbox when you're trying to delete a database to "Close existing connection" i want to do the same thing but using SMO. How can i do this ?

ThankHi,

see my blog entry here:

http://sqlserver2005.de/SQLServer2005/MyBlog/tabid/56/EntryID/9/Default.aspx

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

Saturday, February 25, 2012

Clone DB

Helloo

Can I backup DB programatically, and then restore it with different name also programatically?

meaning:
I have db2006, can I backup this db then restore it as db2007 programatically?using a stored procedure for example?

So by doing this the user will be using db2007 @. the begininng of the year and so on each year

I'm using sql2000

Please I need your help
Thank you

hi,

you can use sp_attach and sp_detach.

notice you can attach it with different db_name

Examples

EXEC sp_detach_db 'pubs', 'true'

copy the files and attach it with different dbname

EXEC sp_attach_db @.dbname = N'pubs1', 

@.filename1 = N'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf',

@.filename2 = N'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs_log.ldf'

|||

Thank you for your reply

but I had explained in a wrong way

I need to create a dublicate for this database programatically
meaning if i have db2004, I need to create db2005 programatically same as db2004(tables and procedures, only structure)

Is that possible?

thank you

|||

you can right click the database in the Enterprise manager or management studio

and clcik on task>generate scripts

|||

Look into the smo objects in books online. You could probably build a program to do this pretty easily to script out the database, create a clone database, and apply the script.

If this is a production database, if you have maintain scripts of the database, that is probably the best way to go, just by applying the scripts (but that takes a good amount of discipline on all developers, which can be hard to maintain depending on corporate culture)

Friday, February 10, 2012

clearing connection with SQLDMO

Hello, I use VS.NET and SQLDMO to do some administrative tasks.
I need to restore a database, but in some case some connections remains in
my soft even after closing them. This prevent restoration of the database.
I want to clear these connection, so I need to do the same thing that the
clear button do in the detach database window (in enterprise
manager/databases/.../all task/detach database)
SylvainKILL <spid>
David Portas
SQL Server MVP
--
"Sylvain Provencher" <sylvain.provencher@.nobelia.com> wrote in message
news:OV5oCYHxFHA.908@.tk2msftngp13.phx.gbl...
> Hello, I use VS.NET and SQLDMO to do some administrative tasks.
> I need to restore a database, but in some case some connections remains in
> my soft even after closing them. This prevent restoration of the database.
> I want to clear these connection, so I need to do the same thing that the
> clear button do in the detach database window (in enterprise
> manager/databases/.../all task/detach database)
> Sylvain
>|||Yes, but how can I get list of process to know which to kill ?
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:Lu2dnd1AebDajabeRVnygg@.giganews.com...
> KILL <spid>
> --
> David Portas
> SQL Server MVP
> --
>
> "Sylvain Provencher" <sylvain.provencher@.nobelia.com> wrote in message
> news:OV5oCYHxFHA.908@.tk2msftngp13.phx.gbl...
>|||I found sp_who to get this info
"Sylvain Provencher" <sylvain.provencher@.nobelia.com> wrote in message
news:%23p$MdQPxFHA.3856@.tk2msftngp13.phx.gbl...
> Yes, but how can I get list of process to know which to kill ?