Richard,
If you can programmatically with a bit of string handling work out the dbname based on the filename,
and the files are all in a single directory, and they actually attach ...
Then you may find the following helpful:
set nocount on
declare @CrLf char(2)
set @CrLf = CHAR(13) + CHAR(10)
declare @Path varchar(200)
set @Path = 'c:\mssql\data\'
-- Get list of files in directory
declare @SqlCmd varchar(300)
set @SqlCmd = 'dir ' + @Path + '*.* /a-d /o:d /t:c /n /B'
create table #DirList
(
RowID int identity,
FileOnly varchar(400)
)
insert #DirList ( FileOnly )
exec master..xp_cmdshell @SqlCmd
select 'sp_attach_single_file_db @dbname = [' + left(FileOnly, len(FileOnly)-4) + '], @physname = ''' + @Path + FileOnly
+ '''' + @CrLF + 'Go' + @CrLF
from #DirList
where FileOnly like '%.mdf'
order by RowID
drop table #DirList
Cutting and pasting in Query Analyser ( with a bit of editing to get rid of system databases etc ).
Regards
AJ
[quoted text, click to view] "Richard M." <anonymous@discussions.microsoft.com> wrote in message
news:B988A1D8-4775-441C-8403-8D8C9C557E66@microsoft.com...
> I administer a server with 300 small databases. It appears to be some type of file corruption and now all the
databases are suspect.
>
> I am getting the following errors:
>
> Cannot associate files with differnet databases.
>
> Also: Log file does not match the primary file. It may be from a different database or the log may have been rebuilt
previously.
>
> Device activation error....
>
>
> Now I read several online articles and determined the only way I can recover these databases, is using
"sp_attach_single_file_db"
>
> Now, with 300 databases, that would take several hours. That is the last thing I want to do.
>
> Can someone please help. I dunno what to do. The backups I have are outdated.