Recupero File LOG SQL SERVER 2005

lunedì 03 settembre 2012 - 18.55
Tag Elenco Tags  SQL Server 2005

DavAlpha Profilo | Newbie

Salve a tutti,
Nel tentativo di droppare il file di log sotto SQL SERVER 2005(di dimensioni 22 GB) questo è andato totalmente perso.
Come posso ricostruirlo avendo solo il db MDF ?

Grazie a tutti.

alx_81 Profilo | Guru

>Salve a tutti,
Ciao

>Nel tentativo di droppare il file di log sotto SQL SERVER 2005(di
>dimensioni 22 GB) questo è andato totalmente perso.
Non è una pratica da seguire, anche perchè se il db è online il file non è toccabile.
Direi che quindi hai spendo i servizi e cancellato il file, quando forse ti bastava shrinkarlo se si trattava di un problema di spazio.

>Come posso ricostruirlo avendo solo il db MDF ?
prova a detachare il database e riattaccharlo, dovrebbe creartene uno nuovo, ma attenzione a queste operazioni. Non sono da fare.
Qual era il problema, ci sono altre soluzioni.

>Grazie a tutti.
di nulla!

--
Alessandro Alpi | SQL Server MVP
MCP|MCITP|MCTS|MCT

http://www.alessandroalpi.net
http://blogs.dotnethell.it/suxstellino
http://mvp.microsoft.com/profiles/Alessandro.Alpi

DavAlpha Profilo | Newbie

Ciao grazie per la risposta.
Allora tramite il nostro programma c'è un istruzione che fa queste operazioni:
1)prima interrompe il motore con questo codice
Result = Shell("net stop MSSQL$SQL2005", AppWinStyle.NormalFocus, True)
2)poi scollega il database svuotando il log e ricollegandolo poi successivamente con questo comando
cmd_Temp = New SqlCommand("EXEC sp_detach_db '" & DbName & "', 'true'", mycnn)
Result = cmd_Temp.ExecuteNonQuery()

File.Delete(txtFileLog.Text)
Thread.CurrentThread.Sleep(5000)

sql = "EXEC sp_attach_single_file_db @dbname = '" & DbName & "', " & vbCrLf & _
"@physname = '" & txtFileDB.Text & "'"
cmd_Temp = New SqlCommand(sql, mycnn)
Result = cmd_Temp.ExecuteNonQuery()
mycnn.Close()

MessageBox.Show("Operazione Eseguita Correttamente! Verrà Chiuso il Socket!", "Esito Operazione", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Close()

Però è successo che mentre faceva questa operazione, non so come, mi ha cancellato direttamente il log interrompendo la procedura e mi è rimasto solo il file mdf.

Spero di aver esposto bene il problema.

Ciao e grazie

alx_81 Profilo | Guru

guarda, non voglio approfondire il motivo, ma se riesci, evita assolutamente questa procedura!
A che pro è fatta? Ci sarà pure un problema che questo work around tenta di risolvere.
Se è per problema di spazio, ti invito assolutamente a cambiare approccio. Lo devo scrivere anche per chi ci legge..

>Però è successo che mentre faceva questa operazione, non so come,
>mi ha cancellato direttamente il log interrompendo la procedura
>e mi è rimasto solo il file mdf.
semplicemente non è atomica l'operazione e se qualcosa va storto "in mezzo" non è garantita la transazionalità.

se vuoi cerchiamo una soluzione migliore al problema.
Comunque, come ti dicevo l'attach dovrebbe ricrearlo daccapo.

--
Alessandro Alpi | SQL Server MVP
MCP|MCITP|MCTS|MCT

http://www.alessandroalpi.net
http://blogs.dotnethell.it/suxstellino
http://mvp.microsoft.com/profiles/Alessandro.Alpi

DavAlpha Profilo | Newbie

ho provato a fare questa operazione con la procedura riportata di seguito ma non è andato a buon fine, è come se il database.mdf fosse corrotto

USE master;
GO
EXEC sp_attach_single_file_db @dbname = 'GestNetDB',
@physname =
N'C:\Programmi\sii@net\GestNetDB\GestNetDB.MDF';

aspetto notizie
grazie

alx_81 Profilo | Guru

>ho provato a fare questa operazione con la procedura riportata
>di seguito ma non è andato a buon fine, è come se il database.mdf
>fosse corrotto

Questo è un altro metodo:
CREATE DATABASE TuoDB ON (FILENAME = N'tuopath.mdf') FOR ATTACH_REBUILD_LOG GO

ma se la prima non è andata, credo che dovrai capire qual è l'errore che ti torna l'operazione.
Prova ad usare gli strumenti grafici se non riesci a vedere l'errore (destro mouse sulla cartella dei database --> attach..)

--
Alessandro Alpi | SQL Server MVP
MCP|MCITP|MCTS|MCT

http://www.alessandroalpi.net
http://blogs.dotnethell.it/suxstellino
http://mvp.microsoft.com/profiles/Alessandro.Alpi

DavAlpha Profilo | Newbie

ho risolto il problema chiamando il supporto della msde
il problema era che facendo il detach del database mi ha interrotto l'operazione eliminando il file .LDF e non chiudendomi il file .MDF correttamente.

Soluzione:

ACTION PLAN:

1. Move and Copy your .mdf file to a safe place

2. Create a new database with the same name and with the same .mdf file name and preferably in the same location

3. Stop SQL Server and re-name the new .mdf file

4. Copy over the original .mdf file

5. Start SQL Server and connect to Query Analyzer

6. Rebuild the log using the following steps

a. 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

b. Then set the status of the DB that is giving you the problem (XXXXX) into Emergency Mode by running the following query:

update sysdatabases set status = 32768 where name = '<DBName>'
go
checkpoint
go

shutdown with nowait
go

c. 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.

d. Exit the query window.

e. Then start up SQL Server from a command - prompt window by issuing:

sqlservr -c -T3608 -T4022

f. 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>'

g. Verify that the status is 32768. If it is, then issue the query:

dbcc traceon(3604)
dbcc rebuild_log('<DB_Name>','<log_filename>')

REBUILD_LOG should take less than 5 minutes even on a very large database. It should complete with the message
DBCC execution completed

h. Take the database out of bypass recovery mode by issuing the command

update sysdatabases set status = 0 where name = '<DBName>'

i. Exit the query window and then shutdown (Ctrl-C in the command-prompt window) and restart SQL server. Verify the status of the
database by running DBCC CHECKDB on the database.

Grazie a tutti

Spero sia utile a molti di voi.
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5