SQL 2005/Mgmt Studio won't close database on exit

  • I created a database (development) and tables using Mgmt Studio. When I access the database using Mgmt Studio it won't release the database when I exit Mgmt Studio. I disconnect from Object Explorer before I exit the app. When I try to access the db form my app in VS the db is in use or if I try to copy the file to my thumb drive for backup I can't because the file is in use. The only solution that works is to reboot the computer.

    Anybody have any ideas.

    TH

  • Management studio doesn't create anything. It submits your code to the server, which compiles and executes it. The server process opens database files and holds them open while it's running. If you stop the server service, you can copy the files.

    You can also detach the database and copy the files.

  • Thanks!

    I can detach the db everytime I leave to Mgmt Studio and that should solve the issue. I really appreciate the reply. I am moving to SQL Server and am just learning the in and outs.

  • Is your db in single user mode. other wise there shud be no issues to connect to it from the app.

    instead of attaching and detaching you can do a backup and restore.

    "Keep Trying"

  • Lookup Backup in the books online.

    You might also look at this[/url].

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Thanks everyone. I can go on now to working on other self induced problems. (Am I the only one who spends more time debuging than writing code?) I can't tell you how great it is to be able to get help this way. It sure is better than the old days of beating your head against the wall untill you give up and decide to fix the problem by some crude workaround.

    TH

  • The other thing you can do, if you don't want to have to detach the database every time you shut down Management Studio, is set the database options to "Auto Close" to "True".

    You can either use Management Studio to do this, by right-clicking on the database and going to Properties, Options, and set Auto Close to "True", or you can use the following command:

    Alter Database -- Your DB name here

    set Auto_Close On

    (You'll have to fill in your database name, of course.)

    If you do that, you can copy the database files just so long as nobody has a connection open to that particular database.

    Generally, it's a really bad idea to have this option turned on, but for what you need, it might work.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • If you detach it every time, you'll need to attach it again. It won't be in your list of databases.

    What are you trying to do here? Meaning what's your process for doing things? Perhaps we have a better solution (like backup/restore suggested above).

  • I am converting large data files from a txt format and adding them in to SQL Server db. I'll write the code in C# to parse and organize the data from the text file and then add the data to the db. I use Management Studio to check on the data that was imported and run various queries to validate the process. I have done this type of thing before and never had a problem switching back and forth from Management Studio to Visual Studio. I don't know why I am having problems this time, as I haven't changed anything.

    I recently updated my video driver (NVIDIA for a HP portable with embedded 8600 M GS) and have been having problems with the driver failing. HP wants me to send the computer back so they can play with it, but last time I did that I was without a computer for 4 months! Don't think I do it again unless it totally fails. I don't know if this is the cause of the problem.

    Thanks,

    TH

  • How are you adding to the DB? I don't see any place in there where you need to shut down the db file. You should be inserting into the database using server commands.

    If you are using Compact edition files (.sdf), there might be some strange file locking there.

  • I am using SQL commands via C#. I never shut down the db. The db remains in use by Management Studio and is never released for use by another. I use connection.open and connection.close in C# and always close the connection at the end of every transaction.

    TH

  • What is your connection string? There is a 'feature' for SQL Server 2005 call User Instances that you may be running into.

    If you are using AttachDbFilename in your connection string, that is probably what is happening.

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • Sorry for the delay in responding to your reply. I just saw the "page 2" notification and had not seen your entry. I have solved the problem well enough to continue working by setting Auto Close to "true". It made things so I could continue working without rebooting. Now the only question is: Now that I have an answer how do I indicate that the topic should be closed?

    Thanks again to everyone for all the help.

    TH

    No nifty quotes yet, but I'm looking for one.:)

  • I don't know of a formal method to mark a thread as done. Usually, they just end with the original poster saying something like you just did. "Hey, it worked", or "I fixed it", or something like that.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Thanks everyone. It's working!

Viewing 15 posts - 1 through 15 (of 15 total)

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