Fail to attach DB in windows 7

i wrote a program with C# to attach database in windows 7, but i get the 
error message:
"the log cannot be rebuilt because the database was not cleanly shut down"
following is the SQL statement
sp_attach_single_file_db  @dbname = 'Test',@physname = 'c:\temp\test.mdf'

0
Utf
4/6/2010 9:45:01 AM
sqlserver.programming 1873 articles. 0 followers. Follow

2 Replies
467 Views

Similar Articles

[PageSpeed] 7

Hi
I think the best solution would to restore the database from the last good 
backup

See some workaround (worked for me on SQL 7/2000)

1. From a query window, set the status so that you can update the system
tables by running the following query:
use Master
go
sp_configure "allow", 1
go
reconfigure with override
go

2. Go into the data directory (MSSQL\DATA) and rename the log file 
associated
the DB in question (XXXX.ldf) to some
temporary name, such as XXXX.TMP.

3. Exit the query window.
4. Then start up SQL Server from a DOS command window by issuing:
sqlservr -c -T3608 -T4022.
5. Bring up another query window and verify that the DB is in emergency mode
by issuing:
select Name, Status from Sysdatabases where name = '<DB_Name>'

6. Verify that the status is 32768. If it is, then issue the query:
dbcc traceon(3604)
dbcc rebuild_log('<DB_Name>','<log_filename>') <--- You will need
the quotation marks
REBUILD_LOG should take less than 5 minutes even on a very large
database. It should complete with the message
DBCC execution completed
7. Take the database out of bypass recovery mode by issuing the command
update sysdatabases set status = 0 where name = '<DBName>'
8. Exit the query window and then shutdown (Ctrl-C in the DOS window) and
restart SQL server. Verify the status of the
database by running  DBCC CHECKDB on the database.




"bin" <bin@discussions.microsoft.com> wrote in message 
news:64A50FCC-FEC6-4433-A95B-25407AF4F4DE@microsoft.com...
>i wrote a program with C# to attach database in windows 7, but i get the
> error message:
> "the log cannot be rebuilt because the database was not cleanly shut down"
> following is the SQL statement
> sp_attach_single_file_db  @dbname = 'Test',@physname = 'c:\temp\test.mdf'
> 


0
Uri
4/6/2010 10:54:40 AM
> "the log cannot be rebuilt because the database was not cleanly shut down"
> following is the SQL statement
> sp_attach_single_file_db  @dbname = 'Test',@physname = 'c:\temp\test.mdf'

Was the database first detached from the source using sp_detach_db?  Be 
aware that the attach might not work if the database was not cleanly 
detached, although you will often get lucky with files that were only 
copied.  Also, sp_attach_db is deprecated; it is better to use CREATE 
DATABASE...FOR ATTACH instead.

-- 
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

"bin" <bin@discussions.microsoft.com> wrote in message 
news:64A50FCC-FEC6-4433-A95B-25407AF4F4DE@microsoft.com...
> i wrote a program with C# to attach database in windows 7, but i get the
> error message:
> "the log cannot be rebuilt because the database was not cleanly shut down"
> following is the SQL statement
> sp_attach_single_file_db  @dbname = 'Test',@physname = 'c:\temp\test.mdf'
> 
0
Dan
4/6/2010 12:00:46 PM
Reply:

Similar Artilces:

Outlook 2000 mail with attachment
I have sent out mail with a Word attachment from Outlook to recipients who use Outlook Express. They are getting the text of the message but not the Word attachment. Has anyone seen this problem and what is the fix? Bryan ...

FindResourceEx fails.
Hello I cant the the following function to work. FindResourceEx returns NULL. TRACE prints 1814 as error. m_wLanguage is 1053, and I got swedish as a lang in my resourcefile. const char* CResourceLoader::GetString(int nId) { HRSRC hResource = FindResourceEx( NULL, RT_STRING, MAKEINTRESOURCE(nId), m_wLanguage); TRACE("%d\n", GetLastError()); if (!hResource) { char szString[512]; LoadString(NULL, nId, szString, 512); return szString; } else return (const char*)LoadResource(NULL, hResource); } Jonas > I cant the the following function to work. FindResourc...

Problem with NDR 5.7.1 / 554
Hello everybody. We have a problem with a user that have sent an e-mail to an external receipt. When the internal user sent the e-mail to this external user, he receive the following NDR: The following recipient(s) could not be reached: external.user@anotherdomain.com on 6/27/2005 5:32 PM You do not have permission to send to this recipient. For assistance, contact your system administrator. <MY_SMTP_SERVER@mydomain.com #5.7.1 smtp;554 5.7.1 Message cannot be accepted, spam filter rejection> I want to know what is the most likely cause for this problem. Thanks the NDR says it...

Quick Campaigns are failing
Quick campaigns used to work for us but don't anymore. I get the following error after creating the quick campaign: This Quick Campaign could not be performed due to an error: 0x80131500. For more information, contact your system administrator. with the "Status Reason = aborted" I've searched everywhere for this error but can't find anything. Has anyone seen this before? The only change I made to the server was to use the rule deployment wizard but I also did this on another CRM installation server and Quick Campaigns still work there. Update to this: ...

Windows XP Explorer
How do I get Windows Explorer to default to viewing files in detail as opposed to the current default, tile? Thank you. Click View "Mike Hirsch" <mike.hirsch@icxt.com> wrote in message news:%23DMV8OLkKHA.1540@TK2MSFTNGP06.phx.gbl... > How do I get Windows Explorer to default to viewing files in detail as > opposed to the current default, tile? Thank you. > Mike Hirsch wrote: > How do I get Windows Explorer to default to viewing files in detail as > opposed to the current default, tile? Thank you. > > Tools, Folder Opti...

attachments #69
I've had people tell me that they tried to send me an email with an attachment and it wasn't able to go trhough. Do I need to do something in Outlook to allow attachments, or could it be my antivirus software? What version of Outlook? Are the messages in question telling you that attachments to the messages were blocked by Outlook? -- Jocelyn Fiorello MVP - Outlook *** Messages sent to my e-mail address will NOT be answered -- please reply only to the newsgroup to preserve the message thread. *** In news:E8882194-B97D-45F0-9EB2-2D53ED1E6FF3@microsoft.com, DaveB wrote: > I...

Re: connection fails daily
On 18/12/2009 23:42, fcsark9handler wrote: ????????? *What* did the poster write? -- Dave (Sometimes man stumbles over the truth ...... Sir Winston Churchill) ...

Unexpected characters appear in Windows
Am running Windows Vista Home Premium, SP 1 with Windows Mail. Due to catastrophic hardware malfunctions I bought a new system with the new OS installed for about two days. Thus far, only Windows Mail shows this problem. If I go to use end bracket for example (>) - something I like to use when quoting back replies - it appears only as a period (.) Question marks (?) come up as some kind of French letter with an accent. All of the things associated with shift+"x" seem to be fouled ... A multitude of other characters are also wrong but I think only highlighting...

Consistency Check fails and fails and fails ...
Hello all last Tuesday, we had a Blue Screen on our Home Directories server. After having it restarted, I got a DPM error, thus needing a Consistency Check. Today, one week later, I did 30 Consistency Checks, all having failed with all kinds of errors: - DPM encountered an error while performing an operation for \\?\Volume{83986761-1bce-4d28-bf4c-25bf9d86a50f}\HomeDirectories\K... (ID 2033 Details: The system cannot find the file specified (0x80070002)) - DPM encountered an error while performing an operation for \\?\Volume{83986761-1bce-4d28-bf4c-25bf9d86a50f}\HomeDirectories\G...

Outlook attachments
I used to know how to adjust the Outlook security settings so people can open blocked attachments. Something about a form and adding a registry key? Can someone point me to the KB article? Thanks in advance. Try this one KB290499 (OL2002: Administrator Information About E-Mail Security Features). I think it might be what you are looking for. "Laura" <anonymous@discussions.microsoft.com> wrote in message news:08ec01c3d916$5468fb60$a101280a@phx.gbl... > I used to know how to adjust the Outlook security > settings so people can open blocked attachments. > Someth...

Why is collection failing?
I'm creating a wrapper class for a collection object, mainly so I can test whether a given records exists. I'm baffled as to why I'm getting "Invalid procedure or argument" in the exists function when I try to extract the value, whether it actually exists or not. I've tried collection.item and collection(item), same result. BTW, the values are numbers that I convert to strings. Option Compare Database Option Explicit 'this class object extends the collection object to include an 'exists' boolean function Private colStatus As VBA.Collection Private S...

Attachements to email
When I attach files to an email it is attaching them in the body of the email instead of under the subject line. How do I change the setting? That behavior is determined by your message format and Outlook version, neither of which you mentioned. Explain why you think it matters. -- Russ Valentine [MVP-Outlook] "Castle Rock" <Castle Rock@discussions.microsoft.com> wrote in message news:2AFEF625-DABE-49D1-9EAB-A1B302678462@microsoft.com... > When I attach files to an email it is attaching them in the body of the > email > instead of under the subject line. How do I...

Windows 7 with IE 8 64 bit problems
I hope someone can assist me. I'm trying to load two programs on my new laptop, both seem to have compatibility issues with Windows 7 and/or 64 bit. How can I change my IE settings to 32 bit. The two programs are: Desktop weather (from weather.com) VZAccess Manager (used to tether my Blackberry for wifi access) Both seem have an issue with 64 bit, so I wanted to change it to 32 bit but don't know how. Appreciate anyone's suggestions or help! Thanks, Cheryle Windows 7 64-bit includes both 32-bit and 64-bit versions of Internet Explorer 8. --- Leonard G...

Remake deleted account in Windows Live Mail
Hi, is it possible to remae an acount I have removed from Windows Live Mail ? Or just a possibility to import the emails there was in the 2 account I removed ? I did not think the program would delete the emails, when I removed the account settings. Hope someone can help, as there are some emails I would like to save. Best wishes Steen Did you look on the web access for those accounts to see if the emails are still out there? "steendk" <steendk@discussions.microsoft.com> wrote in message news:652B3826-1F5C-4309-99DC-7EE579109C44@microsoft.com......

CreateDirectoryW fails
Hi I want to create a directory with more then 300 characters. I am using the CreateDirectoryW function and prepending \\?\ to the path for eg.. CreateDirectoryW("\\\\?\\C:\\Temp\\..." some long name but the function fails with error 123. What could be the problem. I am working on Windows 2000. Regards Jakir Would it hurt to tell us what error 123 means? (I looked it up and it says the fllename syntax is illegal). Give your code snippet below, I'm not surprised. Take a look at CreateDirectoryW. What is its argument type? A Unicode string. So you should supply a Unic...

I certainly love to hate Outlook blocking attachments
Having just lost a day because the Access database someone tried to send me got blocked by Outlook, I finally came across William Kennedy's article "Blocked attachments: The Outlook feature you love to hate." Well I agree with you in one respect, Mr Kennedy. I certainly hate this feature. It has that sort of "nanny state" feel about it ("nanny state" is a common derogatory phrase in the UK for when government or officialdom impose unnecessary restrictions on people, supposedly for their own good). There are two things that mystify me. Firstly, ...

Unable to forward attachments
When our users receive email in MS CRM that have attachments, they are unable to forward this email without having to re-attach the attachment. Is this a feature of the app or is there a problem with the functionality? ...

Adding more RAM to Windows XP?
Laptop with Windows XP Pro, 1.66GHz/Duo with 2G of RAM. If I upgrade to 4G RAM - is it always good to upgrade WinXP from 2G to 4G RAM? Can anyone tell me if there a noticeable hit to battery life? Any downside anyone can share? Thanks!!! Toni wrote: > Laptop with Windows XP Pro, 1.66GHz/Duo with 2G of RAM. > > If I upgrade to 4G RAM - is it always good to upgrade WinXP from 2G to 4G RAM? > > Can anyone tell me if there a noticeable hit to battery life? Any downside anyone can > share? > > Thanks!!! > > > The 32bit v...

Fyi..Support request regarding Windows Live Essential Wave 4 beta
This is a multi-part message in MIME format. ------=_NextPart_000_0178_01CB1938.618266B0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable From the Windows Live Solution Center = http://windowslivehelp.com/thread.aspx?threadid=3D8a67c6f7-8a04-48d0-972e= -1252034d6390 <qp> To differentiate Windows Live Essentials Installer BETA related issues = from the current version, please add the word =93BETA=94 in the = =93Detailed Descriptions=94 to get your questions answered faster when = creating a Post. This will help ou...

Users failing to log in to Exchange on some PCs but not others.
Last week a number of laptop users reported that whenever they run Outlook 2002 to access exchange they are being prompted with a login dialogue. As they are already authorised network users this should not be happening. I took the most important users laptop and checked the settings to find everything was OK. I started a test profile and tried to set up the user there. Same problem. I went to another PC and set up a new profile and accessed exchange immediately. Back at the laptop, I reinstalled the Outlook Suite, The Network components and anything else I could think may be at fault, but sti...

Unsafe Attachments #9
I'm sure this must have come up before but I can't find a link. I want to send an URL to someone from within IE6. I use the send a link button and up pops an email with the text of the URL. However the email header contains a warning notice stating "This message has not been sent. Outlook blocked access to the following potentially unsafe attachments: xxxxx.url" This is annoying because if I hand copy the URL from IE6 and paste it into an email. ie do it manually, it gets sent with no problem. I've checked on another PC and there it worked. The difference seems to...

Slideshow and attached Music
I have been working on a slideshow presentation of our daughter's wedding. There are 9 different shows that I'm combining to put on a CD. I get each timed to the music selections perfectly and each time I play them back or burn a CD they are different.....the picture timings are delayed, sometimes by 3-4 sec. It's never the same twice. Eventually I want to be able to play the finished (perfect) slide show on a TV. But that's another subject to tackle when this one is resolved. HELP!!!! -- Mary J. in Washington Try to make a film of your presentation just ...

Assertion while creating a window
Hello there, I am trying to add a window as a tab of tab control. My tab control already has two tab ( tree controls are attached to both tabs) Now I am trying to create a window and attaching a window to third tab. So I created a class CSearchTabWnd derived from CWnd and trying to create it in OnCreate of tab control. But I am getting an assertion failure when I call create method of CSearchTabWnd. Let me know where I am wrong ! Assertion is at ASSERT(pWnd->m_hWnd == NULL); in AfxHookWindowCreate // Create Search Tab Window if(!m_wndSearchTab.Create(NULL,"Search",WS_CHILD | WS_V...

Alter Outlook attachments inside emails
I would like to: 1) Open an attachment in my mailbox (eg: test.docx) 2) Modify it 3) Save it, not saving as another file .. but actually modifying the attachment itself Is it possible ? Thanks. It's possible - as long as you do not close the message it was attached to before saving. So - open the message, then the attachment, then edit and close the attachment before closing the message. See http://www.slipstick.com/outlook/securetemp.htm for more info. -- Diane Poremsky [MVP - Outlook] Outlook Tips: http://www.outlook-tips.net/ Outlook & Exchange Solutions C...

window
How do I create a full screen main window by MFC (like games) You need to look into the DirectX SDK. HTH -- ============ Frank Hickman NobleSoft, Inc. ============ Replace the _nosp@m_ with @ to reply. "Arman Sahakyan" <anonymous@discussions.microsoft.com> wrote in message news:011e01c3c6d3$227ad420$a001280a@phx.gbl... > How do I create a full screen main window by MFC (like > games) See the following: Adding a Full Screen Feature to an MFC Application ID: Q164162 http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B164162 -- Ajay Kalra [MVP - VC++] aj...