July 4, 2005 at 3:57 am
I learned the little I know about this from looking at the scripts created by Redgate SQL Compare. I think this is one of the quicker ways to learn - the scripts are not perfect but they are better than I could write myself, the concepts are portable and you can edit anything you like before running.
It's a good tool, will help you rollback or exit if things fail, and I think they do a free trial. I wouldn't be without it now, and it was not expensive.
HTH
Bill.
July 4, 2005 at 5:05 am
The only way I know to do this is to create a temporay table (#temp) at the start of the batch, and after every DML/DDL statment check the @@Error system variable. If > 0, delete the #temp table. Then after each GO, check if #temp still exists. (if Object_id('tempdb..#temp') > 0) If it doesn't, return.
here's a little test script
--create table #temp(id int)
--drop table #temp
if Object_id('tempdb..#temp') > 0
print 'there'
else
print 'not there'
HTH
Dave J
July 5, 2005 at 1:47 pm
Thanks a lot !
I am still confused that why sometimes after executing sp_attath_single_file_db,the database status could be "Offline".In my understanding,the database should be "Online"
July 6, 2005 at 4:55 am
Is it still firing up? Try adding a small waitfor delay '00:00:30' after
July 6, 2005 at 8:56 am
![]()
The problem occurs at times. Last time when it occured,I checked the log message and found after waiting for 10 minutes, the database is still offline .But I can manually set it online via EM in no time.
July 6, 2005 at 9:39 am
what command is EM using? Capture the command in Profiler.
Then put that in your script if it errors?
July 6, 2005 at 12:49 pm
Hi Noel, many thanks for your help!
Yes. I have made the change to alter database online after attaching it.
And until now I have not reproduced this problem. Since this issue was not always reproducable before ,it's hard to say this is the final resolution. I hope it is !
This issue is so strange and inconsistent ,I really want to figure out the root cause. But I get lost.
July 6, 2005 at 1:11 pm
I am pretty sure with that is not going to happen again but just for curiosity how were you doing the detaching of it ?
* Noel
July 6, 2005 at 2:50 pm
Three steps.
1.Set database offline (Clear connections)
2.Detach database
3.Delete mdf and ldf files.
I used to use drop command .Later on I found it can not fit all situations.For example, if database doesn't exist in system tables while database file exist in dest directory(for example,after uninstalling the sqlserver)
July 6, 2005 at 4:07 pm
some how the OFFLINE status is definetly being kept in master I can't figure out a possible scenario but you should look at the steps you are taking very carefully. I know this does not helps but just to give you some feed back ![]()
* Noel
Viewing 11 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply