ulrich.fuchs
16th January 2003, 09:23
I have a customer which had a virus on it's Baan server two days ago.

It seems the virus broke the SQL server database. As far as I have understood, there are two database files, one for the data, another one for the transaction log(?). The database file seems ok, the other file has size 0 bytes now.

SQL Server doesn't start up any more.
Has anybody an idea if - and if, how - the database can be restored from just this one file? Otherwise the backup from three days ago (Friday) would have to be restored, which - of course - would be not the best thing.

Any help greatly appreciated!!

Darren Phillips
16th January 2003, 12:56
need a bit more information to comment properly but is the sql server service running and other databases are opertating like the master msdb or is the whole sql server enviroment down as this will decide how to start the recovery(check the nt application event logs).

If the sql service is not starting then do a backup and install sql server again and the same service pack level it was on before. restore the database files see if the system comes up.

if it is only the baan database that has a problem then backup the mdf and ldf files. then restore the baan backup database and use

sp_detach_bd (syntax is attached below)

restore the current mdf file


you can then delete the ldf file or just rename it and use
sp_attach_single_file_db (Attaches a database that doesn't have a ldf file).


Syntax
sp_attach_single_file_db [ @dbname = ] 'dbname'
, [ @physname = ] 'physical_name'

Arguments
[@dbname =] 'dbname'

Is the name of the database to be attached to the server. dbname is sysname, with a default of NULL.

[@physname =] 'phsyical_name'

Is the physical name, including path, of the database file. physical_name is nvarchar(260), with a default of NULL.

Return Code Values
0 (success) or 1 (failure)

Result Sets
None

Remarks
When sp_attach_single_file_db attaches the database to the server, it builds a new log file and performs additional cleanup work to remove replication from the newly attached database.

Use sp_attach_single_file_db only on databases that were previously detached from the server using an explicit sp_detach_db operation.

Use sp_attach_single_file_db only on databases that have a single log file. Do not use this stored procedure on databases that have multiple log files.

Permissions
Only members of the sysadmin and dbcreator fixed server roles can execute this procedure.

Examples
This example detaches pubs and then attaches one file from pubs to the current server.

EXEC sp_detach_db @dbname = 'pubs'
EXEC sp_attach_single_file_db @dbname = 'pubs',
@physname = 'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf'




Syntax
sp_detach_db [ @dbname = ] 'dbname'
[ , [ @skipchecks = ] 'skipchecks' ]

Arguments
[@dbname =] 'dbname'

Is the name of the database to be detached. dbname is sysname, with a default value of NULL.

[@skipchecks =] 'skipchecks'

skipchecks is nvarchar(10), with a default value of NULL. If true, UPDATE STATISTICS is skipped. If false, UPDATE STATISTICS is run. This option is useful for databases that are to be moved to read-only media.

Return Code Values
0 (success) or 1 (failure)

Result Sets
None

Remarks
The detached files remain and can be reattached using sp_attach_db or sp_attach_single_file_db. The files can also be moved to another server and attached.

Permissions
Only members of the sysadmin fixed server role can execute sp_detach_db.

Examples
This example detaches the pubs database with skipchecks set to true.

EXEC sp_detach_db 'pubs', 'true'

ulrich.fuchs
16th January 2003, 19:39
Darran, thanks for the help.

My customer decided to restore from the Friday tape, but still this is very useful information here! - Thanks anyway!

benito
16th January 2003, 19:41
There is also a command to rebuild the transaction log,

dbcc rebuild_log

Make sure you have a backup of your db before doing this. Good luck.