Showing posts with label run. Show all posts
Showing posts with label run. Show all posts

Friday, March 30, 2012

restore db with script?

Hi all.
I have a sql server backup file for SQL Server 2000.
Is there a way to bring this file to another computer with SQL and run a
script that tells the server to restore the backup file automatically
without using the GUI?
Thanks in advance.Yes, on the target machine, schedule a T-sql job to run a restore command,
see restore syntax in BOL.
Ray Higdon MCSE, MCDBA, CCNA
--
"Daniel" <dhw377@.nothing.no.spam.com> wrote in message
news:pHYMb.1223$ZJ1.790@.lakeread01...
quote:

> Hi all.
> I have a sql server backup file for SQL Server 2000.
> Is there a way to bring this file to another computer with SQL and run a
> script that tells the server to restore the backup file automatically
> without using the GUI?
>
> Thanks in advance.
>

restore db with script?

Hi all.
I have a sql server backup file for SQL Server 2000.
Is there a way to bring this file to another computer with SQL and run a
script that tells the server to restore the backup file automatically
without using the GUI?
Thanks in advance.Yes, on the target machine, schedule a T-sql job to run a restore command,
see restore syntax in BOL.
--
Ray Higdon MCSE, MCDBA, CCNA
--
"Daniel" <dhw377@.nothing.no.spam.com> wrote in message
news:pHYMb.1223$ZJ1.790@.lakeread01...
> Hi all.
> I have a sql server backup file for SQL Server 2000.
> Is there a way to bring this file to another computer with SQL and run a
> script that tells the server to restore the backup file automatically
> without using the GUI?
>
> Thanks in advance.
>

Restore DB to Point in Time

I have a group of folks that are Peoplesoft Developers, of which the
back-end is a 65 GB SQL Server database. They run test procedures and
processes against this database, but then it is a pretty common practice for
them to ask the DBAs to restore to an old backup so they can run more tests
after modifying their code.
Is there an easier way to do this? Restoring a 65 GB database is rather
daunting and time consuming. Wouldn't there be a way to not commit a
timeframe of activity (transaction log, for example), ultimately returning
the database back to a previous point in time?
I hope this makes sense, and that someone has come across this scenario in
the past.
Thanks for any advice,
AllenIf you are running SQL Server 2005 this is a perfect situation for
database snapshots. This effectively creates a read-only copy of the
database, and you can revert the database back to the state at the
time of the snapshot.
Roy Harvey
Beacon Falls, CT
On Wed, 19 Jul 2006 08:58:37 -0500, "A McGuire"
<allen.mcguire@.gmail.com.invalid> wrote:

>I have a group of folks that are Peoplesoft Developers, of which the
>back-end is a 65 GB SQL Server database. They run test procedures and
>processes against this database, but then it is a pretty common practice fo
r
>them to ask the DBAs to restore to an old backup so they can run more tests
>after modifying their code.
>Is there an easier way to do this? Restoring a 65 GB database is rather
>daunting and time consuming. Wouldn't there be a way to not commit a
>timeframe of activity (transaction log, for example), ultimately returning
>the database back to a previous point in time?
>I hope this makes sense, and that someone has come across this scenario in
>the past.
>Thanks for any advice,
>Allen
>|||Unfortunately in this instance I'm using SQL 2000. Any ideas for SQL 2000?
What about getting copies of the databases at the point in time they
continually want to restore to, and then attach to them when I need to
revert back to the older version (after deleting the modified ones of
course)?
Still thinking about this, but there has to be a more efficient way to
revert back to a previous state without having to restore a 65 GB
database...
Would it be
"Roy Harvey" <roy_harvey@.snet.net> wrote in message
news:9qgsb2td3nc7csfk6rogastm6vohds7iq4@.
4ax.com...[vbcol=seagreen]
> If you are running SQL Server 2005 this is a perfect situation for
> database snapshots. This effectively creates a read-only copy of the
> database, and you can revert the database back to the state at the
> time of the snapshot.
> Roy Harvey
> Beacon Falls, CT
> On Wed, 19 Jul 2006 08:58:37 -0500, "A McGuire"
> <allen.mcguire@.gmail.com.invalid> wrote:
>|||Yes you can use sp_detach copy a file to another location or rename it in
the same folder and then sp_attach one file for them to play with.
If they need to revert just sp_attach the renamed file.
"A McGuire" <allen.mcguire@.gmail.com.invalid> wrote in message
news:eDh9NH0qGHA.5008@.TK2MSFTNGP05.phx.gbl...
> Unfortunately in this instance I'm using SQL 2000. Any ideas for SQL
> 2000?
> What about getting copies of the databases at the point in time they
> continually want to restore to, and then attach to them when I need to
> revert back to the older version (after deleting the modified ones of
> course)?
> Still thinking about this, but there has to be a more efficient way to
> revert back to a previous state without having to restore a 65 GB
> database...
> Would it be
> "Roy Harvey" <roy_harvey@.snet.net> wrote in message
> news:9qgsb2td3nc7csfk6rogastm6vohds7iq4@.
4ax.com...
>|||Awesome - thanks for confirming my suspicions ;-)
That will work great considering this continual restore process takes about
4-6 hours.
"alex sadykov" <alexsadykov@.gmail.com> wrote in message
news:%23JJKkE1qGHA.4684@.TK2MSFTNGP05.phx.gbl...
> Yes you can use sp_detach copy a file to another location or rename it in
> the same folder and then sp_attach one file for them to play with.
> If they need to revert just sp_attach the renamed file.
>
> "A McGuire" <allen.mcguire@.gmail.com.invalid> wrote in message
> news:eDh9NH0qGHA.5008@.TK2MSFTNGP05.phx.gbl...
>|||A McGuire wrote:
> Awesome - thanks for confirming my suspicions ;-)
> That will work great considering this continual restore process takes abou
t
> 4-6 hours.
> "alex sadykov" <alexsadykov@.gmail.com> wrote in message
> news:%23JJKkE1qGHA.4684@.TK2MSFTNGP05.phx.gbl...
>
Just keep in mind that it also takes a while to copy a 65GB database
file and a log file in order to use sp_attach_db. I'm also wondering why
it takes 4-6 hours to restore a 65 GB database. Our biggest database
which is a 110 GB database file and a 65 GB log file can be restored in
less than 1 hour. If it's because you have a slow server/disk system,
the copy/sp_attach_db solution will take quite a while as well.
Often I find that it's not that much faster to copy the files and attach
them compared to doing a RESTORE. The part that takes time is for the OS
to create the files on disk and that's more or less the same with both
solutions.
Regards
Steen Schlter Persson
Databaseadministrator / Systemadministrator|||On my way home last night that notion came to me - copying the 65 GB file
took a few hours. I'm not saving a whole lot of time... unfortunately.
I don't deal at all with the hardware - in fact I've never seen the
servers - so I'm not quite sure what they are.
"Steen Persson (DK)" <spe@.REMOVEdatea.dk> wrote in message
news:efL%23In8qGHA.4508@.TK2MSFTNGP04.phx.gbl...
>A McGuire wrote:
> Just keep in mind that it also takes a while to copy a 65GB database file
> and a log file in order to use sp_attach_db. I'm also wondering why it
> takes 4-6 hours to restore a 65 GB database. Our biggest database which is
> a 110 GB database file and a 65 GB log file can be restored in less than
> 1 hour. If it's because you have a slow server/disk system, the
> copy/sp_attach_db solution will take quite a while as well.
> Often I find that it's not that much faster to copy the files and attach
> them compared to doing a RESTORE. The part that takes time is for the OS
> to create the files on disk and that's more or less the same with both
> solutions.
>
> --
> Regards
> Steen Schlter Persson
> Databaseadministrator / Systemadministrator|||On Thu, 20 Jul 2006 11:41:41 -0500, "A McGuire"
<allen.mcguire@.gmail.com.invalid> wrote:

>On my way home last night that notion came to me - copying the 65 GB file
>took a few hours. I'm not saving a whole lot of time... unfortunately.
To use file copy you need a master "saved" copy on hand, plus the copy
currently attached and in use. If you have space for a third copy you
might be able to save time. Don't wait for them to ask for the
database to be restored. Copy the master version using different file
names, so that when they do ask you just have to detach the active
copy and attach to the one already in place. Then delete the files
you just detached and replace them with fresh copies from the master
set right away.
Which, as a read it, is probably confusing.
Roy|||I did get a copy of the restored .MDF (detatch, copy, attach), so I'm good
there. Before they only had the .BAK files from early May, for example, so
my only option this time around was a restore. Only problem is that the
.MDF is in a neighboring folder, not the same one, which means a multi-hour
copy. I suppose I could rename it as you suggest and put it in the same
folder. That will save me the copy time.
I assume you suggest the third copy so when I go to 'restore' next time
(drop current, attach to .MDF) that I have an additional free .MDF of the
snapshot handy that won't be in use. The current would get dropped, one of
the copies would be put to use (attached to), and I would just make another
copy of the 3rd - this would be the procedure each time.
"Roy Harvey" <roy_harvey@.snet.net> wrote in message
news:pngvb2psrs8hg44hh15vlsjl3hqfsn2ilr@.
4ax.com...
> On Thu, 20 Jul 2006 11:41:41 -0500, "A McGuire"
> <allen.mcguire@.gmail.com.invalid> wrote:
>
> To use file copy you need a master "saved" copy on hand, plus the copy
> currently attached and in use. If you have space for a third copy you
> might be able to save time. Don't wait for them to ask for the
> database to be restored. Copy the master version using different file
> names, so that when they do ask you just have to detach the active
> copy and attach to the one already in place. Then delete the files
> you just detached and replace them with fresh copies from the master
> set right away.
> Which, as a read it, is probably confusing.
> Roysql

Restore DB to Point in Time

I have a group of folks that are Peoplesoft Developers, of which the
back-end is a 65 GB SQL Server database. They run test procedures and
processes against this database, but then it is a pretty common practice for
them to ask the DBAs to restore to an old backup so they can run more tests
after modifying their code.
Is there an easier way to do this? Restoring a 65 GB database is rather
daunting and time consuming. Wouldn't there be a way to not commit a
timeframe of activity (transaction log, for example), ultimately returning
the database back to a previous point in time?
I hope this makes sense, and that someone has come across this scenario in
the past.
Thanks for any advice,
AllenIf you are running SQL Server 2005 this is a perfect situation for
database snapshots. This effectively creates a read-only copy of the
database, and you can revert the database back to the state at the
time of the snapshot.
Roy Harvey
Beacon Falls, CT
On Wed, 19 Jul 2006 08:58:37 -0500, "A McGuire"
<allen.mcguire@.gmail.com.invalid> wrote:
>I have a group of folks that are Peoplesoft Developers, of which the
>back-end is a 65 GB SQL Server database. They run test procedures and
>processes against this database, but then it is a pretty common practice for
>them to ask the DBAs to restore to an old backup so they can run more tests
>after modifying their code.
>Is there an easier way to do this? Restoring a 65 GB database is rather
>daunting and time consuming. Wouldn't there be a way to not commit a
>timeframe of activity (transaction log, for example), ultimately returning
>the database back to a previous point in time?
>I hope this makes sense, and that someone has come across this scenario in
>the past.
>Thanks for any advice,
>Allen
>|||Unfortunately in this instance I'm using SQL 2000. Any ideas for SQL 2000?
What about getting copies of the databases at the point in time they
continually want to restore to, and then attach to them when I need to
revert back to the older version (after deleting the modified ones of
course)?
Still thinking about this, but there has to be a more efficient way to
revert back to a previous state without having to restore a 65 GB
database...
Would it be
"Roy Harvey" <roy_harvey@.snet.net> wrote in message
news:9qgsb2td3nc7csfk6rogastm6vohds7iq4@.4ax.com...
> If you are running SQL Server 2005 this is a perfect situation for
> database snapshots. This effectively creates a read-only copy of the
> database, and you can revert the database back to the state at the
> time of the snapshot.
> Roy Harvey
> Beacon Falls, CT
> On Wed, 19 Jul 2006 08:58:37 -0500, "A McGuire"
> <allen.mcguire@.gmail.com.invalid> wrote:
>>I have a group of folks that are Peoplesoft Developers, of which the
>>back-end is a 65 GB SQL Server database. They run test procedures and
>>processes against this database, but then it is a pretty common practice
>>for
>>them to ask the DBAs to restore to an old backup so they can run more
>>tests
>>after modifying their code.
>>Is there an easier way to do this? Restoring a 65 GB database is rather
>>daunting and time consuming. Wouldn't there be a way to not commit a
>>timeframe of activity (transaction log, for example), ultimately returning
>>the database back to a previous point in time?
>>I hope this makes sense, and that someone has come across this scenario in
>>the past.
>>Thanks for any advice,
>>Allen|||Yes you can use sp_detach copy a file to another location or rename it in
the same folder and then sp_attach one file for them to play with.
If they need to revert just sp_attach the renamed file.
"A McGuire" <allen.mcguire@.gmail.com.invalid> wrote in message
news:eDh9NH0qGHA.5008@.TK2MSFTNGP05.phx.gbl...
> Unfortunately in this instance I'm using SQL 2000. Any ideas for SQL
> 2000?
> What about getting copies of the databases at the point in time they
> continually want to restore to, and then attach to them when I need to
> revert back to the older version (after deleting the modified ones of
> course)?
> Still thinking about this, but there has to be a more efficient way to
> revert back to a previous state without having to restore a 65 GB
> database...
> Would it be
> "Roy Harvey" <roy_harvey@.snet.net> wrote in message
> news:9qgsb2td3nc7csfk6rogastm6vohds7iq4@.4ax.com...
>> If you are running SQL Server 2005 this is a perfect situation for
>> database snapshots. This effectively creates a read-only copy of the
>> database, and you can revert the database back to the state at the
>> time of the snapshot.
>> Roy Harvey
>> Beacon Falls, CT
>> On Wed, 19 Jul 2006 08:58:37 -0500, "A McGuire"
>> <allen.mcguire@.gmail.com.invalid> wrote:
>>I have a group of folks that are Peoplesoft Developers, of which the
>>back-end is a 65 GB SQL Server database. They run test procedures and
>>processes against this database, but then it is a pretty common practice
>>for
>>them to ask the DBAs to restore to an old backup so they can run more
>>tests
>>after modifying their code.
>>Is there an easier way to do this? Restoring a 65 GB database is rather
>>daunting and time consuming. Wouldn't there be a way to not commit a
>>timeframe of activity (transaction log, for example), ultimately
>>returning
>>the database back to a previous point in time?
>>I hope this makes sense, and that someone has come across this scenario
>>in
>>the past.
>>Thanks for any advice,
>>Allen
>|||Awesome - thanks for confirming my suspicions ;-)
That will work great considering this continual restore process takes about
4-6 hours.
"alex sadykov" <alexsadykov@.gmail.com> wrote in message
news:%23JJKkE1qGHA.4684@.TK2MSFTNGP05.phx.gbl...
> Yes you can use sp_detach copy a file to another location or rename it in
> the same folder and then sp_attach one file for them to play with.
> If they need to revert just sp_attach the renamed file.
>
> "A McGuire" <allen.mcguire@.gmail.com.invalid> wrote in message
> news:eDh9NH0qGHA.5008@.TK2MSFTNGP05.phx.gbl...
>> Unfortunately in this instance I'm using SQL 2000. Any ideas for SQL
>> 2000?
>> What about getting copies of the databases at the point in time they
>> continually want to restore to, and then attach to them when I need to
>> revert back to the older version (after deleting the modified ones of
>> course)?
>> Still thinking about this, but there has to be a more efficient way to
>> revert back to a previous state without having to restore a 65 GB
>> database...
>> Would it be
>> "Roy Harvey" <roy_harvey@.snet.net> wrote in message
>> news:9qgsb2td3nc7csfk6rogastm6vohds7iq4@.4ax.com...
>> If you are running SQL Server 2005 this is a perfect situation for
>> database snapshots. This effectively creates a read-only copy of the
>> database, and you can revert the database back to the state at the
>> time of the snapshot.
>> Roy Harvey
>> Beacon Falls, CT
>> On Wed, 19 Jul 2006 08:58:37 -0500, "A McGuire"
>> <allen.mcguire@.gmail.com.invalid> wrote:
>>I have a group of folks that are Peoplesoft Developers, of which the
>>back-end is a 65 GB SQL Server database. They run test procedures and
>>processes against this database, but then it is a pretty common practice
>>for
>>them to ask the DBAs to restore to an old backup so they can run more
>>tests
>>after modifying their code.
>>Is there an easier way to do this? Restoring a 65 GB database is rather
>>daunting and time consuming. Wouldn't there be a way to not commit a
>>timeframe of activity (transaction log, for example), ultimately
>>returning
>>the database back to a previous point in time?
>>I hope this makes sense, and that someone has come across this scenario
>>in
>>the past.
>>Thanks for any advice,
>>Allen
>>
>|||A McGuire wrote:
> Awesome - thanks for confirming my suspicions ;-)
> That will work great considering this continual restore process takes about
> 4-6 hours.
> "alex sadykov" <alexsadykov@.gmail.com> wrote in message
> news:%23JJKkE1qGHA.4684@.TK2MSFTNGP05.phx.gbl...
>
Just keep in mind that it also takes a while to copy a 65GB database
file and a log file in order to use sp_attach_db. I'm also wondering why
it takes 4-6 hours to restore a 65 GB database. Our biggest database
which is a 110 GB database file and a 65 GB log file can be restored in
less than 1½ hour. If it's because you have a slow server/disk system,
the copy/sp_attach_db solution will take quite a while as well.
Often I find that it's not that much faster to copy the files and attach
them compared to doing a RESTORE. The part that takes time is for the OS
to create the files on disk and that's more or less the same with both
solutions.
Regards
Steen Schlüter Persson
Databaseadministrator / Systemadministrator|||On my way home last night that notion came to me - copying the 65 GB file
took a few hours. I'm not saving a whole lot of time... unfortunately.
I don't deal at all with the hardware - in fact I've never seen the
servers - so I'm not quite sure what they are.
"Steen Persson (DK)" <spe@.REMOVEdatea.dk> wrote in message
news:efL%23In8qGHA.4508@.TK2MSFTNGP04.phx.gbl...
>A McGuire wrote:
>> Awesome - thanks for confirming my suspicions ;-)
>> That will work great considering this continual restore process takes
>> about 4-6 hours.
>> "alex sadykov" <alexsadykov@.gmail.com> wrote in message
>> news:%23JJKkE1qGHA.4684@.TK2MSFTNGP05.phx.gbl...
> Just keep in mind that it also takes a while to copy a 65GB database file
> and a log file in order to use sp_attach_db. I'm also wondering why it
> takes 4-6 hours to restore a 65 GB database. Our biggest database which is
> a 110 GB database file and a 65 GB log file can be restored in less than
> 1½ hour. If it's because you have a slow server/disk system, the
> copy/sp_attach_db solution will take quite a while as well.
> Often I find that it's not that much faster to copy the files and attach
> them compared to doing a RESTORE. The part that takes time is for the OS
> to create the files on disk and that's more or less the same with both
> solutions.
>
> --
> Regards
> Steen Schlüter Persson
> Databaseadministrator / Systemadministrator|||On Thu, 20 Jul 2006 11:41:41 -0500, "A McGuire"
<allen.mcguire@.gmail.com.invalid> wrote:
>On my way home last night that notion came to me - copying the 65 GB file
>took a few hours. I'm not saving a whole lot of time... unfortunately.
To use file copy you need a master "saved" copy on hand, plus the copy
currently attached and in use. If you have space for a third copy you
might be able to save time. Don't wait for them to ask for the
database to be restored. Copy the master version using different file
names, so that when they do ask you just have to detach the active
copy and attach to the one already in place. Then delete the files
you just detached and replace them with fresh copies from the master
set right away.
Which, as a read it, is probably confusing.
Roy|||I did get a copy of the restored .MDF (detatch, copy, attach), so I'm good
there. Before they only had the .BAK files from early May, for example, so
my only option this time around was a restore. Only problem is that the
.MDF is in a neighboring folder, not the same one, which means a multi-hour
copy. I suppose I could rename it as you suggest and put it in the same
folder. That will save me the copy time.
I assume you suggest the third copy so when I go to 'restore' next time
(drop current, attach to .MDF) that I have an additional free .MDF of the
snapshot handy that won't be in use. The current would get dropped, one of
the copies would be put to use (attached to), and I would just make another
copy of the 3rd - this would be the procedure each time.
"Roy Harvey" <roy_harvey@.snet.net> wrote in message
news:pngvb2psrs8hg44hh15vlsjl3hqfsn2ilr@.4ax.com...
> On Thu, 20 Jul 2006 11:41:41 -0500, "A McGuire"
> <allen.mcguire@.gmail.com.invalid> wrote:
>>On my way home last night that notion came to me - copying the 65 GB file
>>took a few hours. I'm not saving a whole lot of time... unfortunately.
> To use file copy you need a master "saved" copy on hand, plus the copy
> currently attached and in use. If you have space for a third copy you
> might be able to save time. Don't wait for them to ask for the
> database to be restored. Copy the master version using different file
> names, so that when they do ask you just have to detach the active
> copy and attach to the one already in place. Then delete the files
> you just detached and replace them with fresh copies from the master
> set right away.
> Which, as a read it, is probably confusing.
> Roy

Wednesday, March 21, 2012

Restore database fails because database is in use.

I'm a newbie so please be gentle.

In attempting to run a restore I get the following error message:
"Exclusive access could not be obtained because the database is in
use." However, it doesn't appear that there are any connections to the
database. At the suggestion of another thread, I ran sp_who2 and there
are no connections to the database in question. I've been running the
same restore for months and all has been well, until yesterday...

I wrote an .asp page (below) to test connectivity to this database.
The vb code ran successfully and soon thereafter, my nightly restore
failed. Task manager does no show that the asp page is active.

Lastly, I did add a user ("jbtest") as well as change the option to use
either Windows authentication or SQL Server authentication in
Enterprise Manager.

Any ideas would be greatly appreciated.

Thanks.

<%@. Language=VBScript %
<%
companyName = "agemni"

Set cnn = Server.CreateObject("ADODB.Connection")
cnn.ConnectionString = "DRIVER=SQL
Server;SERVER=SHEELA-NA-GIG;UID=jbtest;PWD=test1;APP=Microsoft
Development Environment;WSID=SHEELA-NA-GIG;DATABASE=" & companyName &
";Trusted_Connection=No"

cnn.ConnectionTimeout = 300
cnn.CommandTimeout = 300
cnn.Open

Set RS = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM Preferences"
RS.Open strSQL, cnn

Response.Write "connection established with the <b>" & RS("Company
Name") & "</b> database. They are a <b>" & RS("street") & "</b>
customer. "

RS.Close
Set RS = Nothing
%<jbmccluskey@.satcountry.com> wrote in message
news:1112117455.317127.10740@.g14g2000cwa.googlegro ups.com...
> I'm a newbie so please be gentle.
> In attempting to run a restore I get the following error message:
> "Exclusive access could not be obtained because the database is in
> use." However, it doesn't appear that there are any connections to the
> database. At the suggestion of another thread, I ran sp_who2 and there
> are no connections to the database in question. I've been running the
> same restore for months and all has been well, until yesterday...
> I wrote an .asp page (below) to test connectivity to this database.
> The vb code ran successfully and soon thereafter, my nightly restore
> failed. Task manager does no show that the asp page is active.
> Lastly, I did add a user ("jbtest") as well as change the option to use
> either Windows authentication or SQL Server authentication in
> Enterprise Manager.
> Any ideas would be greatly appreciated.
> Thanks.

<snip
Probably the most reliable solution is to use ALTER DATABASE to get rid of
any open connections, wherever they're from:

alter database MyDB set restricted_user with rollback immediate

See Books Online for the other state options (single_user, offline etc.) -
one of them might suit your needs better.

You don't mention how you're running the restore, but if it's via a
scheduled job, you should also check that the selected database for the
restore step is set to master, not to the database you're restoring,
otherwise the job can block itself.

Simon|||Thanks for the reply Simon. The problem was that I was trying to run
the RESTORE in the database itself as opposed to running it under
MASTER.

JB

Tuesday, March 20, 2012

Restore Database - Incorrect syntax near 'GO'

Hello, is it something new in SQL 2005, that you cannot have a GO statement at the end of a restore database command? If I run a statement like below, it fails on teh GO...

Msg 102, Level 15, State 1, Line 5

Incorrect syntax near 'GO'.

But if I remove the GO it works.... I coulda sworn a GO was ok to complete a batch with ANY SQL statements in it?!? Am I doing something stugatz?

Thanks, Bruce

RESTORE DATABASE MyDatabase

FROM DISK = 'E:\SQL\MyDatabase.BAK'

WITH NORECOVERY,

MOVE 'MyDatabase_Data' TO 'E:\SQL\MyDatabase_Data.MDF',

MOVE 'MyDatabase_Log' TO 'E:\SQL\MyDatabase_Log.LDF'

GO

What tool are you using? GO should be parsed out by the tool and never sent to SQL Server itself, but that does not appear to be occurring here.|||Just using the regular ole SQL Server Mgt Studio query window... GO is still set as my delimiter, I checked that... It's not a big deal, just curious to know if I am doing something strange or something is different in SQL 2005... that doesn't allow you to have a GO immediately after a RESTORE? probably the syntax of my RESTORE is wrong somehow?!? Bruce|||

No, it worked for me. Have you tried putting another return in there (maybe there is an invalid character)? This should work.

Also you are not trying to EXEC it right? (I am pretty sure you would have said Smile This will cause that error:

exec ('

RESTORE DATABASE MyDatabase

FROM DISK = ''E:\SQL\MyDatabase.BAK''

WITH NORECOVERY,

MOVE ''MyDatabase_Data'' TO ''E:\SQL\MyDatabase_Data.MDF'',

MOVE ''MyDatabase_Log'' TO ''E:\SQL\MyDatabase_Log.LDF''

GO'

)

|||

I can't remember clearly...

Isn't it necessary to also RESTORE the Log when you move the file in a database RESTORE.

Code Snippet


RESTORE DATABASE MyDatabase
FROM DISK = 'E:\SQL\MyDatabase.BAK'
WITH
NORECOVERY,
MOVE 'MyDatabase_Data' TO 'E:\SQL\MyDatabase_Data.MDF',
MOVE 'MyDatabase_Log' TO 'E:\SQL\MyDatabase_Log.LDF'

RESTORE LOG MyDatabase
FROM MyDataBase_Log
WITH RECOVERY

|||ok, this was driving me nuts... but, found it... retyped the entire command and it worked... then compared the before and after SQL code... somewhere in the script there was a carriage return "0d" with no line feed "0a"... so it was invisible to the eye... and a "GO" must have to be on a "line" being defined as after a "0d 0a" combo... knew it was something stugatz. must have been done in an old editor many moons ago I guess, not sure how else you'd lose PART of a carriage return/line feed.... Thanks, Bruce|||Arnie, good question. The database I happen to be dealing with is SIMPLE recovery mode, but do you have to restore the LOG separately if it was a FULL recovery model? Why then restore the Log in the RESTORE DATABASE command? or if your example said "WITH RECOVERY" wouldn't that restore the LOG (LDF) that is named in the RESTORE DATABASE MOVE statement? or if it's FULL recovery mode, and you did NOT specify the RESTORE LOG, hmmm, what do you get? Anyways, my original issue was resolved by finding a bad carriage return/ line feed character... thought I might need a semi-colon to end the RESTORE command, like the WITH statement requires a semi-colon... not... But now you have me wondering about this LOG restore thing.... back to BOL I go........................Thanks, Bruce|||

With a 'Simple' recovery model, there shouldn't be any additional effort required to restore the log files. However, since you left the database in NORECOVERY mode, it would be necessary to add the RESTORE LOG as I suggested.

With a 'Full' recovery model, you would want to restore the database first, and then restore the log file(s), using RECOVERY on the last log file restore.

I'm glad you found the 'culprit'. Darn non-visible characters sometimes bite us...

Friday, March 9, 2012

RESTORE as New Database

Hello!
I have a question regarding the "LogicalName" when restoring a backup as an
entirely different database.
I run this:
USE master
GO
RESTORE FILELISTONLY
FROM DISK='C:\Program Files\MyApp\Archives\Archive_20000311.BAK'
RESTORE DATABASE MyNewDatabase
FROM DISK= 'C:\Program Files\MyApp\Archives\Archive_20000311.BAK'
WITH RECOVERY,
MOVE 'MyOriginalDatabase_data' TO 'C:\Program
Files\MyApp\MSSQL$MYAPP\Data\MyNewDataba
se_data.mdf',
MOVE 'MyOriginalDatabase_log' TO 'C:\Program
Files\MyApp\MSSQL$MYAPP\Data\MyNewDataba
se_log.ldf'
GO
And my PhysicalNames are correct for the new database but the LogicalNames
remain the same as the original database. Is this correct?
I cannot have the new database have any ties/links to the original database.
Is the TSQL incorrect above or can I "rename" the LogicalName for the new
database?
Thank you in advance for your time.Carol
Yep, you can change a logical name file of the database.
What is your concernment?
"Carol" <pooch@.hotmail.com> wrote in message
news:uV8zua2BEHA.2600@.TK2MSFTNGP09.phx.gbl...
> Hello!
> I have a question regarding the "LogicalName" when restoring a backup as
an
> entirely different database.
> I run this:
> USE master
> GO
> RESTORE FILELISTONLY
> FROM DISK='C:\Program Files\MyApp\Archives\Archive_20000311.BAK'
> RESTORE DATABASE MyNewDatabase
> FROM DISK= 'C:\Program Files\MyApp\Archives\Archive_20000311.BAK'
> WITH RECOVERY,
> MOVE 'MyOriginalDatabase_data' TO 'C:\Program
> Files\MyApp\MSSQL$MYAPP\Data\MyNewDataba
se_data.mdf',
> MOVE 'MyOriginalDatabase_log' TO 'C:\Program
> Files\MyApp\MSSQL$MYAPP\Data\MyNewDataba
se_log.ldf'
> GO
> And my PhysicalNames are correct for the new database but the LogicalNames
> remain the same as the original database. Is this correct?
> I cannot have the new database have any ties/links to the original
database.
> Is the TSQL incorrect above or can I "rename" the LogicalName for the new
> database?
> Thank you in advance for your time.
>|||Hi,
1. And my PhysicalNames are correct for the new database but the
LogicalNames remain the same as the original database. Is this correct?
Yes , You can do that.
2. Is the TSQL incorrect above or can I "rename" the LogicalName for the new
database?
It is not required to rename the logical file name. Only physical name
need to be changed.
Thanks
Hari
"Carol" <pooch@.hotmail.com> wrote in message
news:uV8zua2BEHA.2600@.TK2MSFTNGP09.phx.gbl...
> Hello!
> I have a question regarding the "LogicalName" when restoring a backup as
an
> entirely different database.
> I run this:
> USE master
> GO
> RESTORE FILELISTONLY
> FROM DISK='C:\Program Files\MyApp\Archives\Archive_20000311.BAK'
> RESTORE DATABASE MyNewDatabase
> FROM DISK= 'C:\Program Files\MyApp\Archives\Archive_20000311.BAK'
> WITH RECOVERY,
> MOVE 'MyOriginalDatabase_data' TO 'C:\Program
> Files\MyApp\MSSQL$MYAPP\Data\MyNewDataba
se_data.mdf',
> MOVE 'MyOriginalDatabase_log' TO 'C:\Program
> Files\MyApp\MSSQL$MYAPP\Data\MyNewDataba
se_log.ldf'
> GO
> And my PhysicalNames are correct for the new database but the LogicalNames
> remain the same as the original database. Is this correct?
> I cannot have the new database have any ties/links to the original
database.
> Is the TSQL incorrect above or can I "rename" the LogicalName for the new
> database?
> Thank you in advance for your time.
>|||Hi Uri,
This database needs to be a snapshot of data (ArchivedData) and it cannot be
altered in any way. So I wasn't sure... if it's connected to the origianl DB
somehow I would have problems. Also if I have to DROP the new DB on
occassion , I can't have the Original DB dropped too if SQL's looking for
LogicalName to DROP.
:-O
I'm not sure how to rename...I've been playing around with sp_rename
procedure but what type of "object" is the LogicalName?
I guess if the two databases aren't connected in any way, I can just leave
it as is...and keep my fingers crossed.
;)
Thanks for your quick response!
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:uVFBDh2BEHA.1140@.TK2MSFTNGP10.phx.gbl...
> Carol
> Yep, you can change a logical name file of the database.
> What is your concernment?
> "Carol" <pooch@.hotmail.com> wrote in message
> news:uV8zua2BEHA.2600@.TK2MSFTNGP09.phx.gbl...
> an
LogicalNames
> database.
new
>|||Hi Hari!
Thank you for your quick response as well.
I will just leave it as it is since the physicalnames are correct.
Thank you!

Carol
"Hari" <hari_prasad_k@.hotmail.com> wrote in message
news:um%23iBm2BEHA.628@.TK2MSFTNGP10.phx.gbl...
> Hi,
> 1. And my PhysicalNames are correct for the new database but the
> LogicalNames remain the same as the original database. Is this correct?
> Yes , You can do that.
> 2. Is the TSQL incorrect above or can I "rename" the LogicalName for the
new
> database?
> It is not required to rename the logical file name. Only physical
name
> need to be changed.
> Thanks
> Hari
>
>
>
> "Carol" <pooch@.hotmail.com> wrote in message
> news:uV8zua2BEHA.2600@.TK2MSFTNGP09.phx.gbl...
> an
LogicalNames
> database.
new
>|||Carol
-- Rename Logical name
-- Created by OJ Date: 05-24-00
---
Set quoted_identifier off set ansi_nulls on
Set nocount on
-- Allow system files to be updated
Exec sp_configure 'allow updates', 1
Reconfigure with Override
go
Declare @.dbname varchar(30),
@.newDataName varchar(64),
@.newLogName varchar(64)
Select @.dbname=rtrim(ltrim(db_name()))
Select @.newDataName=@.dbname + '_Dat',
@.newLogName=@.dbname + '_Log'
Select 'The OLD logical name for ' + rtrim(filename) + ' is: ' + name from
sysfiles1 where fileid=1
Select 'The OLD logical name for ' + rtrim(filename) + ' is: ' + name from
sysfiles1 where fileid=2
-- Update dataName
Update sysfiles1
set name=@.newDataName
where fileid=1
-- Update LogName
Update sysfiles1
set name=@.newLogName
where fileid=2
Select 'The NEW logical name for ' + rtrim(filename) + ' is: ' + name from
sysfiles1 where fileid=1
Select 'The NEW logical name for ' + rtrim(filename) + ' is: ' + name from
sysfiles1 where fileid=2
set nocount off
go
"Carol" <pooch@.hotmail.com> wrote in message
news:eYKkYo2BEHA.2888@.TK2MSFTNGP09.phx.gbl...
> Hi Uri,
> This database needs to be a snapshot of data (ArchivedData) and it cannot
be
> altered in any way. So I wasn't sure... if it's connected to the origianl
DB
> somehow I would have problems. Also if I have to DROP the new DB on
> occassion , I can't have the Original DB dropped too if SQL's looking for
> LogicalName to DROP.
> :-O
> I'm not sure how to rename...I've been playing around with sp_rename
> procedure but what type of "object" is the LogicalName?
> I guess if the two databases aren't connected in any way, I can just leave
> it as is...and keep my fingers crossed.
> ;)
> Thanks for your quick response!
>
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:uVFBDh2BEHA.1140@.TK2MSFTNGP10.phx.gbl...
as
> LogicalNames
> new
>|||If you are using SQL 2000, you can change the logical file names after the
restore with the NEWNAME parameter on ALTER DATABASE ... MODIFY FILE. For
example:
ALTER DATABASE MyNewDatabase
MODIFY FILE
(NAME='MyOriginalDatabase_Data', NEWNAME='MyNewDatabase_Data')
GO
As previously mentioned in this thread, the scope of the logical name is
local to the database so the logical name is cosmetic.
Hope this helps.
Dan Guzman
SQL Server MVP
"Carol" <pooch@.hotmail.com> wrote in message
news:uV8zua2BEHA.2600@.TK2MSFTNGP09.phx.gbl...
> Hello!
> I have a question regarding the "LogicalName" when restoring a backup as
an
> entirely different database.
> I run this:
> USE master
> GO
> RESTORE FILELISTONLY
> FROM DISK='C:\Program Files\MyApp\Archives\Archive_20000311.BAK'
> RESTORE DATABASE MyNewDatabase
> FROM DISK= 'C:\Program Files\MyApp\Archives\Archive_20000311.BAK'
> WITH RECOVERY,
> MOVE 'MyOriginalDatabase_data' TO 'C:\Program
> Files\MyApp\MSSQL$MYAPP\Data\MyNewDataba
se_data.mdf',
> MOVE 'MyOriginalDatabase_log' TO 'C:\Program
> Files\MyApp\MSSQL$MYAPP\Data\MyNewDataba
se_log.ldf'
> GO
> And my PhysicalNames are correct for the new database but the LogicalNames
> remain the same as the original database. Is this correct?
> I cannot have the new database have any ties/links to the original
database.
> Is the TSQL incorrect above or can I "rename" the LogicalName for the new
> database?
> Thank you in advance for your time.
>|||Thanks, Dan!

(This newsgroup ROCKS!)

Carol
"Dan Guzman" <danguzman@.nospam-earthlink.net> wrote in message
news:uBX3G32BEHA.712@.tk2msftngp13.phx.gbl...
> If you are using SQL 2000, you can change the logical file names after the
> restore with the NEWNAME parameter on ALTER DATABASE ... MODIFY FILE. For
> example:
> ALTER DATABASE MyNewDatabase
> MODIFY FILE
> (NAME='MyOriginalDatabase_Data', NEWNAME='MyNewDatabase_Data')
> GO
> As previously mentioned in this thread, the scope of the logical name is
> local to the database so the logical name is cosmetic.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Carol" <pooch@.hotmail.com> wrote in message
> news:uV8zua2BEHA.2600@.TK2MSFTNGP09.phx.gbl...
> an
LogicalNames
> database.
new
>|||I do not recommend hacking system tables, especially as there is a supported
way to change the logical file names in SQL2K: ALTER DATABASE.
(Not only isn't it supported, but in SQL2K, the database file information is
mirrored in master..sysaltfiles!)
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:Oj8kK22BEHA.2380@.TK2MSFTNGP10.phx.gbl...
> Carol
> -- Rename Logical name
> -- Created by OJ Date: 05-24-00
> ---
> Set quoted_identifier off set ansi_nulls on
> Set nocount on
> -- Allow system files to be updated
> Exec sp_configure 'allow updates', 1
> Reconfigure with Override
> go
> Declare @.dbname varchar(30),
> @.newDataName varchar(64),
> @.newLogName varchar(64)
> Select @.dbname=rtrim(ltrim(db_name()))
> Select @.newDataName=@.dbname + '_Dat',
> @.newLogName=@.dbname + '_Log'
> Select 'The OLD logical name for ' + rtrim(filename) + ' is: ' + name from
> sysfiles1 where fileid=1
> Select 'The OLD logical name for ' + rtrim(filename) + ' is: ' + name from
> sysfiles1 where fileid=2
> -- Update dataName
> Update sysfiles1
> set name=@.newDataName
> where fileid=1
> -- Update LogName
> Update sysfiles1
> set name=@.newLogName
> where fileid=2
> Select 'The NEW logical name for ' + rtrim(filename) + ' is: ' + name from
> sysfiles1 where fileid=1
> Select 'The NEW logical name for ' + rtrim(filename) + ' is: ' + name from
> sysfiles1 where fileid=2
>
> set nocount off
> go
> "Carol" <pooch@.hotmail.com> wrote in message
> news:eYKkYo2BEHA.2888@.TK2MSFTNGP09.phx.gbl...
cannot
> be
origianl
> DB
for
leave
backup
> as
the
>

Restore and update problem on Windows

Hi,
I have restored a database from a BAK file and tried to run a update query.
While executing the query , i got this error.

Server: Msg 208, Level 16, State 1, Procedure ctsv_992F1918D5FC11D4968C0090271F4533, Line 2
Invalid object name 'MSmerge_contents'.

What can be the possible reasons for the error?
Suggest the solutions if any.Which version of sql server are you using ? Are you using merge replication ?|||Hi,
I am using the MS SQL Server 2000.
About merge replication, i am not aware of this as i am a new user. More over we are restoring the backup that we have, from the restored database we can see all this views and procedures which are used for merge replication.
How can we check that we are using merge replication?

Regards,|||Look under enterprise manager - go to the replication folder - look at publications or subscriptions and you should see entries.|||Are you restoring onto the same sql server instance ? Are you only restoring a particular database ?|||Hi,
There are no entries in the Publications and Subscriptions folder.
We are restoring a particular backup that we got from our client.|||Are you saying then that this is not a backup of the current machine you are working with - it was a backup of another sql server machine ? Or are you restoring on the clients machine ?|||Hi,
Yes , you guessed that correctly.
It's a backup from some other machine (client's db backup) and we are restoring it on our machine for fixing few things.
This original database is not with us and we do not have details of his machine either. We only have the .BAK file.|||Without that information, you are running in the fog. My only recommendation is to try and run sp_mergecleanupmetadata - make sure you read the bol about this stored procedure. The only problem is that you have no replication so this stored procedure may be of no use. Let me know if you have any success with this.

When you say you are fixing a few things - will these fixes go back to the client ?

Tuesday, February 21, 2012

restore

Hi,
When I run the sql:
RESTORE DATABASE mydb
FROM DISK='\\myserver\mydb.bak'
Got error:
Msg 3201, Level 16, State 2, XXXDELL, Line 2
Cannot open backup device
\\myserver\mydb.bak' . Device
error or device off-line. See the SQL Server error log for more
details.
Msg 3013, Level 16, State 1, Server XXXDELL, Line 2
RESTORE DATABASE is terminating abnormally.
the path is right.
is it restore statment support UNC? how to fix it? Thanks.Make sure that the SQL Server service account has permissions on the share.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"js" <js@.someone@.hotmail.com> wrote in message news:%23nqb0uusFHA.524@.TK2MSFTNGP12.phx.gbl.
.
> Hi,
> When I run the sql:
> RESTORE DATABASE mydb
> FROM DISK='\\myserver\mydb.bak'
> Got error:
> Msg 3201, Level 16, State 2, XXXDELL, Line 2
> Cannot open backup device
> \\myserver\mydb.bak' . Device
> error or device off-line. See the SQL Server error log for more
> details.
> Msg 3013, Level 16, State 1, Server XXXDELL, Line 2
> RESTORE DATABASE is terminating abnormally.
> the path is right.
> is it restore statment support UNC? how to fix it? Thanks.
>
>|||Check that the sql agent services account has read permission to the unc
folder.
AMB
"js" wrote:

> Hi,
> When I run the sql:
> RESTORE DATABASE mydb
> FROM DISK='\\myserver\mydb.bak'
> Got error:
> Msg 3201, Level 16, State 2, XXXDELL, Line 2
> Cannot open backup device
> \\myserver\mydb.bak' . Device
> error or device off-line. See the SQL Server error log for more
> details.
> Msg 3013, Level 16, State 1, Server XXXDELL, Line 2
> RESTORE DATABASE is terminating abnormally.
> the path is right.
> is it restore statment support UNC? how to fix it? Thanks.
>
>
>|||Hi
RESTORE DATABASE mydb
FROM DISK='\\myserver\mydb.bak'
is not valid.
RESTORE DATABASE mydb
FROM DISK='\\myserver\sharename\mydb.bak'
would be right and make sure the service account has rights to the share.
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"js" wrote:

> Hi,
> When I run the sql:
> RESTORE DATABASE mydb
> FROM DISK='\\myserver\mydb.bak'
> Got error:
> Msg 3201, Level 16, State 2, XXXDELL, Line 2
> Cannot open backup device
> \\myserver\mydb.bak' . Device
> error or device off-line. See the SQL Server error log for more
> details.
> Msg 3013, Level 16, State 1, Server XXXDELL, Line 2
> RESTORE DATABASE is terminating abnormally.
> the path is right.
> is it restore statment support UNC? how to fix it? Thanks.
>
>
>|||"Alejandro Mesa" wrote in message
news:73490624-C538-4CC3-9C9A-B40710E0E0B1@.microsoft.com...
> Check that the sql agent services account has read permission to the unc
> folder.
>
Thanks for the help.
is it sql agent services account or sql server account?|||SQL Server service account.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"js" <js@.someone@.hotmail.com> wrote in message news:eDlbE%23usFHA.3852@.TK2MSFTNGP15.phx.gbl
..
> "Alejandro Mesa" wrote in message news:73490624-C538-4CC3-9C9A-B40710E0E0
B1@.microsoft.com...
> Thanks for the help.
> is it sql agent services account or sql server account?
>|||sql agent services account
AMB
"js" wrote:

> "Alejandro Mesa" wrote in message
> news:73490624-C538-4CC3-9C9A-B40710E0E0B1@.microsoft.com...
> Thanks for the help.
> is it sql agent services account or sql server account?
>
>|||Sorry for the wrong info. In order to backup or restore from a shared folder
,
the sql server service should use a domain account and this account should
have enough permission to read and / or write to it.
AMB
"Alejandro Mesa" wrote:
> sql agent services account
>
> AMB
> "js" wrote:
>