Solved

Problem with a Job (detach - copyto - attach)

Posted on 2006-11-09
10
420 Views
Last Modified: 2008-02-01
I have a job (SQL 2005, Win Server 2003 Ent) with a 3 steps:

1. EXEC sp_detach_db 'MyDB'

2. xcopy "C:\Data\*.*" c:\Backup\ /y/s/e/q/h/r               - all credentials and proxies are fine

3. EXEC sp_attach_db 'MyDB', 'C:\Data\MyDB.mdf'

First and third steps work fine, but 2nd steps gives an error "Access denied"
What I've found yet:
after 1st step the file MyDB.mdf has the only 'System' permission left;
so, the 2nd gives an error;
after 3rd step - all permissons are back (I mean 'Admins', 'Users' etc)

Help, please.
0
Comment
Question by:vadim63
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17908102
Make sure that the user with which u connect to sql server has enough permission to move the data
0
 
LVL 43

Expert Comment

by:Eugene Z
ID: 17908147
<I have a job>
is it sql server agent job?

Make sure it own\ run by 'sa'
0
 
LVL 7

Expert Comment

by:CharliePete00
ID: 17908250
Have you tried using the Copy database wizard in Management Stdio instead?
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 10

Author Comment

by:vadim63
ID: 17908288
Yes, It is sql server agent job, it own\ run by 'sa' and user has 'admin' permissions with a full control. But, as I stated above, after sp_detach_db all permissions (exept 'System') are gone. And I can get it back after sp_attach_db only. Any ideas?
0
 
LVL 30

Accepted Solution

by:
nmcdermaid earned 500 total points
ID: 17911203
Does the sql server agent service account have enough permissions to copy the file?
0
 
LVL 10

Author Comment

by:vadim63
ID: 18222169
Sorry for the delay. I was out of country. Nmcdermaid is right. It was a permission issue. Thank you.
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 18226270
@vadim63,

I hope you didn't see my post :(
0
 
LVL 30

Expert Comment

by:nmcdermaid
ID: 18226366
Might be some miscomunication here. Strictly speaking it's not the user that connects to SQL Server that needs rights its the SQL Agent.
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 18226368
hmmm, i really mean that , Seems like i didn't type that ..
0
 
LVL 30

Expert Comment

by:nmcdermaid
ID: 18226741
hehe I know the feeling :)
0

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question