Using Contig to defrag files

  • I've seen a few posts on here about this topic but not many that are helpful for my situation.

    This occurs on both SQL 2005 and SQL 2000 servers.

    When I go to a command prompt and type the following I have success:

    D:\Contig\contig.exe -v E:\SQLData\db.mdf

    When I use Scheduled Task I have success as well.

    Both of them run in about 2 seconds.

    However, inside of SQL I'm having issues.

    The SQL Engine and Agent run under the same domain account, and that domain account is in the local admins group on the box.

    I tried to run it from within a Query window as:

    EXEC xp_cmdshell 'D:\Contig\contig.exe -v E:\SQLData\db.mdf'

    I tried to schedule a job to use CmdExec as:

    D:\Contig\contig.exe -v E:\SQLData\db.mdf

    It just sits there and acts like it's doing something but from what I can tell it isn't and you finally have to cancel it.

    No errors in the event log, Agent Log, or SQL Error Log. Nothing to go off of.

    I've tried it scheduled as different users who are admins but no luck. Does anyone have any ideas?

  • Your SQL Service Account would need to have the necessary rights in the OS to allow it to run this. It isn't based on the user calling xp_cmdshell, its based on the SQL Service Accounts permissions.

    Jonathan Kehayias | Principal Consultant | MCM: SQL Server 2008
    My Blog | Twitter | MVP Profile
    Training | Consulting | Become a SQLskills Insider
    Troubleshooting SQL Server: A Guide for Accidental DBAs[/url]

  • ok, so lets assume we are dealing with domain\login as the account in question. It runs both the engine and agent.

    Under the OS, you have a group called Administrators. Within that group you'll find this account as well.

    On the folder that runs contig, you will find that the account has full permissions.

    Where am I missing it?

  • When you are running this from the query window, are you running it local on the server or remote from your machine? It's possible you're losing the credentials from the jumps.

  • Noticed teh -v in your call also. Try use -q to prevent anything from possible waiting forthe command to exit. This would cause the events to show as they do from xp_cmdshell

    EXEC xp_cmdshell 'D:\Contig\contig.exe -q E:\SQLData\db.mdf'

  • running the query locally on the server.

    tried with -q, -v, and without anything.

    If I got some type of error that might help me know where to look but I've got nothing.

  • I actually think it may be the software license agreement which would make sense from the hanging issue. I only say that because I have successfully recreated your problem. Hopefully I can figure it out quickly for you

  • Can you switch Agent to your account and see if it executes?

  • It was the user agreement coming up in the background and waiting for the Accept command.

    Here is how you'll need to handle it, or how I fixed the issue anyhow.

    Open the contig.exe while logged in as the SQL Server service account. Sense xp_cmdshell sends calls with that account the license agreement that comes up on the first time opened must be accepted as that user. This writes the reg entry and will not come up again.

    Log back out and log in as yourself. Run the command and it shoudl work

    My call was

    Exec xp_cmdshell 'C:\contig.exe -q "E:\SQL2005DATA\2005\MSSQL.3\MSSQL\DATA\dba.mdf"'

  • Ted,

    Thanks for the update.

  • great find. That did it.

  • SQLDenis shared with me the the -accepteula switch which is available on all the sysinternals tools. This also fixed the problem

    Exec xp_cmdshell 'C:\Contig\contig.exe -v -accepteula "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\DBA.mdf"'

Viewing 12 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic. Login to reply