Hi all, I need some advice, guidance and help with this problem.
With my application I am writing there is a need for the administrator to create a new project (database). Now I have written an Admin module for my app, and within this I want to allow the creation of this new database. However the new database I need to be a copy of the default database I supply with the app (this has no data, but does contain some 15 tables and 54 stored procedures, hence the reason why I am thinking its best to copy the default database and rename).
Now this is where I need help.... I think there is 2 ways I can acheive this:-
1) Detach the default database. Copy the .mdf and .ldf files and rename. Attach both the default database and the new database.
I have done the code for this, but this does seem like it would be quite to error trap i.e. if something happened with the copy I would need to ensure that the default database gets re-attached.
2) Is I could create a backup of the default database into a .bak and then just restore the backup into a new database. Which to be honest seems a better way to do this, especially as the default database structure will not change.
The only problem with this is I am unsure how to acheive this, code wise??
Just a bit of more info, the reason why I am creating seperate databases instead of including them in the same database and using different tables is that when the job / project ends the database will need to be electronically archived. And there is legal issues about storing different job / project data.
Anyway, sorry to go on but this is quite an important issue that I would like to do right.
Thanks in advance
Simon
With my application I am writing there is a need for the administrator to create a new project (database). Now I have written an Admin module for my app, and within this I want to allow the creation of this new database. However the new database I need to be a copy of the default database I supply with the app (this has no data, but does contain some 15 tables and 54 stored procedures, hence the reason why I am thinking its best to copy the default database and rename).
Now this is where I need help.... I think there is 2 ways I can acheive this:-
1) Detach the default database. Copy the .mdf and .ldf files and rename. Attach both the default database and the new database.
I have done the code for this, but this does seem like it would be quite to error trap i.e. if something happened with the copy I would need to ensure that the default database gets re-attached.
2) Is I could create a backup of the default database into a .bak and then just restore the backup into a new database. Which to be honest seems a better way to do this, especially as the default database structure will not change.
The only problem with this is I am unsure how to acheive this, code wise??
Just a bit of more info, the reason why I am creating seperate databases instead of including them in the same database and using different tables is that when the job / project ends the database will need to be electronically archived. And there is legal issues about storing different job / project data.
Anyway, sorry to go on but this is quite an important issue that I would like to do right.
Thanks in advance
Simon