Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 .NET Inside SQL Server (2005)
 Problem while attaching Database

Author  Topic 

bharath_kolanda
Starting Member

6 Posts

Posted - 2009-10-12 : 08:25:15
Hello Everyone,

I am facing some problems while attaching database to server. Here is my problem. My application will attach the database to SQlServer, when application started, and detach it before closing the application. After detaching i am removing the ldf file. Suppose if the application crashes or if we terminate the appllciation from task manager, the next time attching will have problem. The next time it will attach properly. Please help how to solve this problem.

Thanks and Regards,
Bharath kumar.K

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-10-12 : 12:35:34
This is a very bad idea. You could end up with a corrupted database as detach/attach is risky. I would highly recommend that you do not add this "functionality" to your application.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2009-10-12 : 12:45:05
DO NOT DELETE the transaction log. It is not an optional part of the database.

http://sqlinthewild.co.za/index.php/2009/06/09/deleting-the-transaction-log/

--
Gail Shaw
SQL Server MVP
Go to Top of Page

bharath_kolanda
Starting Member

6 Posts

Posted - 2009-10-13 : 00:59:48
Hi,

Even if dont remove the log file after detaching, and if close by application abruptly (using tak manager), the next time while attaching it showing problem. before attaching i am checking whether the same database is already attached or not, if it is attached i am
detaching the database by killing the process and then tryring to attach. Even after doing this attaching is failing.

Regards,
Bharath kumar.K
Go to Top of Page

bharath_kolanda
Starting Member

6 Posts

Posted - 2009-10-13 : 01:13:17
Hi,

Ifound out the problem, after detaching the database, i am attaching it directly, becuase of this the problem is coming. I just refreshed the databases and then atatched. Now the error is not coming and database is attaching properly. Thanking for your time.

Regards,
Bharath kumar.K
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-10-13 : 01:29:04
I hope you aren't developing this application for a company and that it is just a test system. You should truly reconsider your design.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2009-10-13 : 03:28:52
quote:
Originally posted by tkizer

I hope you aren't developing this application for a company and that it is just a test system. You should truly reconsider your design.


Agreed.

You should attach the DB once and leave it attached when the app terminates. There is no good reason to detach the DB once the app closes down.

--
Gail Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -