Showing posts with label createanother. Show all posts
Showing posts with label createanother. Show all posts

Monday, March 12, 2012

How to duplicate a database?

Hi:
I have a database for my asp.net application and now I want to create
another database with everything same, including the data, except the
database name(this database will be used by another asp.net application).
How can I do this programmingly? I am using C#.
Thank you very much!
Quentin H.You can restore from a recent backup and specify the new name. Also, you can
detach, copy the mdf file, and then re-attach under a new name. How to do
this from C# ? You could use data management objects (DMO), but I would
suggest just writing a stored procedure and calling the SP from C#.
"Quentin Huo" <q.huo@.manyworlds.com> wrote in message
news:%23QcXgaiZFHA.3328@.TK2MSFTNGP09.phx.gbl...
> Hi:
> I have a database for my asp.net application and now I want to create
> another database with everything same, including the data, except the
> database name(this database will be used by another asp.net application).
> How can I do this programmingly? I am using C#.
> Thank you very much!
> Quentin H.
>|||Thank you for your quick reply!
Also, I want to ask how I can do if I want to duplicate the database, but
without any data. Do I need to use DMO? I tried this before by DTS, but
everytime when I did this, some definition of fields were changed. For
example, there is a field named "adddate" which default value is
"getDate()". However, after I duplicate it from DTS, the default value
(getdate()) was lost. Maybe I lost something when I did DTS?
Thanks
Q.
"JT" <someone@.microsoft.com> wrote in message
news:%23fQMymiZFHA.3364@.TK2MSFTNGP12.phx.gbl...
> You can restore from a recent backup and specify the new name. Also, you
> can
> detach, copy the mdf file, and then re-attach under a new name. How to do
> this from C# ? You could use data management objects (DMO), but I would
> suggest just writing a stored procedure and calling the SP from C#.
> "Quentin Huo" <q.huo@.manyworlds.com> wrote in message
> news:%23QcXgaiZFHA.3328@.TK2MSFTNGP09.phx.gbl...
>|||The easiest way of doing this is the restore from a recent backup ! You
can restore from a backup using DMO or TSQL with ADO !
Your best bet if you use DTS is to use copy object job. Try the copy
database wizard and reuse the DTS made by it !
Pollus Brodeur