Exclusive access could not be obtained because the database is in use

Hi
I am trying to use sql server 2005 management stodio to restore a database. But I got this error message:
Exclusive access could not be obtained because the database is in use
Anyone know how to solve this problem?
Thanks
Li

 Li556035 wrote:
Hi
I am trying to use sql server 2005 management stodio to restore a database. But I got this error message:
Exclusive access could not be obtained because the database is in use
Anyone know how to solve this problem?
Thanks
Li
If you don not have any process running on your pc that uses your database like Enterprise Manager or any other third party application, use
SqlConnection.ClearAllPools();
 in C# code before restoring. Like the following code:
Code Snippet
public void BackupAndRestore(string Query)
     SqlConnection.ClearAllPools();
SqlConnection connection = new     SqlConnection(ConfigurationManager.AppSettings["ConnectToMasterDB"]);
     SqlDataAdapter da = new SqlDataAdapter();
     da.SelectCommand = new SqlCommand();
     da.SelectCommand.Connection = connection;
     da.SelectCommand.CommandText = Query;
     da.SelectCommand.ExecuteNonQuery();

Similar Messages

  • Error - Exclusive access could not be obtained because the database is in use

    I am actually trying to make a script (in Sql Server 2008) to restore one database from one backup file. I made the following code and I am getting an error -
    Msg 3101, Level 16, State 1, Line 3
    Exclusive access could not be obtained because
    the database is in use.
    Msg 3013, Level 16, State 1, Line 3
    RESTORE DATABASE is terminating abnormally.
    How do I fix this problem ?
    IF DB_ID('AdventureWorksDW') IS NOT NULL
    BEGIN
    RESTORE DATABASE [AdventureWorksDW]
    FILE = N'AdventureWorksDW_Data'
    FROM
    DISK = N'C:\Program Files\Microsoft SQL Server\
    MSSQL10_50.SS2008\MSSQL\Backup\AdventureWorksDW.bak'
    WITH FILE = 1,
    MOVE N'AdventureWorksDW_Data'
    TO N'C:\Program Files\Microsoft SQL Server\
    MSSQL10_50.SS2008\MSSQL\DATA\AdventureWorksDW.mdf',
    MOVE N'AdventureWorksDW_Log'
    TO N'C:\Program Files\Microsoft SQL Server\
    MSSQL10_50.SS2008\MSSQL\DATA\AdventureWorksDW_0.LDF',
    NOUNLOAD, STATS = 10
    END

    Check, if there are existing connections to the database you are restoring by following command
    select spid from sys.sysprocesses where dbid = db_id('AdventureWorksDW')
    if you see any existing connections then kill them by issuing KILL command Syntax for kill is
    KILL <SPID>
    once you see there are no more connections then 
    Use mastergoIF DB_ID('AdventureWorksDW') IS NOT NULL
    BEGIN
    RESTORE DATABASE [AdventureWorksDW]
    FILE = N'AdventureWorksDW_Data'
    FROM
    DISK = N'C:\Program Files\Microsoft SQL Server\
    MSSQL10_50.SS2008\MSSQL\Backup\AdventureWorksDW.bak'
    WITH FILE = 1,
    MOVE N'AdventureWorksDW_Data'
    TO N'C:\Program Files\Microsoft SQL Server\
    MSSQL10_50.SS2008\MSSQL\DATA\AdventureWorksDW.mdf',
    MOVE N'AdventureWorksDW_Log'
    TO N'C:\Program Files\Microsoft SQL Server\
    MSSQL10_50.SS2008\MSSQL\DATA\AdventureWorksDW_0.LDF',
    NOUNLOAD, STATS = 10
    END
    Mark as answer, if it works.

  • CS2/W8 - Could not initialize photoshop because the file is locked

    I just upgraded to Windows 8 64 bit last night.  I had been running Cs2 just fine on Windows 7 64 bit for a few years now.   In fact I used it last week.  Now after the upgrade is complete, I get this error message when I try to launch CS2: 
    Could not initialize photoshop because the file is locked. use the properties command in the Windows Explorer to unlock the file.
    Of course, there is no mention of which file is locked. 
    I tried a repair install, it didnt help, same error. 

    HAve you tried resetting preferences?  Start PS and IMMEDIATELY hold down the shift ctrl alt keys.  Should get a reset window if fast enough.

  • When I close Photoshop CS6, the following message appears: "Could not save Preferences because the file is locked, you do not have necessary access permissions, or another program is using the file.

    When I quit Photoshop CS6, the following message appears:
    " Could not save Preferences because the file is locked, you do not have necessary access permissions, or another program is using the file. Use the ‘Get Info’ command in the Finder to ensure the file is unlocked and you have permission to access the file. If the problem persists, save the document to a different file or duplicate it in the Finder."
    If I try to change the Workspace in PS6 from Essentials to any other Workspace, the following messsage appears:
    "Could not apply the workspace because the file is locked, you do not have necessary access permissions, or another program is using the file. Use the ‘Get Info’ command in the Finder to ensure the file is unlocked and you have permission to access the file. If the problem persists, save the document to a different file or duplicate it in the Finder."
    I have checked the Sharing and Permissions section of the "Get Info" panel accessed from the Finder and I have set Read and Write Privileges for my user account for Photoshop CS6. System and Admin are also set to Read and Write.
    I have a MacBook Pro with OS X Version 10.9.5 and have all available updates for Photoshop CS6, Lightroom 5 and Bridge CS6.
    I tried uninstalling the program and downloading it again and reinstalling, but nothing changed.
    Can you help?
    Thanks,
    cjpnm

    You may get better help in Photoshop General Discussion
    The Cloud forum is not about using individual programs
    The Cloud forum is about the Cloud as a delivery & install process
    If you will start at the Forums Index https://forums.adobe.com/welcome
    You will be able to select a forum for the specific Adobe product(s) you use
    Click the "down arrow" symbol on the right (where it says All communities) to open the drop down list and scroll
    If FINDER means Mac, read below (and try to give more information when asking a question)
    Mac 10.9.3 workaround https://forums.adobe.com/thread/1489922
    Enable Mac Root User https://forums.adobe.com/thread/1156604
    -more Root User http://forums.adobe.com/thread/879931
    -and more root user http://forums.adobe.com/thread/940869?tstart=0

  • When accessing my itunes library of music I get the notation on all songs ...The song could not be located because the origional file could not be found...how can this be corrected or did Apple wipe out all the files

    wien I access Itunes I get the notification....the song could not be located because the origional filoe could not be found...I have over 2000
    songs in my library ....Does this mean they are all gone....How can one retrieve them???

    This missing song thing happens if the file is no longer where iTunes expects to find it. Possible causes are that you or some third party tool has moved, renamed or deleted the file, or that the drive it lives on has had a change of drive letter. It is also possible that iTunes has changed from expecting the files to be in the pre-iTunes 9 layout to post-iTunes 9 layout,or vice-versa, and so is looking in slightly the wrong place.
    Select a track with an exclamation mark, use Ctrl-I to get info, then cancel when asked to try to locate the track. Look on the summary tab for the location that iTunes thinks the file should be. Now take a look around your hard drive(s). Hopefully you can locate the track in question. If a section of your library has simply been moved, or a drive letter has changed, it should be possible to reverse the actions.
    Alternatively, as long as you can find a location holding the missing files, then you should be able to use my FindTracks script to reconnect them to iTunes .
    Once you've sorted out the broken links I've written a script called DeDuper which can help remove unwanted duplicates. See this thread for background.
    tt2

  • Whenever I close down Photoshop CS5 I get the message: "Could not save Preferences because the file is locked or you do not have the necessary access privileges. Use the get info command in Finder to unlock the file or change permission on the file or enc

    Whenever I close down Photoshop CS5 I get the message: "Could not save Preferences because the file is locked or you do not have the necessary access privileges. Use the get info command in Finder to unlock the file or change permission on the file or enclosing folders." What on earth does it mean? How can I stop this message from appearing?

    See here:
    I cannot save recent images.

  • When i try downloading adobe pro i am getting an error message that is saying: The application could not be installed because the installer file is damaged. Try obtaining a new installer file from the application author.

    when i try downloading adobe pro i am getting an error message that is saying: The application could not be installed because the installer file is damaged. Try obtaining a new installer file from the application author.

    Hi Kashmore,
    Seems like the downloaded file was corrupt that could be because of either network restriction or the anti virus might have blocked it. My suggestion would be to try and download the product either by turning off the Antivirus or try a different network.
    Cheers,
    Kartikay Sharma

  • Trying to download the free trial of Adobe Acrobat XL Pro.  I keep getting the message "The application could not be installed because the installer file is damaged. Try obtaining a new installer file from the application author."  I've repeatedly tried g

    Trying to download the free trial of Adobe Acrobat XL Pro.  I keep getting the message "The application could not be installed because the installer file is damaged. Try obtaining a new installer file from the application author."  I've repeatedly tried getting a new installer file, but get the same message every time.

    K_don52 and Ande8135 please remove your current installation of the Adobe Download Assistant and reinstall.  You can find more details in the known issues section of Troubleshoot Adobe Download Assistant.

  • ERROR: The operation could not be performed because the file can't be accessed or doesn't exist. Please contact your web developer to correct the problem.

    Only on one page, the client is receiving this error:
    Error - The operation could not be performed because the
    file cant be accessed or doesnt exist. Please contact your web
    developer to correct the problem.
    I tested it with a couple different usernames and a couple different browsers and it works fine on my end.. but none the less it is happening to him. This is the second time it happened to two different clients.
    ??? Any ideas ??? Anyone else had this happen?

    Here's the setup on the two machines in particular...
    Machine #1:
    XP Pro
    Was IE7, now latest FF
    No antivirus
    Firewall – Windows Firewall, Downloaded AVG free trial ver., but not installed
    Machine #2:
    XP Pro
    IE7
    Again, No AV… had Kaspersky… but uninstalled it
    Windows Firewall
    Maybe that could be of some assistance... not seeing anything that could possibly block or inhibit the ICE. Each machine is independent of the other, separate networks, different locations, JavaScript enabled, no cookie blockers, etc.
    ....STUMPED!!!   

  • Could not save Preferences because the file is locked, you do not have necessary access permissions, or another program is using the file. Use the 'Get Info' command in the Finder to ensure the file is unlocked and you have permission to access the file.

    I have this massage every time close ps cc
    Could not save Preferences because the file is locked, you do not have necessary access permissions, or another program is using the file. Use the ‘Get Info’ command in the Finder to ensure the file is unlocked and you have permission to access the file. If the problem persists, save the document to a different file or duplicate it in the Finder.

    You may get better help in Photoshop General Discussion
    The Cloud forum is not about using individual programs
    The Cloud forum is about the Cloud as a delivery & install process
    If you will start at the Forums Index https://forums.adobe.com/welcome
    You will be able to select a forum for the specific Adobe product(s) you use
    Click the "down arrow" symbol on the right (where it says All communities) to open the drop down list and scroll
    If FINDER means Mac, read below (and try to give more information when asking a question)
    Mac 10.9.3 workaround https://forums.adobe.com/thread/1489922
    Enable Mac Root User https://forums.adobe.com/thread/1156604
    -more Root User http://forums.adobe.com/thread/879931
    -and more root user http://forums.adobe.com/thread/940869?tstart=0

  • HT201407 Updated my iphone 3gs to ios 6.0.1. Receive message "your iphone could not be activated because the activation server is temporarily unavailable". The phone could not read my Roger iccid. I tried with wifi and itune. Could not access restore on i

    I can not activate my iphone 3gs after updating to ios 6.0.01. I tried connecting to the activating server by wifi and itune. Keep getting the same message"your iphone could not be activated because the activiation server is temporary unavailable". It could not read my Rogers iccid. I try to restore my phone on itune but it does not have the "restore" icon. Please help.

    bladetibi wrote:
    the same problem i have to......i have to go to my operator to solve my problem????and then i will be able to activate my iphone ???and have service????thx
    See your Other Post on this Topic...
    https://discussions.apple.com/message/20817908#20817908

  • TS1389 i keep having a "the iphone could not be sync because the computer is no longer authorized" i authorize it and still no result

    i keep having a "the iphone could not be sync because the computer is no longer authorized" i authorize it and still no result

    i keep having the same problem, my little cousin changed the passcode to my iphone 4s and she cant remember it. I've tried transfering all data(apps, movies ect..)to my computer but it says i need authorisation, i put in my apple id and it says i am already logged on to 3 out of 5 computers so i press ok and it goes back to the apple id thingy! please someone help me becausei need to access my phone!!!!!!!
    Anyone what do i do!

  • Could not be saved because the source file could not be read.

    I tried to download and after a while, this error message: ''[filename] could not be saved because the source file could not be read.'' I've been on google searching but I could not find the answer can someone PLEASE help me. it happened when downloading a game and I've already seen a few times before but it was less important.
    sorry for the bad english I used a translator.

    This problem isn't only happening with Firefox 4, for windows, as the System Details, and Tags indicate.
    I'm using a Mac laptop (OS X 10.5.8 -- Leopard), using Firefox 6, and have been having this problem with large files for quite a while ... possibly since FF 4, but definitely with FF 5. The large files I've had the problem with are in the 500 - 900 MB range, and from commercial sites as well as most recently with a zip file containing photos from a friend which he uploaded to dl.dropbox.com ... attempted it numerous times, after trying the various suggested "fixes", and each time at around 255 MB, the download quits, with the error that file cannot be read from the server.
    The various proposed solutions I've found on the web -- resetting the user configured options connected to downloads in FF config (about:config); deleting the compreg.dat file in the FF profile folder, don't pause the download (never have done this) etc.
    Others have opined that the problem is flaky intermittent WiFi, or Security/Anti Virus software interfering with FF's accessibility to the file during the download; or a caching problem at one's ISP -- HOWEVER Safari doesn't experience this problem at all. Each time that I've experienced it in FF, I launch Safari, and can download the file completely without any errors.
    Would really like to see someone from Mozilla respond to this ... lots of us are experiencing it.
    Whatever happened to Netscape's ability to recover from download interruptions and resume a download at the point where it had been interrupted (like when a dial up modem dropped the line in the middle of the download) -- sure would be useful to see that feature come back in FF.
    Thanks,
    Muiz

  • I am having trouble dating to version 3.6.14. I am running Linux/Ubutu OS and I get this error message:/tmp/p7x3vko2.part could not be saved, because the source file could not be read. Please help. Thank you , Deb

    I am having trouble dating to version 3.6.14 or updating to the Beta testing. I am running Linux/Ubutu OS and I get this error message:/tmp/p7x3vko2.part could not be saved, because the source file could not be read. Please help. Thank you , Deb

    Solved for me.
    I set the owner/permissions of my profile's mozilla folder's (and all the files in it) to read/write access, and the problem disappeared.
    in linux:''
    * cd /home/myusername/.mozilla
    * chown -cR myusername:mygroup ./
    * chmod -cR +rw ./
    '''Never do that with root privs (nor with sudo)'''

  • "The picture could not be opened because the original image could not be found."

    "The picture XXXXX.jpg could not be opened because the original image could not be found." - I've translated from Portuguese, so it's possible to contain errors on text but I think it is clear to understand.
    This error message has appeared on my screen for a thousand times, repeatedly. I've canceled everyone, but still appears,how this error has ocurred for every picture in my library.
    I gave up, I'm tired to cancel every window. I don't know what to do. And worst, I'm not able to open Settings or any other command, only "Cancel" or "Search Image", and it opens a Finder window that doesn't give me access to iPhoto Library.

    Download iPhoto Library Manager and use its rebuild function. (In Library Manager it's the FIle -> Rebuild command)
    This will create an entirely new library. It will then copy (or try to) your photos and all the associated metadata and versions to this new Library, and arrange it as close as it can to what you had in the damaged Library. It does this based on information it finds in the iPhoto sharing mechanism - but that means that things not shared won't be there, so no slideshows, books or calendars, for instance - but it should get all your events, albums and keywords, faces and places back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one.  

Maybe you are looking for

  • Error message when opening a shared workbook with Excel 2007

    Hello, We would like to share a workbook outside BW (by saving into a serveur).Since we use Excel 2007, we can't anymore open this workbook. We have a message error (see bellow). For your information, it was ok with Excel 2003. When whe save the work

  • I already have a 10-year-old web site. Instructions for iWeb update?

    My web site has been up for ten years. I created it with PageMill 2.0, and now I can't even communicate with it on my new iMac because it's an OS 9 application. That means I'm going back and forth between my old eMac and this one to try and upgrade.

  • Can we capture HTTP response for async message without BPM?

    We are in the process of migrating an XI 2.0 scenario to XI 3.0. The scenario is as follows in XI 2.0 - SAP sends an IDoc to XI which is mapped to an HTTP request and sent to an endpoint.  The HTTP response is captured and shown in SXMB_MONI. When we

  • Export Sales, Local Sales, Scrap Sales and Stock Transfer

    Hi,       i want the scenario for this with configuration           Export Sales, Local Sales, Scrap Sales and Stock Transfer. plz help me guys.

  • An alternate approach to numerous "if" blocks??

    I have a part of code in my application where different objects are instantiated and some processing done based on one variable value. The present approach used numerous "if" statements. I would like to optimize this part of code. Example of how my c