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 2000 Forums
 SQL Server Administration (2000)
 Attaching database fails

Author  Topic 

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2003-03-04 : 01:34:29
Hi,
I have a database with a log file more than 700 mb ,to delete the transaction log l dettached the database moved the log file to different location and on attaching the database again got the followigng error :

Error 823: I/O error 38(Reached the end of the file.) detected during read at offset 0000000000000000 in file 'F:\database\log\database_name_log.ldf'.



and from enterprise manager after attaching the file the 'OK' button does not get highlighted.

this was the nightmare .so I really avoid using dettach/dettach for truncating the log files.

Regrads,
harshal.


Expect the UnExpected

Edited by - harshal_in on 03/04/2003 01:41:50

nr
SQLTeam MVY

12543 Posts

Posted - 2003-03-04 : 02:07:49
Should always take a backup before doing this.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2003-03-04 : 02:29:43
quote:

Should always take a backup before doing this.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.


I have already taken a backup.
can u help me with the error please?

Expect the UnExpected
Go to Top of Page

samsekar
Constraint Violating Yak Guru

437 Posts

Posted - 2003-03-04 : 04:59:17
I faced the same problem when i tried to attach my own created ldf file. try to attach again without giving the ldf say..
sp_attach_db @dbname='test', @filename1='c:\test_data.mdf'

Regards,
Sekar

Edited by - samsekar on 03/04/2003 05:01:09
Go to Top of Page

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2003-03-04 : 05:55:17
quote:

I faced the same problem when i tried to attach my own created ldf file. try to attach again without giving the ldf say..
sp_attach_db @dbname='test', @filename1='c:\test_data.mdf'

Regards,
Sekar

Edited by - samsekar on 03/04/2003 05:01:09



If I dont' provide the log file name it says:
Server: Msg 1813, Level 16, State 2, Line 1
Could not open new database 'humdono'. CREATE DATABASE is aborted.
Device activation error. The physical file name 'F:\database\log\database_log.ldf' may be incorrect.
Device activation error. The physical file name 'F:\database\log\database_log1.ldf' may be incorrect.

any IDEAS?

Expect the UnExpected
Go to Top of Page

samsekar
Constraint Violating Yak Guru

437 Posts

Posted - 2003-03-04 : 06:58:32
We can use Create Database For Attach option but a new log file will be created and the data from the old log file will be lost. let me explain the scenario i tried here for the problem. i copied distmdl.mdf file and pasted the same as dummy.mdf and i renamed the distmdl.ldf file to x.ldf.
Then i tried these query.

CREATE DATABASE dummy
ON PRIMARY
(NAME='DummyData',
FILENAME = 'D:\Program Files\Microsoft SQL Server\MSSQL\Data\dummy.mdf')
FOR ATTACH
GO

The Result is
Device activation error. The physical file name 'D:\Program Files\Microsoft SQL Server\MSSQL\Data\distmdl.ldf' may be incorrect.
New log file 'D:\Program Files\Microsoft SQL Server\MSSQL\Data\dummy_log.LDF' was created.

The database was created successfully with a new log file.
I belive these will help you. All the Best

Regards,
Sekar
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-03-04 : 15:19:28
quote:

If I dont' provide the log file name it says:
Server: Msg 1813, Level 16, State 2, Line 1
Could not open new database 'humdono'. CREATE DATABASE is aborted.
Device activation error. The physical file name 'F:\database\log\database_log.ldf' may be incorrect.
Device activation error. The physical file name 'F:\database\log\database_log1.ldf' may be incorrect.




What is the command that you used to attach the database without a log file? You need to use sp_attach_single_file_db. Is that what you used?


Tara
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2003-03-04 : 19:45:55
You also need to delete or rename the old log file otherwise it will still use it.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-03-04 : 19:51:27
quote:

You also need to delete or rename the old log file otherwise it will still use it.


Yeah I was going to mention that too, but I guess I forgot.

Tara
Go to Top of Page

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2003-03-05 : 00:42:41
quote:

quote:

You also need to delete or rename the old log file otherwise it will still use it.


Yeah I was going to mention that too, but I guess I forgot.

Tara




I had already renamed the log files. And i had used the following command:
sp_attach_db @dbname='test', @filename1='c:\test_data.mdf'


I will try using sp_attach_single_file_db and let u know .

Thnks all of u for the response
regards,
Harshal.

Expect the UnExpected
Go to Top of Page

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2003-03-05 : 00:50:35
quote:

quote:

If I dont' provide the log file name it says:
Server: Msg 1813, Level 16, State 2, Line 1
Could not open new database 'humdono'. CREATE DATABASE is aborted.
Device activation error. The physical file name 'F:\database\log\database_log.ldf' may be incorrect.
Device activation error. The physical file name 'F:\database\log\database_log1.ldf' may be incorrect.




Ok I tried using the following command:
sp_attach_single_file_db @dbname='test',@physname = 'f:\database\data\test_data.mdf'


And before that I had renamed the log files
but it gave me the following error:

Server: Msg 1813, Level 16, State 2, Line 1
Could not open new database 'test'. CREATE DATABASE is aborted.
Device activation error. The physical file name 'F:\database\log\test_log.ldf' may be incorrect.
Device activation error. The physical file name 'F:\database\log\test_log1.ldf' may be incorrect.


so this does not seem to work.
Any more Ideas please??
thanks for u'r time.
Regards,
Harshal.

What is the command that you used to attach the database without a log file? You need to use sp_attach_single_file_db. Is that what you used?


Tara



Expect the UnExpected
Go to Top of Page

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2003-03-05 : 01:01:53
quote:

We can use Create Database For Attach option but a new log file will be created and the data from the old log file will be lost. let me explain the scenario i tried here for the problem. i copied distmdl.mdf file and pasted the same as dummy.mdf and i renamed the distmdl.ldf file to x.ldf.
Then i tried these query.

CREATE DATABASE dummy
ON PRIMARY
(NAME='DummyData',
FILENAME = 'D:\Program Files\Microsoft SQL Server\MSSQL\Data\dummy.mdf')
FOR ATTACH
GO

The Result is
Device activation error. The physical file name 'D:\Program Files\Microsoft SQL Server\MSSQL\Data\distmdl.ldf' may be incorrect.
New log file 'D:\Program Files\Microsoft SQL Server\MSSQL\Data\dummy_log.LDF' was created.

The database was created successfully with a new log file.
I belive these will help you. All the Best

Regards,
Sekar



sekar,
As a matter of fact this also didn'work it gave me the same error when I tried renaming the log files ,and after creating a dummy log file of the same name as before it give me the following error:


Server: Msg 823, Level 24, State 6, Line 1
I/O error 38(Reached the end of the file.) detected during read at offset 0000000000000000 in file 'F:\database\log\test_log.ldf'.

Connection Broken


Expect the UnExpected
Go to Top of Page

samsekar
Constraint Violating Yak Guru

437 Posts

Posted - 2003-03-05 : 01:26:15
quote:

sekar,
As a matter of fact this also didn'work it gave me the same error when I tried renaming the log files ,and after creating a dummy log file of the same name as before it give me the following error:


Server: Msg 823, Level 24, State 6, Line 1
I/O error 38(Reached the end of the file.) detected during read at offset 0000000000000000 in file 'F:\database\log\test_log.ldf'.

Connection Broken


Expect the UnExpected



Harshal,

You dont have to create a log file. It will automatically create when the old log file is not found.

Regards,
Sekar
Go to Top of Page

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2003-03-05 : 01:42:13
sekar,
ok thats the whole problem its not creating a new log file,now when i dont create a log file ,i renamed the previous one and tried :

CREATE DATABASE humdono1
ON PRIMARY
(NAME='test_data',
FILENAME = 'f:\database\data\test_Data.mdf')
FOR ATTACH
GO

It again gave the following error:
Server: Msg 1813, Level 16, State 2, Line 1
Could not open new database 'humdono1'. CREATE DATABASE is aborted.
Device activation error. The physical file name 'F:\database\log\test_log1.ldf' may be incorrect.
Device activation error. The physical file name 'F:\database\log\test_log.ldf' may be incorrect.

I thnk shrinking the files is the best option.
what do u say?

regards,
harshal.

Expect the UnExpected
Go to Top of Page

samsekar
Constraint Violating Yak Guru

437 Posts

Posted - 2003-03-05 : 07:22:11
Shrink File is time consuming. I would say Backup Log is the best option.

Regards,
Sekar
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-03-05 : 13:11:47
Shrinking the files is not going to fix your problem, well at least in my opinion. You can not create the database and specify a file that already exists. It has to be a new file. Since that file exists, your only option is to attach it. I realize that attaching isn't working, so you are going to have to restore the database from the backup that you mentioned that you did prior to detaching it.

I would also suggest checking to see if you have any hardware problems. The fact that it is having problems creating a log might mean that you are having disk problems.

Tara
Go to Top of Page

samsekar
Constraint Violating Yak Guru

437 Posts

Posted - 2003-03-06 : 00:34:52
quote:

Shrinking the files is not going to fix your problem, well at least in my opinion. You can not create the database and specify a file that already exists. It has to be a new file. Since that file exists, your only option is to attach it. I realize that attaching isn't working, so you are going to have to restore the database from the backup that you mentioned that you did prior to detaching it.

I would also suggest checking to see if you have any hardware problems. The fact that it is having problems creating a log might mean that you are having disk problems.

Tara



The BOL Says.
FOR ATTACH

Specifies that a database is attached from an existing set of operating system files. There .... Use the sp_attach_db system stored procedure instead of using CREATE DATABASE FOR ATTACH directly. Use CREATE DATABASE FOR ATTACH only when you must specify more than 16 <filespec> items.

Means, We can attach existing files also.
What is your opinion on this tara ??

Regards,
Sekar

Edited by - samsekar on 03/06/2003 00:41:47
Go to Top of Page

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2003-03-06 : 08:48:53
ok ,
I had the previous log filies which i had renamed after dettaching the database ,now i have renamed them back to the orignal names and attached the database successfully with same old huge log files.
After that I tried shrinking the files.
now it has shrunk only one file ,where as I have two log files one of about 730 mb and other a bit smaller than it.


Expect the UnExpected
Go to Top of Page

franco
Constraint Violating Yak Guru

255 Posts

Posted - 2003-03-06 : 09:42:25
harshal_in, I don't think you can detach db and attach db when you have more than one log file if the purpose is to have a new small one t-log.It seems that you have more than one so the trick won't work.

If you need it you can alter the database so that it only has a single log file,perform the detach and attach operation and after that the database can be again altered to add more log files.





Edited by - franco on 03/06/2003 09:45:09
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-03-06 : 13:05:28
quote:

The BOL Says.
FOR ATTACH

Specifies that a database is attached from an existing set of operating system files. There .... Use the sp_attach_db system stored procedure instead of using CREATE DATABASE FOR ATTACH directly. Use CREATE DATABASE FOR ATTACH only when you must specify more than 16 <filespec> items.

Means, We can attach existing files also.
What is your opinion on this tara ??



Hmmm, I have never used CREATE DATABASE FOR ATTACH before. I have never had a problem with attaching a database either though. I agree with Franco that the problem is because he is using more than one transaction log file. You should do what Franco suggests: alter your database to use only one transaction log, perform the detach, perform the attach using sp_attach_single_file_db, then alter your database to add a transaction log.

Tara
Go to Top of Page

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2003-03-06 : 23:58:53
ok I'll try this out.
thanks for the help.

Expect the UnExpected
Go to Top of Page
    Next Page

- Advertisement -