Showing posts with label automated. Show all posts
Showing posts with label automated. Show all posts

Thursday, March 29, 2012

Automation of Excel to SQL Server 2005

Hi all,

I have a task which needs to be automated.

1) Excel spreadsheet load into sql server database as a table.

2) Then , there will be some quering of data joining this table ( imported from excel) with other tables.

3) Then, output should be back into excel spreadsheet.

All these steps 1,2,3 need to be automated.

Could anybody give me the different steps(if not,, any links which guide me doing so), for doing this and any pre setup required for this.

Thanks for all your help..

You can do this using distributed quires...

Here the sample,

Code Snippet

--To fetch the data from the Excel

select * from

OpenDataSource('Microsoft.Jet.OLEDB.4.0',

'Data Source="c:\book1.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...[Sheet1$]

--To store the data back to the Excel

insert into

OpenDataSource('Microsoft.Jet.OLEDB.4.0',

'Data Source="c:\book1.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...[Sheet1$]

Values('11','Name11')

Tuesday, March 27, 2012

Automating backups with TSM

I was wondering if anyone can share the procedure(s) used in setting up an automated MS SQL database backup through tivoli Storage Manager
( 5.2.7 )........?I'd settle for getting Tivoli to back up files 50% or more of the time. I'd consider getting Tivoli to do reliable, repeatable backups to be a miracle.

-PatPsql

Tuesday, March 20, 2012

automatic restoration

any automated restoration script is available in sql server2000.
I want to do the restoration for 10 databases(full backup,latest differential backup) in other server.

Pls do the needful.

Quote:

Originally Posted by bharadwaj

any automated restoration script is available in sql server2000.
I want to do the restoration for 10 databases(full backup,latest differential backup) in other server.

Pls do the needful.


Try the following

use master
go
declare @.file varchar(200)
select @.file = 'c:\dbackup.backup'

declare @.mdf varchar(500), @.ldf varchar(500)
select @.mdf = 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\databasename.mdf'
select @.ldf = 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\databasename_log.ldf'

restore database <databasename>
from disk = @.file
with
move 'databasename' to @.mdf,
move 'databasename_Log' to @.ldf
go|||Thanks for ur reply.I will try it and let you know.
Bharat

Quote:

Originally Posted by Vidhura

Try the following

use master
go
declare @.file varchar(200)
select @.file = 'c:\dbackup.backup'

declare @.mdf varchar(500), @.ldf varchar(500)
select @.mdf = 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\databasename.mdf'
select @.ldf = 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\databasename_log.ldf'

restore database <databasename>
from disk = @.file
with
move 'databasename' to @.mdf,
move 'databasename_Log' to @.ldf
go

sql

Thursday, March 8, 2012

Automated testing | How to "force" GETDATE() function to return specific value?

Hello,

Our QA team have running a lot of test scripts (for automated regression
testing), they run them on the different databases (Oracle/MS SQL).
Several of those tests are dependent on the current date/time. In order to
be
able to use them efficiently, we changed the current date/time on the QA
database server to a specific date/time before starting the scripts, so we
are sure the test scripts always run in the same environment.

Resetting the date/time of the database server gives us more and more
problems (OS problems, backup/ virusscan, ...).

It is possible to fix the problem with SYSDATE function on Oracle by setting
FIXED_DATE init parameter.

Is it possible to 'change' the current date/time on 'database' level,
instead of on OS level for MSSQL2000?
Do you know other means to do such things?

Thanks in advance,

Konstantin"Konstantin Zakharenko" <kzakharenko@.infopulse.com.ua> wrote in message
news:bpt1s9$ctp$1@.snoopy.infopulse.com.ua...
> Hello,
> Our QA team have running a lot of test scripts (for automated regression
> testing), they run them on the different databases (Oracle/MS SQL).
> Several of those tests are dependent on the current date/time. In order to
> be
> able to use them efficiently, we changed the current date/time on the QA
> database server to a specific date/time before starting the scripts, so we
> are sure the test scripts always run in the same environment.
> Resetting the date/time of the database server gives us more and more
> problems (OS problems, backup/ virusscan, ...).
> It is possible to fix the problem with SYSDATE function on Oracle by
setting
> FIXED_DATE init parameter.
>
> Is it possible to 'change' the current date/time on 'database' level,
> instead of on OS level for MSSQL2000?
> Do you know other means to do such things?
> Thanks in advance,
> Konstantin

I don't know what FIXED_DATE does in Oracle - does it force SYSDATE to
return the same value every time it's called? If so, I don't believe there's
any way to do this in SQL Server. You could create your own function called
dbo.getdate(), and use that, but then it wouldn't be a valid test of your
'real' code.

In any case, it's not clear why you would want to always test with the same
datetime value - you wouldn't prove anything except that your code works
with one particular datetime, and that probably isn't desirable. It might be
better to put some work into establishing what the test results should be
for a given datetime input value, and validate your code that way.

If I've misunderstood, or if this doesn't help, perhaps you can clarify
exactly what you want getdate() to return, and how you want to use it.

Simon|||"Simon Hayes" <sql@.hayes.ch> wrote in message
news:3fc25218$1_3@.news.bluewin.ch...
> "Konstantin Zakharenko" <kzakharenko@.infopulse.com.ua> wrote in message
> news:bpt1s9$ctp$1@.snoopy.infopulse.com.ua...
> > Hello,
> > Our QA team have running a lot of test scripts (for automated regression
> > testing), they run them on the different databases (Oracle/MS SQL).
> > Several of those tests are dependent on the current date/time. In order
to
> > be
> > able to use them efficiently, we changed the current date/time on the QA
> > database server to a specific date/time before starting the scripts, so
we
> > are sure the test scripts always run in the same environment.
> > Resetting the date/time of the database server gives us more and more
> > problems (OS problems, backup/ virusscan, ...).
> > It is possible to fix the problem with SYSDATE function on Oracle by
> setting
> > FIXED_DATE init parameter.
> > Is it possible to 'change' the current date/time on 'database' level,
> > instead of on OS level for MSSQL2000?
> > Do you know other means to do such things?
> > Thanks in advance,
> > Konstantin
> I don't know what FIXED_DATE does in Oracle - does it force SYSDATE to
> return the same value every time it's called? If so, I don't believe
there's
> any way to do this in SQL Server. You could create your own function
called
> dbo.getdate(), and use that, but then it wouldn't be a valid test of your
> 'real' code.
> In any case, it's not clear why you would want to always test with the
same
> datetime value - you wouldn't prove anything except that your code works
> with one particular datetime, and that probably isn't desirable. It might
be
> better to put some work into establishing what the test results should be
> for a given datetime input value, and validate your code that way.
> If I've misunderstood, or if this doesn't help, perhaps you can clarify
> exactly what you want getdate() to return, and how you want to use it.
> Simon

Thank you for replay.

Yes. You are right. The FIXED_DATE lets you set a constant date that SYSDATE
will always return instead of the current date.

The main problem is that if you take a fixed test database, and run for
example a report, the output of that report can be (very) different if you
run this report today vs. the run you will do tomorrow vs. ... Other typical
example: our application (financial one) reacts differently if you want to
create some entities with dates in the past (different execution flow).

We are using Rational Robot in the automated testing. It validates that all
system reaction and outcome is identical to the reference run (verification
points). If the 'current date/time' is changed since the 'reference' run,
you get a lot of (unnecessary) errors/warnings and failed verification
points. That's why we need to run test scripts with specific datetime value.

Of course, automated tests are not intended to replace all other tests,
their purpose to supplement another tests. Automated test scripts are mainly
used for regression testing. Since it is very difficult and time-consuming
to make Robot test scripts time independent it is acceptable for us to
execute tests with fixed datetime.

Unfortunately, calling of new dbo.getdate() function will cause modification
of application. It is time-consuming and task. That's why our main goal is
to solve the problem by means of Oracle/MSSQL parameters. Moreover, your
solution with dbo.getdate() will not work in a case when we need correct
datetime (not fixed).

CREATE FUNCTION dbo.getdate()
RETURNS datetime AS
BEGIN
-- return cast ('2003-01-01' as datetime) -- It is OK.
return getdate() -- It is NOT OK.
END

The GETDATE() is a nondeterministic function and it is not allowed to use it
in user-defined functions.

If we will not solve the problem by configuring MSSQL database (I think it
is most likely) our solution will be to create the following view:

CREATE VIEW v_nondeterministic AS SELECT getdate() AS getdate;

And to use SELECT getdate FROM v_nondeterministic where required.

Best regards,

Konstantin

automated testing

Hi friends,
Are there any tools for automated testing on server side code on market?
Thanks a lot in advance
AlexFor load testing you can use Microsoft Application Center testing.
http://msdn.microsoft.com/msdnmag/i.../ExtremeASPNET/
/*
Warren Brunk - MCITP - SQL 2005, MCDBA
www.techintsolutions.com
Tech Blog - www.technologyis.com
*/
"Alex" <me@.isp.net> wrote in message news:8Wv0h.34950$H7.29278@.edtnps82...
> Hi friends,
> Are there any tools for automated testing on server side code on market?
> Thanks a lot in advance
> Alex
>|||We are using Winrunner and loadrunner
M A Srinivas
Alex wrote:
> Hi friends,
> Are there any tools for automated testing on server side code on market?
> Thanks a lot in advance
> Alex|||Look into 'datadude'...
http://blogs.msdn.com/rwaymi/
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf
"Alex" <me@.isp.net> wrote in message news:8Wv0h.34950$H7.29278@.edtnps82...
> Hi friends,
> Are there any tools for automated testing on server side code on market?
> Thanks a lot in advance
> Alex
>

automated testing

Hi friends,
Are there any tools for automated testing on server side code on market?
Thanks a lot in advance
AlexFor load testing you can use Microsoft Application Center testing.
http://msdn.microsoft.com/msdnmag/issues/05/06/ExtremeASPNET/
/*
Warren Brunk - MCITP - SQL 2005, MCDBA
www.techintsolutions.com
Tech Blog - www.technologyis.com
*/
"Alex" <me@.isp.net> wrote in message news:8Wv0h.34950$H7.29278@.edtnps82...
> Hi friends,
> Are there any tools for automated testing on server side code on market?
> Thanks a lot in advance
> Alex
>|||We are using Winrunner and loadrunner
M A Srinivas
Alex wrote:
> Hi friends,
> Are there any tools for automated testing on server side code on market?
> Thanks a lot in advance
> Alex|||Look into 'datadude'...
http://blogs.msdn.com/rwaymi/
--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf
"Alex" <me@.isp.net> wrote in message news:8Wv0h.34950$H7.29278@.edtnps82...
> Hi friends,
> Are there any tools for automated testing on server side code on market?
> Thanks a lot in advance
> Alex
>

Automated SQL Server Startup

Is there any way start a SQL Server database through a script and still
be able to administrate the server through EM? I have created a scripts
for shutting it down and e-mailing me, but I would like to automate
startup through a scheduled task as well.
Thanks...
NathanFigured it out net start...
doh.
nathan
none@.nnn.com wrote:

> Is there any way start a SQL Server database through a script and still
> be able to administrate the server through EM? I have created a scripts
> for shutting it down and e-mailing me, but I would like to automate
> startup through a scheduled task as well.
> Thanks...
> Nathan
>|||Hi,
I've created 2 batch file, startsql.bat and stopsql.bat. Each have 'net str
at mssqlserver' and net stop mssqlserver' for starting and stoppping the ser
ver. I schedule it in the Schedule (under control panel) by selecting to ru
n the program as startsql.b
at or stopsql.bat and the user id is my window administartor login id and p
assword. I waited and watched and nothing happen. What am I not doing corr
ectly? Is it the batch file or is it the schedule not done correctly? I am
running Window 2000 and SQ
L 2000
Thanks,
Alpha

automated sql injection detectors

anybody ever use any of these...
http://www.security-hacks.com/2007/05/18/top-15-free-sql-injection-scanners ?
thoughts? preferences?I have not used any of them. I think this kind of tool could be a good candidate for preliminary testing for vulnerabilities, but in general I have limited faith in automated testing because it limits itself to the logic implemented by the coder.

Automated SQL documenation?

I am an intern at a university and we are looking for a way to automatically document tables, queries, etc. ColdFusion is the platform used, and SQL Server 2000. Is there a way to have the documentation performed that will capture tables, constraints, etc.? I have found some, but so far, none are working. Please help if you can!!! :confused:SQLDMO would be my first choice, SQL-EM (Enterprise Mangler) would be a tolerable interface if you don't want to code your own.

-PatP|||ditto all 'dat

+

there are LOTS of sp_helpthisthatandwhatever you can use to get all that info if you're not a VB guy.
same stuff EM ends up using to populate its forms, but i like it mo' betta.|||What kind of documentation do you want? Relationships and dependencies and such? Who is the intended audience and what will they be doing with the information?|||I made it a habit to create data diagrams for every db I'm working with.

Automated script generation

I often create scripts from SQL Server 2000 Enterprise Mgr the same way: I select all tables, check Indexes, check Constraints, check Windows text, then I go. Is it possible to automate this task further, for example running the scripting from a Stored Proc?RE: I often create scripts from SQL Server 2000 Enterprise Mgr the same way: I select all tables, check Indexes, check Constraints, check Windows text, then I go. Is it possible to automate this task further, for example running the scripting from a Stored Proc?

Q1 Is it possible to automate this task further, for example running the scripting from a Stored Proc?

A2 Yes, though for some tasks (particularly with previous versions) you may have to use cursors.|||I could, fairly quickly, write a SP that reads some system tables and do the scripting I need itself.

But, is there some way to make Enterprise Mgr to do it, without really having to write a program?|||Originally posted by Coolberg
I could, fairly quickly, write a SP that reads some system tables and do the scripting I need itself.

Well, not quickly I realize, because I need to put the ALTER TABLE ... DROP CONSTRAINT statements in the proper order.
Or could I do a ALTER TABLE ... NOCHECK ALL on all tables...?

automated role creation

i seem to have some misunderstanding about how roles work in sql server
2005. i see that i can add a role to a database
(dbname->[right-click]->properties->permissions->[add ...]. THis allows
me to add either users or roles. Users can be added programmatically
using sp_grantdbaccess @.username, but this does not allow for addition
of roles to access the database (i.e., sp_grantdbaccess @.rolename does
not work).

Is there some other command that is used to add a role to the
database's permissions list? Seems there must be since all the other
parts of the permissions chain work quite well:
* sp_addrole
* sp_addrolemember
* grant <permissionon role::@.rolename
etc.

So the missing ingredient of something like sp_grantdbroleaccess is
what I need and can't seem to find it anywhere!

Thanks much for any helpYou create a role in the database then add users/roles to that role as
you say.

sp_grantdbaccess is used to allow users access to the database whereas a
role is a means of allowing permissions to be allocated to all users in
that role.

You can though administer via nt roles which may be the sort of thing
you are looking for.

www.nigelrivett.net
*** Sent via Developersdex http://www.developersdex.com ***|||cybertoast@.gmail.com wrote:

Quote:

Originally Posted by

i seem to have some misunderstanding about how roles work in sql server
2005. i see that i can add a role to a database
(dbname->[right-click]->properties->permissions->[add ...]. THis allows
me to add either users or roles. Users can be added programmatically
using sp_grantdbaccess @.username, but this does not allow for addition
of roles to access the database (i.e., sp_grantdbaccess @.rolename does
not work).
>
Is there some other command that is used to add a role to the
database's permissions list? Seems there must be since all the other
parts of the permissions chain work quite well:
* sp_addrole
* sp_addrolemember
* grant <permissionon role::@.rolename
etc.
>
So the missing ingredient of something like sp_grantdbroleaccess is
what I need and can't seem to find it anywhere!
>
Thanks much for any help


You should use the T-SQL syntax instead of the SPs whenever possible,
as SPs might get obsolete at some point.

Basically, here is a simple process to handle the users and roles.

1) Create a server-wide login:
create login user1 with password = '123';

2) Create the user in your database:
use database1;
create user user1;

3) Create a role in your database:
use database1;
create role role1;

4) Add the user to the role:
use database1;
exec sp_addrolemember 'role1','user1';

5) Give some permissions to the role:
grant control to role1;

Whenever you need to fine-tune the permissions, you just use the
"grant" keyword on the role.

Note: "grant control" gives all permissions on the database objects,
most of the time you should be more restrictive.

Regards,
lucm|||This sequence is fine, but the problem is that the "grant control to
role1" portion does not add the role to the database permissions list.
Perhaps this is just a bug in the way SQL Server Mgmt Studio displays
roles and users. For instance, when I do a "sp_grantdbaccess
@.username", the user shows up in the database's permissions list. Doing
a "create role @.rolename" then "grant control to @.rolename" still does
not add the role to the "users or roles" permission list under Database
Properties.

I need to test out whether the permissions assigned to the role using
the steps above propagate down to the users irrespective of the
Database Properties issues I've described. However, it seems that there
could be synchronization issues if the "grant control" execution is not
reflected in the permissions gui (for example if someone decides to add
the same role again, what happens?).

Thanks much for the responses tho'.

On Oct 16, 12:32 pm, l...@.iqato.com wrote:

Quote:

Originally Posted by

cyberto...@.gmail.com wrote:

Quote:

Originally Posted by

i seem to have some misunderstanding about how roles work in sql server
2005. i see that i can add a role to a database
(dbname->[right-click]->properties->permissions->[add ...]. THis allows
me to add either users or roles. Users can be added programmatically
using sp_grantdbaccess @.username, but this does not allow for addition
of roles to access the database (i.e., sp_grantdbaccess @.rolename does
not work).


>

Quote:

Originally Posted by

Is there some other command that is used to add a role to the
database's permissions list? Seems there must be since all the other
parts of the permissions chain work quite well:
* sp_addrole
* sp_addrolemember
* grant <permissionon role::@.rolename
etc.


>

Quote:

Originally Posted by

So the missing ingredient of something like sp_grantdbroleaccess is
what I need and can't seem to find it anywhere!


>

Quote:

Originally Posted by

Thanks much for any helpYou should use the T-SQL syntax instead of the SPs whenever possible,


as SPs might get obsolete at some point.
>
Basically, here is a simple process to handle the users and roles.
>
1) Create a server-wide login:
create login user1 with password = '123';
>
2) Create the user in your database:
use database1;
create user user1;
>
3) Create a role in your database:
use database1;
create role role1;
>
4) Add the user to the role:
use database1;
exec sp_addrolemember 'role1','user1';
>
5) Give some permissions to the role:
grant control to role1;
>
Whenever you need to fine-tune the permissions, you just use the
"grant" keyword on the role.
>
Note: "grant control" gives all permissions on the database objects,
most of the time you should be more restrictive.
>
Regards,
lucm

|||Never mind, I'm an idiot - adding the 'grant control' actually adds the
role to the database control set!!! My apologies. I was going under the
impression that just assigning "alter" permissions would be sufficient,
rather than "control" permissions.

Thanks much.

cybertoast wrote:

Quote:

Originally Posted by

This sequence is fine, but the problem is that the "grant control to
role1" portion does not add the role to the database permissions list.
Perhaps this is just a bug in the way SQL Server Mgmt Studio displays
roles and users. For instance, when I do a "sp_grantdbaccess
@.username", the user shows up in the database's permissions list. Doing
a "create role @.rolename" then "grant control to @.rolename" still does
not add the role to the "users or roles" permission list under Database
Properties.
>
I need to test out whether the permissions assigned to the role using
the steps above propagate down to the users irrespective of the
Database Properties issues I've described. However, it seems that there
could be synchronization issues if the "grant control" execution is not
reflected in the permissions gui (for example if someone decides to add
the same role again, what happens?).
>
Thanks much for the responses tho'.
>
On Oct 16, 12:32 pm, l...@.iqato.com wrote:

Quote:

Originally Posted by

cyberto...@.gmail.com wrote:

Quote:

Originally Posted by

i seem to have some misunderstanding about how roles work in sql server
2005. i see that i can add a role to a database
(dbname->[right-click]->properties->permissions->[add ...]. THis allows
me to add either users or roles. Users can be added programmatically
using sp_grantdbaccess @.username, but this does not allow for addition
of roles to access the database (i.e., sp_grantdbaccess @.rolename does
not work).


Quote:

Originally Posted by

Is there some other command that is used to add a role to the
database's permissions list? Seems there must be since all the other
parts of the permissions chain work quite well:
* sp_addrole
* sp_addrolemember
* grant <permissionon role::@.rolename
etc.


Quote:

Originally Posted by

So the missing ingredient of something like sp_grantdbroleaccess is
what I need and can't seem to find it anywhere!


Quote:

Originally Posted by

Thanks much for any helpYou should use the T-SQL syntax instead of the SPs whenever possible,


as SPs might get obsolete at some point.

Basically, here is a simple process to handle the users and roles.

1) Create a server-wide login:
create login user1 with password = '123';

2) Create the user in your database:
use database1;
create user user1;

3) Create a role in your database:
use database1;
create role role1;

4) Add the user to the role:
use database1;
exec sp_addrolemember 'role1','user1';

5) Give some permissions to the role:
grant control to role1;

Whenever you need to fine-tune the permissions, you just use the
"grant" keyword on the role.

Note: "grant control" gives all permissions on the database objects,
most of the time you should be more restrictive.

Regards,
lucm

Automated restore of a user database

I am trying to restore a user database in a scheduled Job I created that executes the following command "restore database sqleligibilitydatabase from disk= 'd:\dbfrom01\sqleligibilitydatabase_db_%.bak'". I get an error 3101 "unable to get exclusive use".
Absolutely no one is on this server when I do this
From which database are you executing the restore command? Make sure it is the master database. you can run an
sp_who just before and get the output from the jobstep to a file and examine that file to see who is using the
database.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"cbriscoejr" <cbriscoejr@.discussions.microsoft.com> wrote in message
news:C9D0496B-0E92-48B2-A3EE-860048654DE4@.microsoft.com...
> I am trying to restore a user database in a scheduled Job I created that executes the following command
"restore database sqleligibilitydatabase from disk= 'd:\dbfrom01\sqleligibilitydatabase_db_%.bak'". I get an
error 3101 "unable to get exclusive use". Absolutely no one is on this server when I do this
|||Hi,
Turn the database to single user before restore and make it multiuser after
restore:-
Change the script to do below :-
Alter database <dbname> set single_user with rollback immediate
go
restore database dbname from disk=...........
go
Alter database <dbname> set multi_user
Thanks
Hari
MCDBA
"cbriscoejr" <cbriscoejr@.discussions.microsoft.com> wrote in message
news:C9D0496B-0E92-48B2-A3EE-860048654DE4@.microsoft.com...
> I am trying to restore a user database in a scheduled Job I created that
executes the following command "restore database sqleligibilitydatabase from
disk= 'd:\dbfrom01\sqleligibilitydatabase_db_%.bak'". I get an error 3101
"unable to get exclusive use". Absolutely no one is on this server when I
do this
|||ALTER DATABASE sqleligibilitydatabase SET OFFLINE WITH ROLLBACK IMMEDIATE
ALTER DATABASE sqleligibilitydatabase SET ONLINE
RESTORE DATABASE......
That will clear all users out of the database. Also, make sure your job
step does not execute in the context of the target database.
Geoff N. Hiten
Microsoft SQL Server MVP
Senior Database Administrator
Careerbuilder.com
I support the Professional Association for SQL Server
www.sqlpass.org
"cbriscoejr" <cbriscoejr@.discussions.microsoft.com> wrote in message
news:C9D0496B-0E92-48B2-A3EE-860048654DE4@.microsoft.com...
> I am trying to restore a user database in a scheduled Job I created that
executes the following command "restore database sqleligibilitydatabase from
disk= 'd:\dbfrom01\sqleligibilitydatabase_db_%.bak'". I get an error 3101
"unable to get exclusive use". Absolutely no one is on this server when I
do this

Automated restore of a user database

I am trying to restore a user database in a scheduled Job I created that exe
cutes the following command "restore database sqleligibilitydatabase from di
sk= 'd:\dbfrom01\sqleligibilitydatabase_db_%
.bak'". I get an error 3101 "un
able to get exclusive use".
Absolutely no one is on this server when I do thisFrom which database are you executing the restore command? Make sure it is t
he master database. you can run an
sp_who just before and get the output from the jobstep to a file and examine
that file to see who is using the
database.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"cbriscoejr" <cbriscoejr@.discussions.microsoft.com> wrote in message
news:C9D0496B-0E92-48B2-A3EE-860048654DE4@.microsoft.com...
> I am trying to restore a user database in a scheduled Job I created that executes
the following command
"restore database sqleligibilitydatabase from disk= 'd:\dbfrom01\sqleligibil
itydatabase_db_%.bak'". I get an
error 3101 "unable to get exclusive use". Absolutely no one is on this serv
er when I do this|||Hi,
Turn the database to single user before restore and make it multiuser after
restore:-
Change the script to do below :-
Alter database <dbname> set single_user with rollback immediate
go
restore database dbname from disk=...........
go
Alter database <dbname> set multi_user
Thanks
Hari
MCDBA
"cbriscoejr" <cbriscoejr@.discussions.microsoft.com> wrote in message
news:C9D0496B-0E92-48B2-A3EE-860048654DE4@.microsoft.com...
> I am trying to restore a user database in a scheduled Job I created that
executes the following command "restore database sqleligibilitydatabase from
disk= 'd:\dbfrom01\sqleligibilitydatabase_db_%
.bak'". I get an error 3101
"unable to get exclusive use". Absolutely no one is on this server when I
do this|||ALTER DATABASE sqleligibilitydatabase SET OFFLINE WITH ROLLBACK IMMEDIATE
ALTER DATABASE sqleligibilitydatabase SET ONLINE
RESTORE DATABASE......
That will clear all users out of the database. Also, make sure your job
step does not execute in the context of the target database.
Geoff N. Hiten
Microsoft SQL Server MVP
Senior Database Administrator
Careerbuilder.com
I support the Professional Association for SQL Server
www.sqlpass.org
"cbriscoejr" <cbriscoejr@.discussions.microsoft.com> wrote in message
news:C9D0496B-0E92-48B2-A3EE-860048654DE4@.microsoft.com...
> I am trying to restore a user database in a scheduled Job I created that
executes the following command "restore database sqleligibilitydatabase from
disk= 'd:\dbfrom01\sqleligibilitydatabase_db_%
.bak'". I get an error 3101
"unable to get exclusive use". Absolutely no one is on this server when I
do this

automated restore

Is it possible to do an automatic/daily restore of a
database to a test box that is being backed up as part of
a maintenence plan? Since the backup file contains a
timestamp, I'm wondering if the file name is stored in one
of the msdb system tables where I can select it into the
restore script. thanks.Yes it is. Here is a bit of code to identify the last backup for a
database. You can then build a process around this to automate the restore.
Keep in mind if you do multiple types of backups (tran, diff, and full) then
you might have to restore from multiple files. Also if the file is on your
prod box, you might need to create a network share or something to get
access to the backup from test.
select physical_device_name
from msdb..backupset a join msdb..backupmediaset b on a.media_set_id =
b.media_set_id
join msdb..backupmediafamily c on a.media_set_id = c.media_set_id
where backup_start_date =
(select top 1 backup_start_date from msdb..backupset
where database_name = 'YourBaseNameHere'
order by backup_start_date desc)
Here is an article that will show you how to even build the restore script:
http://www.databasejournal.com/feat...cle.php/2174411
----
----
--
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"rob" <anonymous@.discussions.microsoft.com> wrote in message
news:2367001c45ed3$30411ae0$a601280a@.phx
.gbl...
> Is it possible to do an automatic/daily restore of a
> database to a test box that is being backed up as part of
> a maintenence plan? Since the backup file contains a
> timestamp, I'm wondering if the file name is stored in one
> of the msdb system tables where I can select it into the
> restore script. thanks.

Automated Restore

Hi,

I have 2 databases, one called "ManagementDB" and the other called "ManagementDBYesterday".

Basically I get asked very frequently to look at yesterdays data for various reasons and I thought it'd be a good idea to always have yesterdays data to hand instead of restoring all the time.

I have tried DTS but this takes too long, I've also thought of replication however the database is modified too frequently for this to be easliy implemented.

Restoring from a backup is quite quick so I thought if I could somehow automate this, I'd have a readily available copy of yesterdays data to hand.

I have a mon-sun daily backup so I need to write some SQL script to restore from the correct backup to the "yesterday" database.

I've only used restore via the enterprise manager and I was wondering if anyone here could help.

kind regards,

Mike,You need to create a scheduled job that will execute something like this:

restore database ManagementDBYesterday
from disk = 'backup_location\ManagementDB.bak' with recovery,
move 'ManagementDB_Data' to 'data_location\ManagementDBYesterday_Data.ndf',
move 'ManagementDB_Primary' to 'data_location\ManagementDBYesterday_Primary.mdf',
move 'ManagementDB_Log' to 'log_location\ManagementDBYesterday_Log.ldf'
If you have different logical file names for each database, you may also want to do this for clarity:

alter database ManagementDBYesterday
modify file (name=ManagementDB_Primary, newname=ManagementDBYesterday_Primary)

alter database ManagementDBYesterday
modify file (name=ManagementDB_Data, newname=ManagementDBYesterday_Data)

alter database ManagementDBYesterday
modify file (name=ManagementDB_Log, newname=ManagementDBYesterday_Log)

automated restore

Is it possible to do an automatic/daily restore of a
database to a test box that is being backed up as part of
a maintenence plan? Since the backup file contains a
timestamp, I'm wondering if the file name is stored in one
of the msdb system tables where I can select it into the
restore script. thanks.
Yes it is. Here is a bit of code to identify the last backup for a
database. You can then build a process around this to automate the restore.
Keep in mind if you do multiple types of backups (tran, diff, and full) then
you might have to restore from multiple files. Also if the file is on your
prod box, you might need to create a network share or something to get
access to the backup from test.
select physical_device_name
from msdb..backupset a join msdb..backupmediaset b on a.media_set_id =
b.media_set_id
join msdb..backupmediafamily c on a.media_set_id = c.media_set_id
where backup_start_date =
(select top 1 backup_start_date from msdb..backupset
where database_name = 'YourBaseNameHere'
order by backup_start_date desc)
Here is an article that will show you how to even build the restore script:
http://www.databasejournal.com/featu...le.php/2174411
----
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"rob" <anonymous@.discussions.microsoft.com> wrote in message
news:2367001c45ed3$30411ae0$a601280a@.phx.gbl...
> Is it possible to do an automatic/daily restore of a
> database to a test box that is being backed up as part of
> a maintenence plan? Since the backup file contains a
> timestamp, I'm wondering if the file name is stored in one
> of the msdb system tables where I can select it into the
> restore script. thanks.

automated restore

Is it possible to do an automatic/daily restore of a
database to a test box that is being backed up as part of
a maintenence plan? Since the backup file contains a
timestamp, I'm wondering if the file name is stored in one
of the msdb system tables where I can select it into the
restore script. thanks.Yes it is. Here is a bit of code to identify the last backup for a
database. You can then build a process around this to automate the restore.
Keep in mind if you do multiple types of backups (tran, diff, and full) then
you might have to restore from multiple files. Also if the file is on your
prod box, you might need to create a network share or something to get
access to the backup from test.
select physical_device_name
from msdb..backupset a join msdb..backupmediaset b on a.media_set_id =b.media_set_id
join msdb..backupmediafamily c on a.media_set_id = c.media_set_id
where backup_start_date = (select top 1 backup_start_date from msdb..backupset
where database_name = 'YourBaseNameHere'
order by backup_start_date desc)
Here is an article that will show you how to even build the restore script:
http://www.databasejournal.com/features/mssql/article.php/2174411
----
----
--
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"rob" <anonymous@.discussions.microsoft.com> wrote in message
news:2367001c45ed3$30411ae0$a601280a@.phx.gbl...
> Is it possible to do an automatic/daily restore of a
> database to a test box that is being backed up as part of
> a maintenence plan? Since the backup file contains a
> timestamp, I'm wondering if the file name is stored in one
> of the msdb system tables where I can select it into the
> restore script. thanks.

Automated restart of Analysis Services

Hello,

I need to put the Analysis server in local mode only while my jobs process cubes on Saturday morning.

I can script the property but I do not know how to automatically restart the service.

Any idea?

Thanks

Philippe

<Alter AllowCreate="true" ObjectExpansion="ObjectProperties" xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">

<Object />

<ObjectDefinition>

<Server xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ddl2="http://schemas.microsoft.com/analysisservices/2003/engine/2" xmlns:ddl2_2="http://schemas.microsoft.com/analysisservices/2003/engine/2/2">

<ID>SMDEV</ID>

<Name>SMDEV</Name>

<ServerProperties>

<ServerProperty>

<Name>Network\ListenOnlyOnLocalConnections</Name>

<Value>true</Value>

</ServerProperty>

</ServerProperties>

</Server>

</ObjectDefinition>

</Alter>

You can create a simple batch file and use there commands "net start MSSQLSErverOlapservice"

and "net stop MSSQLSErverOlapservice".

Another way, you can write a simple C# application using ServiceController inteface. Take a look here; http://msdn2.microsoft.com/en-us/library/sywbez17.aspx

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

automated replication scripting

We create replication scripts on a regular basis, saving them to a warm standby server as a precaution. Is there a way to automate (i.e. in a job) the scripting of replication? Right-clicking in EM is becoming tedious with the number of servers we have (80+ of them SQL Servers). My manager does not want to go through just restoring msdb on the standby; he says there are issues with that. I am new enough to replication to just go with his guidance, which is why we are taking this approach.

You can take a look at RMO programming. For example, Publication object has a method Script() that can be used to create a script (see http://msdn2.microsoft.com/en-us/library/microsoft.sqlserver.replication.publication.script.aspx). Other replication objects, such as DistributionDatabase, MergePublication, has similar methods.|||At a glance, this appears to apply to SQL Server 2005. I cannot find documentation for SQL Server 2000.|||

For SQL 2000, you can use SQL DMO. Check out SQL 2000 BOL and find topic "Script Method (Replication Objects)".

Peng

|||

Peng, that was it! Sweet as pie, it worked beautifully using a VBScript in a DTS. Something I have never done, but always wanted to. I have always known that SQLDMO would eventually become a tool I needed and you've put me onto it. Thank you!

automated replication scripting

We create replication scripts on a regular basis, saving them to a warm standby server as a precaution. Is there a way to automate (i.e. in a job) the scripting of replication? Right-clicking in EM is becoming tedious with the number of servers we have (80+ of them SQL Servers). My manager does not want to go through just restoring msdb on the standby; he says there are issues with that. I am new enough to replication to just go with his guidance, which is why we are taking this approach.

You can take a look at RMO programming. For example, Publication object has a method Script() that can be used to create a script (see http://msdn2.microsoft.com/en-us/library/microsoft.sqlserver.replication.publication.script.aspx). Other replication objects, such as DistributionDatabase, MergePublication, has similar methods.|||At a glance, this appears to apply to SQL Server 2005. I cannot find documentation for SQL Server 2000.|||

For SQL 2000, you can use SQL DMO. Check out SQL 2000 BOL and find topic "Script Method (Replication Objects)".

Peng

|||

Peng, that was it! Sweet as pie, it worked beautifully using a VBScript in a DTS. Something I have never done, but always wanted to. I have always known that SQLDMO would eventually become a tool I needed and you've put me onto it. Thank you!