Showing posts with label initial. Show all posts
Showing posts with label initial. Show all posts

Sunday, March 25, 2012

Automatically enable broker after restore or attach

Is there a way to automatically enable Service Broker on SQL Server 2005 Express Edition after a database has been attached or restored?
My initial idea was to check if broker is disabled whenever the client application starts and enable it from there but the problem with this is that the current user might not have the required permissions. So now I'm looking for another way to enable it right after restore/attach if at all possible. Any ideas would be appreciated.

Simplest approach would be to enabled it via a procedure that does have the appropiate permissions (using EXECUTE AS and code signing).

Other possiblity would be to create a server event notification and use an activate procedure in msdb to enable the database:

Code Snippet

use msdb;

go

create queue [dbevents]

create service [dbevents] on queue [dbevents] ([http://schemas.microsoft.com/SQL/Notifications/PostEventNotification]);

create event notification [dbbackuprestore]

on server for AUDIT_BACKUP_RESTORE_EVENT

to service 'dbevents', 'current database';

Sunday, February 12, 2012

auto increase text!

Hi,
I have an initial value like this:
'TEST0001'
I want to write a sql script that will automatically take that initial value
and keep adding 1 to it and insert into a table for me until it get to
'TEST9999'.
my table should now store:
TEST0001
TEST0002
...
...
TEST0010
TEST0011
...
...
TEST9999
How do I do this?
Thanks,
Tom ddeclare @.seed int
set @.seed = 1
while @.seed < 10000
begin
insert into tableName select 'TEST' + right('000' + cast(@.seed as
varchar(4)), 4)
set @.seed = @.seed + 1
end
"tom d" <tomd@.discussions.microsoft.com> wrote in message
news:1DB51C59-3F93-476E-91CE-6E7B4C7E7259@.microsoft.com...
> Hi,
> I have an initial value like this:
> 'TEST0001'
> I want to write a sql script that will automatically take that initial
> value
> and keep adding 1 to it and insert into a table for me until it get to
> 'TEST9999'.
> my table should now store:
> TEST0001
> TEST0002
> ...
> ...
> TEST0010
> TEST0011
> ...
> ...
> TEST9999
> How do I do this?
> Thanks,
> Tom d
>