Thursday, March 29, 2012
Database in 'In recovery' mode
There was the most awful case. During a update of a DB there was a
switching-off of power supplies. After switch on of a server the base has
passed in mode 'Suspect'. To restore base by standard way it was not
possible. Substitution of files and had turned out to open changes of the
status of base data.
Has executed substitution of files of a database. Has successfully opened a
database, structure - all is accessible.
Check of a file of a database on integrity is executed successfully, errors
are not present (DBCC CHECKDB).
I can not create backup, gives out the message that are opened deferred
transactions.
Also, at change of some objects there is a lag of a server that leads to
change of the status of database 'In Recovery'. In 2 and more hours the
status has not changed.
Whether it is necessary to wait for restoration? How to commit deferred tran?
Thank you for any help.
p.s. Backups very old :(Not sure if this is going to work ... a little bit risky but worth a try (I
guess)...
It seemed that some transaction are not clearing so try to rollback the
transaction and then try to backup the database and then try to turn the
database back online, so the command would look like:
USE master
GO
-- First set it to read only and rollback any active transaction
ALTER DATABASE [DatabaseName]
SET READ_ONLY WITH ROLLBACK IMMEDIATE
GO
-- Backup the database, hopefully it should work since there should not be
any active transaction
BACKUP DATABASE [DatabaseName]
TO DISK = '[FilePathAndName]'
WITH INIT
GO
-- Turn the database back online
ALTER DATABASE [DatabaseName]
SET ONLINE WITH ROLLBACK IMMEDIATE
GO
Hopefully that would work (but no guarantee...)
Lucas
"int64" wrote:
> Hi,
> There was the most awful case. During a update of a DB there was a
> switching-off of power supplies. After switch on of a server the base has
> passed in mode 'Suspect'. To restore base by standard way it was not
> possible. Substitution of files and had turned out to open changes of the
> status of base data.
> Has executed substitution of files of a database. Has successfully opened a
> database, structure - all is accessible.
> Check of a file of a database on integrity is executed successfully, errors
> are not present (DBCC CHECKDB).
> I can not create backup, gives out the message that are opened deferred
> transactions.
> Also, at change of some objects there is a lag of a server that leads to
> change of the status of database 'In Recovery'. In 2 and more hours the
> status has not changed.
> Whether it is necessary to wait for restoration? How to commit deferred tran?
> Thank you for any help.
> p.s. Backups very old :(
>
Tuesday, February 14, 2012
Database crashed its very urgent
one of my database is suddenly crashed with power fluctuation and when i
started the server it is showing "not able to connect database". I have take
n
backup and i was trying to attach database in other system. It has given me
the following error.
Microsoft SQL-DMO (ODBC SQLState: HY000)
--
Error 9003: The LSN (375:9588:1) passed to log scan in database
'QVLMSCASPARES' is invalid.
--
OK
--
Please any one can help me out.
With Regards,
AHARIHari
>I have taken
> backup and i was trying to attach database in other system. It has given m
e
> the following error.
You can recover the data wont attach it. You will attach only if you
have.mdf files with you.
When did you take back up.waht kind of back up( full,differential,log) what
is your recovery model.when did you take master back up.
above information is needed to suggest you right one.
Regards
R.D
--
Regards
R.D
--Knowledge gets doubled when shared
"Srihari" wrote:
> Hi All,
> one of my database is suddenly crashed with power fluctuation and when i
> started the server it is showing "not able to connect database". I have ta
ken
> backup and i was trying to attach database in other system. It has given m
e
> the following error.
> --
> Microsoft SQL-DMO (ODBC SQLState: HY000)
> --
> Error 9003: The LSN (375:9588:1) passed to log scan in database
> 'QVLMSCASPARES' is invalid.
> --
> OK
> --
>
> Please any one can help me out.
> With Regards,
> AHARI|||once the database has crashed i have stopped sqlserver and took the copy of
the microsoft sqlserver directory under program files and kept it in other
location.
I think i am having master back up also.
How can i retrieve the data.
With Regards,
AHARI
"R.D" wrote:
> Hari
> You can recover the data wont attach it. You will attach only if you
> have.mdf files with you.
> When did you take back up.waht kind of back up( full,differential,log) wha
t
> is your recovery model.when did you take master back up.
> above information is needed to suggest you right one.
> Regards
> R.D
> --
> Regards
> R.D
> --Knowledge gets doubled when shared
>
> "Srihari" wrote:
>|||Only God should save you . Back up is different from taking copy of file
after crash.
what kind of crash did you observe.
In the folder you wil find .mdf files
go to enterprise manager, and try to attach it, If you are lucky then you
should get your data.
At least hereafter, take back up in appropriate times. do read BOL
--
Regards
R.D
--Knowledge gets doubled when shared
"Srihari" wrote:
> once the database has crashed i have stopped sqlserver and took the copy o
f
> the microsoft sqlserver directory under program files and kept it in other
> location.
> I think i am having master back up also.
> How can i retrieve the data.
> With Regards,
> AHARI
> "R.D" wrote:
>|||Hi R D
God Helped me!... I had backup of one days prior and i have re entered the
data for one day. some how system is up but in these situations is there an
y
other way to resolve instead of re entering.
With Regards,
AHARI
"R.D" wrote:
> Only God should save you . Back up is different from taking copy of file
> after crash.
> what kind of crash did you observe.
> In the folder you wil find .mdf files
> go to enterprise manager, and try to attach it, If you are lucky then you
> should get your data.
> At least hereafter, take back up in appropriate times. do read BOL
> --
> Regards
> R.D
> --Knowledge gets doubled when shared
>
> "Srihari" wrote:
>|||Yes, that's what transaction log backups are for. Do you have log
backups? If not, then consider implementing them for next time. Read
about transaction log backups in Books Online.
Also, invest in a UPS if you haven't already done so. A database server
needs to be protected from power fluctuations.
David Portas
SQL Server MVP
--|||thanks for you suggestion. I am trying to get the procedure to retrieve data
from crashed database. No one is helping me in that way. Actually this
incident had happend at one of our client place.
At least now can any one tell me how to retrieve data from crashed database.
I tried in google i got some article which is not so clear. if i get the
master also along with crashed database that is LDF and MDF how to retrieve
the data tell me the procedure in detail.
Clients are using UPS too. The database is running from past 4 years.
I felt that News group MVPs will respond quickly and take the matter
serious. Hear i am seeing they are taking it lite and making fun of me.
with Regards,
AHARI
"David Portas" wrote:
> Yes, that's what transaction log backups are for. Do you have log
> backups? If not, then consider implementing them for next time. Read
> about transaction log backups in Books Online.
> Also, invest in a UPS if you haven't already done so. A database server
> needs to be protected from power fluctuations.
> --
> David Portas
> SQL Server MVP
> --
>|||I am not making fun of you. You said in a previous post that you had
already recovered the database so I understood that you didn't need
more help on that. I was answering your specific question about how to
recover additional data by asking for more information on whether you
have a log backup. You didn't answer that question unfortunately.
As I understand it you have restored an old database backup to another
server but you still have a copy of the latest MDF and LDF files
available. It isn't possible to apply the transaction log to a database
that is online and in a recovered state. To apply the transaction log
you first have to restore from a full database backup with the
NORECOVERY option. Only then can you start to restore transaction log
backups, assuming you have them.
To restore the master database you have to first put the database into
single user mode. Only attempt to restore master on either the server
that the backup was originally taken from or on a clean install of SQL
Server.
Have you tried re-attaching the MDF and LDF files as suggested by RD?
That should be your first course of action. There is an example of how
to re-attach under the sp_attach_db topic in Books Online. If you can
attach the database successfully then you are in luck. Take a backup
immediately, run DBCC CHECKDB and then you are back in business
hopefully.
If you re-attach your database but it is marked as "suspect" then
things are bit less rosy to say the least. I recommend you contact
Microsoft support directly as there are no documented solutions and the
possible fixes are not without their own risks. I don't want to suggest
anything that may make things worse.
Relevant articles in Books Online:
"sp_attach_db"
"Restoring the master Database"
"How to restore to the point of failure"
Hope this helps.
David Portas
SQL Server MVP
--|||Hello David portas,
Thanks you for your quick response.
If you see my first posting I have clearly mentioned that, i am attaching
database in other system and mentioned the error message too.
Ok. According to your reply if i get this error i cant retrieve data back.
"David Portas" wrote:
> I am not making fun of you. You said in a previous post that you had
> already recovered the database so I understood that you didn't need
> more help on that. I was answering your specific question about how to
> recover additional data by asking for more information on whether you
> have a log backup. You didn't answer that question unfortunately.
> As I understand it you have restored an old database backup to another
> server but you still have a copy of the latest MDF and LDF files
> available. It isn't possible to apply the transaction log to a database
> that is online and in a recovered state. To apply the transaction log
> you first have to restore from a full database backup with the
> NORECOVERY option. Only then can you start to restore transaction log
> backups, assuming you have them.
> To restore the master database you have to first put the database into
> single user mode. Only attempt to restore master on either the server
> that the backup was originally taken from or on a clean install of SQL
> Server.
> Have you tried re-attaching the MDF and LDF files as suggested by RD?
> That should be your first course of action. There is an example of how
> to re-attach under the sp_attach_db topic in Books Online. If you can
> attach the database successfully then you are in luck. Take a backup
> immediately, run DBCC CHECKDB and then you are back in business
> hopefully.
> If you re-attach your database but it is marked as "suspect" then
> things are bit less rosy to say the least. I recommend you contact
> Microsoft support directly as there are no documented solutions and the
> possible fixes are not without their own risks. I don't want to suggest
> anything that may make things worse.
> Relevant articles in Books Online:
> "sp_attach_db"
> "Restoring the master Database"
> "How to restore to the point of failure"
> Hope this helps.
> --
> David Portas
> SQL Server MVP
> --
>
Database crashed its very urgent
one of my database is suddenly crashed with power fluctuation and when i
started the server it is showing "not able to connect database". I have taken
backup and i was trying to attach database in other system. It has given me
the following error.
--
Microsoft SQL-DMO (ODBC SQLState: HY000)
--
Error 9003: The LSN (375:9588:1) passed to log scan in database
'QVLMSCASPARES' is invalid.
--
OK
--
Please any one can help me out.
With Regards,
AHARIWhat does your SQL Server log say? Looks like you have corruption.
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Srihari" <Srihari@.discussions.microsoft.com> wrote in message
news:3479DD26-661B-48DD-BE5C-DFFAA0DB5EE2@.microsoft.com...
> Hi All,
> one of my database is suddenly crashed with power fluctuation and when i
> started the server it is showing "not able to connect database". I have
> taken
> backup and i was trying to attach database in other system. It has given
> me
> the following error.
> --
> Microsoft SQL-DMO (ODBC SQLState: HY000)
> --
> Error 9003: The LSN (375:9588:1) passed to log scan in database
> 'QVLMSCASPARES' is invalid.
> --
> OK
> --
>
> Please any one can help me out.
> With Regards,
> AHARI|||It says
"Error 9003: The LSN (375:9588:1) passed to log scan in database
'QVLMSCASPARES' is invalid."
With Reagards,
AHARI
"Mike Epprecht (SQL MVP)" wrote:
> What does your SQL Server log say? Looks like you have corruption.
> Regards
> --
> Mike Epprecht, Microsoft SQL Server MVP
> Zurich, Switzerland
> IM: mike@.epprecht.net
> MVP Program: http://www.microsoft.com/mvp
> Blog: http://www.msmvps.com/epprecht/
> "Srihari" <Srihari@.discussions.microsoft.com> wrote in message
> news:3479DD26-661B-48DD-BE5C-DFFAA0DB5EE2@.microsoft.com...
> > Hi All,
> >
> > one of my database is suddenly crashed with power fluctuation and when i
> > started the server it is showing "not able to connect database". I have
> > taken
> > backup and i was trying to attach database in other system. It has given
> > me
> > the following error.
> >
> > --
> > Microsoft SQL-DMO (ODBC SQLState: HY000)
> > --
> > Error 9003: The LSN (375:9588:1) passed to log scan in database
> > 'QVLMSCASPARES' is invalid.
> > --
> > OK
> > --
> >
> >
> > Please any one can help me out.
> >
> > With Regards,
> > AHARI
>
>
Database crashed its very urgent
one of my database is suddenly crashed with power fluctuation and when i
started the server it is showing "not able to connect database". I have taken
backup and i was trying to attach database in other system. It has given me
the following error.
--
Microsoft SQL-DMO (ODBC SQLState: HY000)
--
Error 9003: The LSN (375:9588:1) passed to log scan in database
'QVLMSCASPARES' is invalid.
--
OK
--
Please any one can help me out.
With Regards,
AHARISrihari
Sounds like you are trying to reattach the data and log files. AM I correct/
Do you have a backup of the the db if so restore it on another server
--
Paul Zanbaka
DBA, Programmer Analyst
"Srihari" wrote:
> Hi All,
> one of my database is suddenly crashed with power fluctuation and when i
> started the server it is showing "not able to connect database". I have taken
> backup and i was trying to attach database in other system. It has given me
> the following error.
> --
> Microsoft SQL-DMO (ODBC SQLState: HY000)
> --
> Error 9003: The LSN (375:9588:1) passed to log scan in database
> 'QVLMSCASPARES' is invalid.
> --
> OK
> --
>
> Please any one can help me out.
> With Regards,
> AHARI|||I am attaching in other system then only i got this error.
With Regards
AHARI
"Paul Zanbaka" wrote:
> Srihari
> Sounds like you are trying to reattach the data and log files. AM I correct/
> Do you have a backup of the the db if so restore it on another server
> --
> Paul Zanbaka
> DBA, Programmer Analyst
>
> "Srihari" wrote:
> > Hi All,
> >
> > one of my database is suddenly crashed with power fluctuation and when i
> > started the server it is showing "not able to connect database". I have taken
> > backup and i was trying to attach database in other system. It has given me
> > the following error.
> >
> > --
> > Microsoft SQL-DMO (ODBC SQLState: HY000)
> > --
> > Error 9003: The LSN (375:9588:1) passed to log scan in database
> > 'QVLMSCASPARES' is invalid.
> > --
> > OK
> > --
> >
> >
> > Please any one can help me out.
> >
> > With Regards,
> > AHARI|||Srihari
Instead of attaching the db on other system try to restore it
RESTORE DATABASE
--
Paul Zanbaka
DBA, Programmer Analyst
"Srihari" wrote:
> I am attaching in other system then only i got this error.
> With Regards
> AHARI
> "Paul Zanbaka" wrote:
> > Srihari
> > Sounds like you are trying to reattach the data and log files. AM I correct/
> > Do you have a backup of the the db if so restore it on another server
> > --
> > Paul Zanbaka
> > DBA, Programmer Analyst
> >
> >
> > "Srihari" wrote:
> >
> > > Hi All,
> > >
> > > one of my database is suddenly crashed with power fluctuation and when i
> > > started the server it is showing "not able to connect database". I have taken
> > > backup and i was trying to attach database in other system. It has given me
> > > the following error.
> > >
> > > --
> > > Microsoft SQL-DMO (ODBC SQLState: HY000)
> > > --
> > > Error 9003: The LSN (375:9588:1) passed to log scan in database
> > > 'QVLMSCASPARES' is invalid.
> > > --
> > > OK
> > > --
> > >
> > >
> > > Please any one can help me out.
> > >
> > > With Regards,
> > > AHARI
Database crashed its very urgent
one of my database is suddenly crashed with power fluctuation and when i
started the server it is showing "not able to connect database". I have take
n
backup and i was trying to attach database in other system. It has given me
the following error.
Microsoft SQL-DMO (ODBC SQLState: HY000)
--
Error 9003: The LSN (375:9588:1) passed to log scan in database
'QVLMSCASPARES' is invalid.
--
OK
--
Please any one can help me out.
With Regards,
AHARIYou should use sp_detach_db to explicitly detach the files,
copy then and then try attaching on another system. You also
need to make sure you have all files from the original
database.
However, if your original database is corrupted you
shouldn't be using sp_detach/sp_attach. You should check all
logs and determine the cause of the corruption and address
that issue. Often you need to restore from your last known
good backup.
-Sue
On Mon, 3 Oct 2005 03:03:03 -0700, "Srihari"
<Srihari@.discussions.microsoft.com> wrote:
>Hi All,
>one of my database is suddenly crashed with power fluctuation and when i
>started the server it is showing "not able to connect database". I have tak
en
>backup and i was trying to attach database in other system. It has given me
>the following error.
>--
>Microsoft SQL-DMO (ODBC SQLState: HY000)
>--
>Error 9003: The LSN (375:9588:1) passed to log scan in database
>'QVLMSCASPARES' is invalid.
>--
>OK
>--
>
>Please any one can help me out.
>With Regards,
>AHARI
Database crashed its very urgent
one of my database is suddenly crashed with power fluctuation and when i
started the server it is showing "not able to connect database". I have taken
backup and i was trying to attach database in other system. It has given me
the following error.
Microsoft SQL-DMO (ODBC SQLState: HY000)
Error 9003: The LSN (375:9588:1) passed to log scan in database
'QVLMSCASPARES' is invalid.
OK
Please any one can help me out.
With Regards,
AHARI
Srihari wrote:
> Hi All,
> one of my database is suddenly crashed with power fluctuation and
> when i started the server it is showing "not able to connect
> database". I have taken backup and i was trying to attach database in
> other system. It has given me the following error.
> --
> Microsoft SQL-DMO (ODBC SQLState: HY000)
> --
> Error 9003: The LSN (375:9588:1) passed to log scan in database
> 'QVLMSCASPARES' is invalid.
What do you mean by "I have taken backup"? Do you mean you took a copy
of the database file(s) from the original server when SQL Server was
either off-line or the database was detached. Or do you mean you
performed a backup using BACKUP DATABASE? If you are trying to restore a
backup, then use RESTORE DATABASE. If you are using a copy of the
database files and log files, then use sp_attach_db or
sp_attach_single_file_db.
See if this helps.
http://support.microsoft.com/kb/328354
David Gugick
Quest Software
www.imceda.com
www.quest.com
|||I have taken files offline and trying to attach in other system.
With Regards,
AHARI
"David Gugick" wrote:
> Srihari wrote:
>
> What do you mean by "I have taken backup"? Do you mean you took a copy
> of the database file(s) from the original server when SQL Server was
> either off-line or the database was detached. Or do you mean you
> performed a backup using BACKUP DATABASE? If you are trying to restore a
> backup, then use RESTORE DATABASE. If you are using a copy of the
> database files and log files, then use sp_attach_db or
> sp_attach_single_file_db.
> See if this helps.
> http://support.microsoft.com/kb/328354
>
> --
> David Gugick
> Quest Software
> www.imceda.com
> www.quest.com
>
|||Srihari wrote:
> I have taken files offline and trying to attach in other system.
> With Regards,
> AHARI
>
According to BOL:
"sp_attach_db should only be executed on databases that were previously
detached from the database server using an explicit sp_detach_db
operation. If more than 16 files must be specified, use CREATE DATABASE
with the FOR ATTACH clause.
If you attach a database to a server other than the server from which
the database was detached, and the detached database was enabled for
replication, you should run sp_removedbreplication to remove replication
from the database."
I'm not sure what will happen if you try to attach a copy of the
database files without first using the detach function. Are you
attaching the log files as well? If so, have to tried to not attach the
log file.
See if using the CREATE DATABASE with the FOR ATTACH clause works
instead:
http://support.microsoft.com/?kbid=885712
David Gugick
Quest Software
www.imceda.com
www.quest.com
Database crashed its very urgent
one of my database is suddenly crashed with power fluctuation and when i
started the server it is showing "not able to connect database". I have taken
backup and i was trying to attach database in other system. It has given me
the following error.
Microsoft SQL-DMO (ODBC SQLState: HY000)
Error 9003: The LSN (375:9588:1) passed to log scan in database
'QVLMSCASPARES' is invalid.
OK
Please any one can help me out.
With Regards,
AHARI
What does your SQL Server log say? Looks like you have corruption.
Regards
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Srihari" <Srihari@.discussions.microsoft.com> wrote in message
news:3479DD26-661B-48DD-BE5C-DFFAA0DB5EE2@.microsoft.com...
> Hi All,
> one of my database is suddenly crashed with power fluctuation and when i
> started the server it is showing "not able to connect database". I have
> taken
> backup and i was trying to attach database in other system. It has given
> me
> the following error.
> --
> Microsoft SQL-DMO (ODBC SQLState: HY000)
> --
> Error 9003: The LSN (375:9588:1) passed to log scan in database
> 'QVLMSCASPARES' is invalid.
> --
> OK
> --
>
> Please any one can help me out.
> With Regards,
> AHARI
|||It says
"Error 9003: The LSN (375:9588:1) passed to log scan in database
'QVLMSCASPARES' is invalid."
With Reagards,
AHARI
"Mike Epprecht (SQL MVP)" wrote:
> What does your SQL Server log say? Looks like you have corruption.
> Regards
> --
> Mike Epprecht, Microsoft SQL Server MVP
> Zurich, Switzerland
> IM: mike@.epprecht.net
> MVP Program: http://www.microsoft.com/mvp
> Blog: http://www.msmvps.com/epprecht/
> "Srihari" <Srihari@.discussions.microsoft.com> wrote in message
> news:3479DD26-661B-48DD-BE5C-DFFAA0DB5EE2@.microsoft.com...
>
>
Database crashed its very urgent
one of my database is suddenly crashed with power fluctuation and when i
started the server it is showing "not able to connect database". I have taken
backup and i was trying to attach database in other system. It has given me
the following error.
Microsoft SQL-DMO (ODBC SQLState: HY000)
Error 9003: The LSN (375:9588:1) passed to log scan in database
'QVLMSCASPARES' is invalid.
OK
Please any one can help me out.
With Regards,
AHARI
Srihari
Sounds like you are trying to reattach the data and log files. AM I correct/
Do you have a backup of the the db if so restore it on another server
Paul Zanbaka
DBA, Programmer Analyst
"Srihari" wrote:
> Hi All,
> one of my database is suddenly crashed with power fluctuation and when i
> started the server it is showing "not able to connect database". I have taken
> backup and i was trying to attach database in other system. It has given me
> the following error.
> --
> Microsoft SQL-DMO (ODBC SQLState: HY000)
> --
> Error 9003: The LSN (375:9588:1) passed to log scan in database
> 'QVLMSCASPARES' is invalid.
> --
> OK
> --
>
> Please any one can help me out.
> With Regards,
> AHARI
|||I am attaching in other system then only i got this error.
With Regards
AHARI
"Paul Zanbaka" wrote:
[vbcol=seagreen]
> Srihari
> Sounds like you are trying to reattach the data and log files. AM I correct/
> Do you have a backup of the the db if so restore it on another server
> --
> Paul Zanbaka
> DBA, Programmer Analyst
>
> "Srihari" wrote:
|||Srihari
Instead of attaching the db on other system try to restore it
RESTORE DATABASE
Paul Zanbaka
DBA, Programmer Analyst
"Srihari" wrote:
[vbcol=seagreen]
> I am attaching in other system then only i got this error.
> With Regards
> AHARI
> "Paul Zanbaka" wrote:
Database crashed its very urgent
one of my database is suddenly crashed with power fluctuation and when i
started the server it is showing "not able to connect database". I have take
n
backup and i was trying to attach database in other system. It has given me
the following error.
Microsoft SQL-DMO (ODBC SQLState: HY000)
--
Error 9003: The LSN (375:9588:1) passed to log scan in database
'QVLMSCASPARES' is invalid.
--
OK
--
Please any one can help me out.
With Regards,
AHARISrihari
Sounds like you are trying to reattach the data and log files. AM I correct/
Do you have a backup of the the db if so restore it on another server
--
Paul Zanbaka
DBA, Programmer Analyst
"Srihari" wrote:
> Hi All,
> one of my database is suddenly crashed with power fluctuation and when i
> started the server it is showing "not able to connect database". I have ta
ken
> backup and i was trying to attach database in other system. It has given m
e
> the following error.
> --
> Microsoft SQL-DMO (ODBC SQLState: HY000)
> --
> Error 9003: The LSN (375:9588:1) passed to log scan in database
> 'QVLMSCASPARES' is invalid.
> --
> OK
> --
>
> Please any one can help me out.
> With Regards,
> AHARI|||I am attaching in other system then only i got this error.
With Regards
AHARI
"Paul Zanbaka" wrote:
[vbcol=seagreen]
> Srihari
> Sounds like you are trying to reattach the data and log files. AM I correc
t/
> Do you have a backup of the the db if so restore it on another server
> --
> Paul Zanbaka
> DBA, Programmer Analyst
>
> "Srihari" wrote:
>|||Srihari
Instead of attaching the db on other system try to restore it
RESTORE DATABASE
Paul Zanbaka
DBA, Programmer Analyst
"Srihari" wrote:
[vbcol=seagreen]
> I am attaching in other system then only i got this error.
> With Regards
> AHARI
> "Paul Zanbaka" wrote:
>
Database crashed its very urgent
one of my database is suddenly crashed with power fluctuation and when i
started the server it is showing "not able to connect database". I have take
n
backup and i was trying to attach database in other system. It has given me
the following error.
Microsoft SQL-DMO (ODBC SQLState: HY000)
--
Error 9003: The LSN (375:9588:1) passed to log scan in database
'QVLMSCASPARES' is invalid.
--
OK
--
Please any one can help me out.
With Regards,
AHARIWhat does your SQL Server log say? Looks like you have corruption.
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Srihari" <Srihari@.discussions.microsoft.com> wrote in message
news:3479DD26-661B-48DD-BE5C-DFFAA0DB5EE2@.microsoft.com...
> Hi All,
> one of my database is suddenly crashed with power fluctuation and when i
> started the server it is showing "not able to connect database". I have
> taken
> backup and i was trying to attach database in other system. It has given
> me
> the following error.
> --
> Microsoft SQL-DMO (ODBC SQLState: HY000)
> --
> Error 9003: The LSN (375:9588:1) passed to log scan in database
> 'QVLMSCASPARES' is invalid.
> --
> OK
> --
>
> Please any one can help me out.
> With Regards,
> AHARI|||It says
"Error 9003: The LSN (375:9588:1) passed to log scan in database
'QVLMSCASPARES' is invalid."
With Reagards,
AHARI
"Mike Epprecht (SQL MVP)" wrote:
> What does your SQL Server log say? Looks like you have corruption.
> Regards
> --
> Mike Epprecht, Microsoft SQL Server MVP
> Zurich, Switzerland
> IM: mike@.epprecht.net
> MVP Program: http://www.microsoft.com/mvp
> Blog: http://www.msmvps.com/epprecht/
> "Srihari" <Srihari@.discussions.microsoft.com> wrote in message
> news:3479DD26-661B-48DD-BE5C-DFFAA0DB5EE2@.microsoft.com...
>
>
Database corrupt on power loss
We are planning to use SQL Compact for an industrial control application.
We selected this database based on the assuption that it will survive when power is lost in the middle of a transaction.
We setup a test where we open a connection, write to database and randomly shut of the power while writing to database.
We are running on XPE with EWF enabled for C drive. Database is on D drive.
We cycle the power every ~ 20 seconds.
When the power comes back on, we Verify the database and if return is FALSE we Repair.
The database gets corrupted after 15 to 24 hours.
Looking at the log, for the first 12 hours there is no Repair going on. Every time the Verify returns True. After that, we start seeing Repair going on. The messages in the log are one or more of the following:
"Page with valid ordinal not found - idPage: 1, iPage: 3151"
"Block page not found - pwszTable: EventLogTable, idPage: 4678"
"Selected page not found - idPage: 4951, iPage: 3935"
After a couple more hours of repairing , the database corrupts completely and our application does not start anymore. The database file is always 20K when it gets corrupted.
Is there any setup to be done for the OS or the SQL to be able to survive this kind of test?
Is there anything to do to the database to prevent the corruption?
First of all, are you using transactions to submit your changes?
If yes, did you check file system to see if it got corrupted? Which file system is that? Do you have write cache disabled on HDD?
|||Ilya,
Thanks for the reply!
We use the database as follows:
We open a connection using SqlCeConnection.Open()
We prepare a command using SqlCeCommand.Prepare()
We write to database using SqlCeCommand.ExecuteNonQuery()
We keep same connection open all the time while we are writing.
At this time we don't read from database, we just write.
The operating system is XP Embedded. The file system is NTFS.
I am not sure if there is any corruption in the file system but I assume it is not since I just delete the bad database and restart the test and everything goes back to normal. How would I check to see if there is any file system corruption?
I will check your suggestion about disabling HDD write cache. I doubt that it is disabled.
|||Ilya,
I disabled the cache write for the drive.
I will restart test and hopefuly this is the solution.
Thanks again!
|||Hold on, not just yet… You have to use transactions for all changes to the database to engage ACID and it looks like you’re not using them. Please see this on how to use transactions.
|||
Thanks.
We will change the code to use transactions.
|||Ilya,
We changed the code to use transaction and the database still fails.
Also, the write cache for the hdd is disabled.
This time it failed after 10 hours.
The behaviour is the same as before, the only difference is that now I did not get a lot of pages not found before the program stopped working.
This is the last entry in the database log before it crashed:
Source : D:\MC\7654321\DomainModel\EventLog.sdf
Destination : n/a
Verifying - verMajor: 3, verMinor: 0, verBuild: 5300, verPoint: 0
Time - 2007-22-03 22:38:19.821
Selected page not found - idPage: 1, iPage: 3007
Source : D:\MC\7654321\DomainModel\EventLog.sdf
Destination : C:\DOCUME~1\husky\LOCALS~1\Temp\sql1.tmp
Repairing - verMajor: 3, verMinor: 0, verBuild: 5300, verPoint: 0
Time - 2007-22-03 22:38:20.190
Selected page not found - idPage: 1, iPage: 3007
Here is the code where we are accessing the database:
#region Database Access
private void InitializeDatabase()
{
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " EventManager.Constructor Started");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
// Determine if database file exists
bool databaseExists = File.Exists(_DatabaseFilePath);
if (_CreateEmptyDatabase || !databaseExists)
{
// Remove old database file if we are forcing creating of an empty database
if (databaseExists)
{
File.Delete(_DatabaseFilePath);
}
// Create an empty database if it does not exist yet
CreateEmptyDatabase();
OpenConnection();
CreateTables();
}
else
{
VerifyAndRepairDatabase();
OpenConnection();
}
PrepareInsertEventCommand();
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " EventManager.Constructor Completed in " + stopwatch.ElapsedMilliseconds + " msec");
}
private void VerifyAndRepairDatabase()
{
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " VerifyAndRepairDatabase Started");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (SqlCeEngine sqlCeEngine = new SqlCeEngine(_ConnectionString))
{
LogFile.Log("Event Log Database", "Verified Started");
if (sqlCeEngine.Verify())
{
stopwatch.Stop();
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " Database Verify Completed in " + stopwatch.ElapsedMilliseconds + " msec");
LogFile.Log("Event Log Database", "Verified OK");
}
else
{
LogFile.Log("Event Log Database", "Verified Failed");
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " Database Corrupted --> Repair in Progress");
sqlCeEngine.Repair(null, RepairOption.DeleteCorruptedRows);
stopwatch.Stop();
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " Database Verify and Repair Completed in " + stopwatch.ElapsedMilliseconds + " msec");
LogFile.Log("Event Log Database", "Repair Complete");
}
}
}
private void CreateEmptyDatabase()
{
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " CreateEmptyDatabase Started");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (SqlCeEngine sqlCeEngine = new SqlCeEngine(_ConnectionString))
{
sqlCeEngine.CreateDatabase();
}
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " CreateEmptyDatabase Completed in " + stopwatch.ElapsedMilliseconds + " msec");
}
private void OpenConnection()
{
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " OpenConnection Started");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
_Connection = new SqlCeConnection(_ConnectionString);
_Connection.Open();
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " OpenConnection Completed in " + stopwatch.ElapsedMilliseconds + " msec");
}
private void CreateTables()
{
const string sqlCreateTableCommand =
@."CREATE TABLE " + TableName + " " +
@."(" +
@."[TimeStamp] bigint IDENTITY(1,1) PRIMARY KEY," +
@."[Name] nvarchar(255)," +
@."[DateTime] datetime," +
@."[EventType] integer," +
@."[SourceText] nvarchar(255)," +
@."[MessageText] nvarchar(255)" +
@.");";
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " CreateTables Started");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (SqlCeCommand sqlCommand = new SqlCeCommand(sqlCreateTableCommand, _Connection))
{
sqlCommand.ExecuteNonQuery();
}
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " CreateTables Completed in " + stopwatch.ElapsedMilliseconds + " msec");
}
private void PrepareInsertEventCommand()
{
const string sqlInsertCommand =
@."INSERT INTO " + TableName + @." " +
@."([Name], [DateTime], [EventType], [SourceText], [MessageText]) " +
@."VALUES (@.Name, @.DateTime, @.EventType, @.SourceText, @.MessageText)";
_InsertEventCommand = _Connection.CreateCommand();
_InsertEventCommand.CommandText = sqlInsertCommand;
_InsertEventCommand.Parameters.Add("@.Name", SqlDbType.NVarChar, 255);
_InsertEventCommand.Parameters.Add("@.DateTime", SqlDbType.DateTime, 8);
_InsertEventCommand.Parameters.Add("@.EventType", SqlDbType.Int);
_InsertEventCommand.Parameters.Add("@.SourceText", SqlDbType.NVarChar, 255);
_InsertEventCommand.Parameters.Add("@.MessageText", SqlDbType.NVarChar, 255);
_InsertEventCommand.Prepare();
}
public void UpdateEventHistory(Event machineEvent)
{
// Start transaction
SqlCeTransaction transaction = _Connection.BeginTransaction();
_InsertEventCommand.Transaction = transaction;
try
{
// Update command parameters and write values to database
_InsertEventCommand.Parameters[0].Value = machineEvent.Name;
_InsertEventCommand.Parameters[1].Value = machineEvent.TimeStamp;
_InsertEventCommand.Parameters[2].Value = machineEvent.EventType;
_InsertEventCommand.Parameters[3].Value = machineEvent.SourceText;
_InsertEventCommand.Parameters[4].Value = machineEvent.MessageText;
_InsertEventCommand.ExecuteNonQuery();
transaction.Commit();
}
catch (Exception exception)
{
transaction.Rollback();
_Connection.Close();
throw exception;
}
}
#endregion
Thanks.
|||Maybe you should try changing the CommitMode as per http://msdn2.microsoft.com/en-us/library/esdw1h9d.aspx
(default CommitMode is deferred)
// Commit the changes to disk if everything above succeeded;
// Use Deferred mode for optimal performance; the changes will
// be flashed (sic!) to disk within the timespan specified in the
// ConnectionString 'FLUSH INTERVAL' property; ( = 10 seconds)
//
tx.Commit(CommitMode.Deferred);
// Alternatively, you could use:
// tx.Commit(CommitMode.Immediate);
|||
Have you looked at this: http://support.microsoft.com/kb/296076/en-us ?
|||
Erik,
I changed the code to use commit immediate and the test still fails after about 12 hours.
In my case the database is completely corrupt, since it has only 20k. I think trying to compact will do nothing.
After reading the article you pointed to, looks like I cannot use this database for this kind of application.
I might try just another test by limiting the size. Right now I keep writing to the database at a rate of about 2Mb per hour.
This means my database is about 24Mb when it becomes corrupted. I will try to copy the file and start over when I reach a certain size.
Any other suggestion other than 'don't reset during a transaction'?
Thanks.
|||What is the behavior of the SQL Express database when you power down during a transaction commit? Does SQL Express have the same possible issue of getting the database corrupt as the Compact does?
|||That likely indicates file system corruption- your file is just plain gone. Consider running chkdsk.exe before running database fix. That might restore the file to pre commit state.
|||Hi, Ilya;
I have database corruption problem as well.
I found a very strange issue: my application will write some log to a log file "log.txt", but I found a corrupted .sdf database file has my log information with plain text !!!
How can I tell there is file system corruption? How can this happen? How can I find chkdsk.exe?
Cheers.
|||Is this corruption problem still valid with 3.5 version ?Arnaud.
Database corrupt on power loss
We are planning to use SQL Compact for an industrial control application.
We selected this database based on the assuption that it will survive when power is lost in the middle of a transaction.
We setup a test where we open a connection, write to database and randomly shut of the power while writing to database.
We are running on XPE with EWF enabled for C drive. Database is on D drive.
We cycle the power every ~ 20 seconds.
When the power comes back on, we Verify the database and if return is FALSE we Repair.
The database gets corrupted after 15 to 24 hours.
Looking at the log, for the first 12 hours there is no Repair going on. Every time the Verify returns True. After that, we start seeing Repair going on. The messages in the log are one or more of the following:
"Page with valid ordinal not found - idPage: 1, iPage: 3151"
"Block page not found - pwszTable: EventLogTable, idPage: 4678"
"Selected page not found - idPage: 4951, iPage: 3935"
After a couple more hours of repairing , the database corrupts completely and our application does not start anymore. The database file is always 20K when it gets corrupted.
Is there any setup to be done for the OS or the SQL to be able to survive this kind of test?
Is there anything to do to the database to prevent the corruption?
First of all, are you using transactions to submit your changes?
If yes, did you check file system to see if it got corrupted? Which file system is that? Do you have write cache disabled on HDD?
|||Ilya,
Thanks for the reply!
We use the database as follows:
We open a connection using SqlCeConnection.Open()
We prepare a command using SqlCeCommand.Prepare()
We write to database using SqlCeCommand.ExecuteNonQuery()
We keep same connection open all the time while we are writing.
At this time we don't read from database, we just write.
The operating system is XP Embedded. The file system is NTFS.
I am not sure if there is any corruption in the file system but I assume it is not since I just delete the bad database and restart the test and everything goes back to normal. How would I check to see if there is any file system corruption?
I will check your suggestion about disabling HDD write cache. I doubt that it is disabled.
|||Ilya,
I disabled the cache write for the drive.
I will restart test and hopefuly this is the solution.
Thanks again!
|||Hold on, not just yet… You have to use transactions for all changes to the database to engage ACID and it looks like you’re not using them. Please see this on how to use transactions.
|||
Thanks.
We will change the code to use transactions.
|||Ilya,
We changed the code to use transaction and the database still fails.
Also, the write cache for the hdd is disabled.
This time it failed after 10 hours.
The behaviour is the same as before, the only difference is that now I did not get a lot of pages not found before the program stopped working.
This is the last entry in the database log before it crashed:
Source : D:\MC\7654321\DomainModel\EventLog.sdf
Destination : n/a
Verifying - verMajor: 3, verMinor: 0, verBuild: 5300, verPoint: 0
Time - 2007-22-03 22:38:19.821
Selected page not found - idPage: 1, iPage: 3007
Source : D:\MC\7654321\DomainModel\EventLog.sdf
Destination : C:\DOCUME~1\husky\LOCALS~1\Temp\sql1.tmp
Repairing - verMajor: 3, verMinor: 0, verBuild: 5300, verPoint: 0
Time - 2007-22-03 22:38:20.190
Selected page not found - idPage: 1, iPage: 3007
Here is the code where we are accessing the database:
#region Database Access
private void InitializeDatabase()
{
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " EventManager.Constructor Started");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
// Determine if database file exists
bool databaseExists = File.Exists(_DatabaseFilePath);
if (_CreateEmptyDatabase || !databaseExists)
{
// Remove old database file if we are forcing creating of an empty database
if (databaseExists)
{
File.Delete(_DatabaseFilePath);
}
// Create an empty database if it does not exist yet
CreateEmptyDatabase();
OpenConnection();
CreateTables();
}
else
{
VerifyAndRepairDatabase();
OpenConnection();
}
PrepareInsertEventCommand();
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " EventManager.Constructor Completed in " + stopwatch.ElapsedMilliseconds + " msec");
}
private void VerifyAndRepairDatabase()
{
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " VerifyAndRepairDatabase Started");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (SqlCeEngine sqlCeEngine = new SqlCeEngine(_ConnectionString))
{
LogFile.Log("Event Log Database", "Verified Started");
if (sqlCeEngine.Verify())
{
stopwatch.Stop();
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " Database Verify Completed in " + stopwatch.ElapsedMilliseconds + " msec");
LogFile.Log("Event Log Database", "Verified OK");
}
else
{
LogFile.Log("Event Log Database", "Verified Failed");
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " Database Corrupted --> Repair in Progress");
sqlCeEngine.Repair(null, RepairOption.DeleteCorruptedRows);
stopwatch.Stop();
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " Database Verify and Repair Completed in " + stopwatch.ElapsedMilliseconds + " msec");
LogFile.Log("Event Log Database", "Repair Complete");
}
}
}
private void CreateEmptyDatabase()
{
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " CreateEmptyDatabase Started");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (SqlCeEngine sqlCeEngine = new SqlCeEngine(_ConnectionString))
{
sqlCeEngine.CreateDatabase();
}
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " CreateEmptyDatabase Completed in " + stopwatch.ElapsedMilliseconds + " msec");
}
private void OpenConnection()
{
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " OpenConnection Started");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
_Connection = new SqlCeConnection(_ConnectionString);
_Connection.Open();
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " OpenConnection Completed in " + stopwatch.ElapsedMilliseconds + " msec");
}
private void CreateTables()
{
const string sqlCreateTableCommand =
@."CREATE TABLE " + TableName + " " +
@."(" +
@."[TimeStamp] bigint IDENTITY(1,1) PRIMARY KEY," +
@."[Name] nvarchar(255)," +
@."[DateTime] datetime," +
@."[EventType] integer," +
@."[SourceText] nvarchar(255)," +
@."[MessageText] nvarchar(255)" +
@.");";
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " CreateTables Started");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (SqlCeCommand sqlCommand = new SqlCeCommand(sqlCreateTableCommand, _Connection))
{
sqlCommand.ExecuteNonQuery();
}
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " CreateTables Completed in " + stopwatch.ElapsedMilliseconds + " msec");
}
private void PrepareInsertEventCommand()
{
const string sqlInsertCommand =
@."INSERT INTO " + TableName + @." " +
@."([Name], [DateTime], [EventType], [SourceText], [MessageText]) " +
@."VALUES (@.Name, @.DateTime, @.EventType, @.SourceText, @.MessageText)";
_InsertEventCommand = _Connection.CreateCommand();
_InsertEventCommand.CommandText = sqlInsertCommand;
_InsertEventCommand.Parameters.Add("@.Name", SqlDbType.NVarChar, 255);
_InsertEventCommand.Parameters.Add("@.DateTime", SqlDbType.DateTime, 8);
_InsertEventCommand.Parameters.Add("@.EventType", SqlDbType.Int);
_InsertEventCommand.Parameters.Add("@.SourceText", SqlDbType.NVarChar, 255);
_InsertEventCommand.Parameters.Add("@.MessageText", SqlDbType.NVarChar, 255);
_InsertEventCommand.Prepare();
}
public void UpdateEventHistory(Event machineEvent)
{
// Start transaction
SqlCeTransaction transaction = _Connection.BeginTransaction();
_InsertEventCommand.Transaction = transaction;
try
{
// Update command parameters and write values to database
_InsertEventCommand.Parameters[0].Value = machineEvent.Name;
_InsertEventCommand.Parameters[1].Value = machineEvent.TimeStamp;
_InsertEventCommand.Parameters[2].Value = machineEvent.EventType;
_InsertEventCommand.Parameters[3].Value = machineEvent.SourceText;
_InsertEventCommand.Parameters[4].Value = machineEvent.MessageText;
_InsertEventCommand.ExecuteNonQuery();
transaction.Commit();
}
catch (Exception exception)
{
transaction.Rollback();
_Connection.Close();
throw exception;
}
}
#endregion
Thanks.
|||Maybe you should try changing the CommitMode as per http://msdn2.microsoft.com/en-us/library/esdw1h9d.aspx
(default CommitMode is deferred)
// Commit the changes to disk if everything above succeeded;
// Use Deferred mode for optimal performance; the changes will
// be flashed (sic!) to disk within the timespan specified in the
// ConnectionString 'FLUSH INTERVAL' property; ( = 10 seconds)
//
tx.Commit(CommitMode.Deferred);
// Alternatively, you could use:
// tx.Commit(CommitMode.Immediate);
Have you looked at this: http://support.microsoft.com/kb/296076/en-us ?
|||Erik,
I changed the code to use commit immediate and the test still fails after about 12 hours.
In my case the database is completely corrupt, since it has only 20k. I think trying to compact will do nothing.
After reading the article you pointed to, looks like I cannot use this database for this kind of application.
I might try just another test by limiting the size. Right now I keep writing to the database at a rate of about 2Mb per hour.
This means my database is about 24Mb when it becomes corrupted. I will try to copy the file and start over when I reach a certain size.
Any other suggestion other than 'don't reset during a transaction'?
Thanks.
|||What is the behavior of the SQL Express database when you power down during a transaction commit? Does SQL Express have the same possible issue of getting the database corrupt as the Compact does?
|||That likely indicates file system corruption- your file is just plain gone. Consider running chkdsk.exe before running database fix. That might restore the file to pre commit state.
|||Hi, Ilya;
I have database corruption problem as well.
I found a very strange issue: my application will write some log to a log file "log.txt", but I found a corrupted .sdf database file has my log information with plain text !!!
How can I tell there is file system corruption? How can this happen? How can I find chkdsk.exe?
Cheers.
|||Is this corruption problem still valid with 3.5 version ?Arnaud.
Database corrupt on power loss
We are planning to use SQL Compact for an industrial control application.
We selected this database based on the assuption that it will survive when power is lost in the middle of a transaction.
We setup a test where we open a connection, write to database and randomly shut of the power while writing to database.
We are running on XPE with EWF enabled for C drive. Database is on D drive.
We cycle the power every ~ 20 seconds.
When the power comes back on, we Verify the database and if return is FALSE we Repair.
The database gets corrupted after 15 to 24 hours.
Looking at the log, for the first 12 hours there is no Repair going on. Every time the Verify returns True. After that, we start seeing Repair going on. The messages in the log are one or more of the following:
"Page with valid ordinal not found - idPage: 1, iPage: 3151"
"Block page not found - pwszTable: EventLogTable, idPage: 4678"
"Selected page not found - idPage: 4951, iPage: 3935"
After a couple more hours of repairing , the database corrupts completely and our application does not start anymore. The database file is always 20K when it gets corrupted.
Is there any setup to be done for the OS or the SQL to be able to survive this kind of test?
Is there anything to do to the database to prevent the corruption?
First of all, are you using transactions to submit your changes?
If yes, did you check file system to see if it got corrupted? Which file system is that? Do you have write cache disabled on HDD?
|||Ilya,
Thanks for the reply!
We use the database as follows:
We open a connection using SqlCeConnection.Open()
We prepare a command using SqlCeCommand.Prepare()
We write to database using SqlCeCommand.ExecuteNonQuery()
We keep same connection open all the time while we are writing.
At this time we don't read from database, we just write.
The operating system is XP Embedded. The file system is NTFS.
I am not sure if there is any corruption in the file system but I assume it is not since I just delete the bad database and restart the test and everything goes back to normal. How would I check to see if there is any file system corruption?
I will check your suggestion about disabling HDD write cache. I doubt that it is disabled.
|||Ilya,
I disabled the cache write for the drive.
I will restart test and hopefuly this is the solution.
Thanks again!
|||Hold on, not just yet… You have to use transactions for all changes to the database to engage ACID and it looks like you’re not using them. Please see this on how to use transactions.
|||
Thanks.
We will change the code to use transactions.
|||Ilya,
We changed the code to use transaction and the database still fails.
Also, the write cache for the hdd is disabled.
This time it failed after 10 hours.
The behaviour is the same as before, the only difference is that now I did not get a lot of pages not found before the program stopped working.
This is the last entry in the database log before it crashed:
Source : D:\MC\7654321\DomainModel\EventLog.sdf
Destination : n/a
Verifying - verMajor: 3, verMinor: 0, verBuild: 5300, verPoint: 0
Time - 2007-22-03 22:38:19.821
Selected page not found - idPage: 1, iPage: 3007
Source : D:\MC\7654321\DomainModel\EventLog.sdf
Destination : C:\DOCUME~1\husky\LOCALS~1\Temp\sql1.tmp
Repairing - verMajor: 3, verMinor: 0, verBuild: 5300, verPoint: 0
Time - 2007-22-03 22:38:20.190
Selected page not found - idPage: 1, iPage: 3007
Here is the code where we are accessing the database:
#region Database Access
private void InitializeDatabase()
{
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " EventManager.Constructor Started");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
// Determine if database file exists
bool databaseExists = File.Exists(_DatabaseFilePath);
if (_CreateEmptyDatabase || !databaseExists)
{
// Remove old database file if we are forcing creating of an empty database
if (databaseExists)
{
File.Delete(_DatabaseFilePath);
}
// Create an empty database if it does not exist yet
CreateEmptyDatabase();
OpenConnection();
CreateTables();
}
else
{
VerifyAndRepairDatabase();
OpenConnection();
}
PrepareInsertEventCommand();
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " EventManager.Constructor Completed in " + stopwatch.ElapsedMilliseconds + " msec");
}
private void VerifyAndRepairDatabase()
{
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " VerifyAndRepairDatabase Started");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (SqlCeEngine sqlCeEngine = new SqlCeEngine(_ConnectionString))
{
LogFile.Log("Event Log Database", "Verified Started");
if (sqlCeEngine.Verify())
{
stopwatch.Stop();
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " Database Verify Completed in " + stopwatch.ElapsedMilliseconds + " msec");
LogFile.Log("Event Log Database", "Verified OK");
}
else
{
LogFile.Log("Event Log Database", "Verified Failed");
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " Database Corrupted --> Repair in Progress");
sqlCeEngine.Repair(null, RepairOption.DeleteCorruptedRows);
stopwatch.Stop();
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " Database Verify and Repair Completed in " + stopwatch.ElapsedMilliseconds + " msec");
LogFile.Log("Event Log Database", "Repair Complete");
}
}
}
private void CreateEmptyDatabase()
{
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " CreateEmptyDatabase Started");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (SqlCeEngine sqlCeEngine = new SqlCeEngine(_ConnectionString))
{
sqlCeEngine.CreateDatabase();
}
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " CreateEmptyDatabase Completed in " + stopwatch.ElapsedMilliseconds + " msec");
}
private void OpenConnection()
{
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " OpenConnection Started");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
_Connection = new SqlCeConnection(_ConnectionString);
_Connection.Open();
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " OpenConnection Completed in " + stopwatch.ElapsedMilliseconds + " msec");
}
private void CreateTables()
{
const string sqlCreateTableCommand =
@."CREATE TABLE " + TableName + " " +
@."(" +
@."[TimeStamp] bigint IDENTITY(1,1) PRIMARY KEY," +
@."[Name] nvarchar(255)," +
@."[DateTime] datetime," +
@."[EventType] integer," +
@."[SourceText] nvarchar(255)," +
@."[MessageText] nvarchar(255)" +
@.");";
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " CreateTables Started");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (SqlCeCommand sqlCommand = new SqlCeCommand(sqlCreateTableCommand, _Connection))
{
sqlCommand.ExecuteNonQuery();
}
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " CreateTables Completed in " + stopwatch.ElapsedMilliseconds + " msec");
}
private void PrepareInsertEventCommand()
{
const string sqlInsertCommand =
@."INSERT INTO " + TableName + @." " +
@."([Name], [DateTime], [EventType], [SourceText], [MessageText]) " +
@."VALUES (@.Name, @.DateTime, @.EventType, @.SourceText, @.MessageText)";
_InsertEventCommand = _Connection.CreateCommand();
_InsertEventCommand.CommandText = sqlInsertCommand;
_InsertEventCommand.Parameters.Add("@.Name", SqlDbType.NVarChar, 255);
_InsertEventCommand.Parameters.Add("@.DateTime", SqlDbType.DateTime, 8);
_InsertEventCommand.Parameters.Add("@.EventType", SqlDbType.Int);
_InsertEventCommand.Parameters.Add("@.SourceText", SqlDbType.NVarChar, 255);
_InsertEventCommand.Parameters.Add("@.MessageText", SqlDbType.NVarChar, 255);
_InsertEventCommand.Prepare();
}
public void UpdateEventHistory(Event machineEvent)
{
// Start transaction
SqlCeTransaction transaction = _Connection.BeginTransaction();
_InsertEventCommand.Transaction = transaction;
try
{
// Update command parameters and write values to database
_InsertEventCommand.Parameters[0].Value = machineEvent.Name;
_InsertEventCommand.Parameters[1].Value = machineEvent.TimeStamp;
_InsertEventCommand.Parameters[2].Value = machineEvent.EventType;
_InsertEventCommand.Parameters[3].Value = machineEvent.SourceText;
_InsertEventCommand.Parameters[4].Value = machineEvent.MessageText;
_InsertEventCommand.ExecuteNonQuery();
transaction.Commit();
}
catch (Exception exception)
{
transaction.Rollback();
_Connection.Close();
throw exception;
}
}
#endregion
Thanks.
|||Maybe you should try changing the CommitMode as per http://msdn2.microsoft.com/en-us/library/esdw1h9d.aspx
(default CommitMode is deferred)
// Commit the changes to disk if everything above succeeded;
// Use Deferred mode for optimal performance; the changes will
// be flashed (sic!) to disk within the timespan specified in the
// ConnectionString 'FLUSH INTERVAL' property; ( = 10 seconds)
//
tx.Commit(CommitMode.Deferred);
// Alternatively, you could use:
// tx.Commit(CommitMode.Immediate);
Have you looked at this: http://support.microsoft.com/kb/296076/en-us ?
|||Erik,
I changed the code to use commit immediate and the test still fails after about 12 hours.
In my case the database is completely corrupt, since it has only 20k. I think trying to compact will do nothing.
After reading the article you pointed to, looks like I cannot use this database for this kind of application.
I might try just another test by limiting the size. Right now I keep writing to the database at a rate of about 2Mb per hour.
This means my database is about 24Mb when it becomes corrupted. I will try to copy the file and start over when I reach a certain size.
Any other suggestion other than 'don't reset during a transaction'?
Thanks.
|||What is the behavior of the SQL Express database when you power down during a transaction commit? Does SQL Express have the same possible issue of getting the database corrupt as the Compact does?
|||That likely indicates file system corruption- your file is just plain gone. Consider running chkdsk.exe before running database fix. That might restore the file to pre commit state.
|||Hi, Ilya;
I have database corruption problem as well.
I found a very strange issue: my application will write some log to a log file "log.txt", but I found a corrupted .sdf database file has my log information with plain text !!!
How can I tell there is file system corruption? How can this happen? How can I find chkdsk.exe?
Cheers.
|||Is this corruption problem still valid with 3.5 version ?Arnaud.
|||Sqlce is a standalone file . so if the file was corrupt.
It looks like no good way to repaire it .
Database corrupt on power loss
We are planning to use SQL Compact for an industrial control application.
We selected this database based on the assuption that it will survive when power is lost in the middle of a transaction.
We setup a test where we open a connection, write to database and randomly shut of the power while writing to database.
We are running on XPE with EWF enabled for C drive. Database is on D drive.
We cycle the power every ~ 20 seconds.
When the power comes back on, we Verify the database and if return is FALSE we Repair.
The database gets corrupted after 15 to 24 hours.
Looking at the log, for the first 12 hours there is no Repair going on. Every time the Verify returns True. After that, we start seeing Repair going on. The messages in the log are one or more of the following:
"Page with valid ordinal not found - idPage: 1, iPage: 3151"
"Block page not found - pwszTable: EventLogTable, idPage: 4678"
"Selected page not found - idPage: 4951, iPage: 3935"
After a couple more hours of repairing , the database corrupts completely and our application does not start anymore. The database file is always 20K when it gets corrupted.
Is there any setup to be done for the OS or the SQL to be able to survive this kind of test?
Is there anything to do to the database to prevent the corruption?
First of all, are you using transactions to submit your changes?
If yes, did you check file system to see if it got corrupted? Which file system is that? Do you have write cache disabled on HDD?
|||Ilya,
Thanks for the reply!
We use the database as follows:
We open a connection using SqlCeConnection.Open()
We prepare a command using SqlCeCommand.Prepare()
We write to database using SqlCeCommand.ExecuteNonQuery()
We keep same connection open all the time while we are writing.
At this time we don't read from database, we just write.
The operating system is XP Embedded. The file system is NTFS.
I am not sure if there is any corruption in the file system but I assume it is not since I just delete the bad database and restart the test and everything goes back to normal. How would I check to see if there is any file system corruption?
I will check your suggestion about disabling HDD write cache. I doubt that it is disabled.
|||Ilya,
I disabled the cache write for the drive.
I will restart test and hopefuly this is the solution.
Thanks again!
|||Hold on, not just yet… You have to use transactions for all changes to the database to engage ACID and it looks like you’re not using them. Please see this on how to use transactions.
|||
Thanks.
We will change the code to use transactions.
|||Ilya,
We changed the code to use transaction and the database still fails.
Also, the write cache for the hdd is disabled.
This time it failed after 10 hours.
The behaviour is the same as before, the only difference is that now I did not get a lot of pages not found before the program stopped working.
This is the last entry in the database log before it crashed:
Source : D:\MC\7654321\DomainModel\EventLog.sdf
Destination : n/a
Verifying - verMajor: 3, verMinor: 0, verBuild: 5300, verPoint: 0
Time - 2007-22-03 22:38:19.821
Selected page not found - idPage: 1, iPage: 3007
Source : D:\MC\7654321\DomainModel\EventLog.sdf
Destination : C:\DOCUME~1\husky\LOCALS~1\Temp\sql1.tmp
Repairing - verMajor: 3, verMinor: 0, verBuild: 5300, verPoint: 0
Time - 2007-22-03 22:38:20.190
Selected page not found - idPage: 1, iPage: 3007
Here is the code where we are accessing the database:
#region Database Access
private void InitializeDatabase()
{
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " EventManager.Constructor Started");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
// Determine if database file exists
bool databaseExists = File.Exists(_DatabaseFilePath);
if (_CreateEmptyDatabase || !databaseExists)
{
// Remove old database file if we are forcing creating of an empty database
if (databaseExists)
{
File.Delete(_DatabaseFilePath);
}
// Create an empty database if it does not exist yet
CreateEmptyDatabase();
OpenConnection();
CreateTables();
}
else
{
VerifyAndRepairDatabase();
OpenConnection();
}
PrepareInsertEventCommand();
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " EventManager.Constructor Completed in " + stopwatch.ElapsedMilliseconds + " msec");
}
private void VerifyAndRepairDatabase()
{
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " VerifyAndRepairDatabase Started");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (SqlCeEngine sqlCeEngine = new SqlCeEngine(_ConnectionString))
{
LogFile.Log("Event Log Database", "Verified Started");
if (sqlCeEngine.Verify())
{
stopwatch.Stop();
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " Database Verify Completed in " + stopwatch.ElapsedMilliseconds + " msec");
LogFile.Log("Event Log Database", "Verified OK");
}
else
{
LogFile.Log("Event Log Database", "Verified Failed");
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " Database Corrupted --> Repair in Progress");
sqlCeEngine.Repair(null, RepairOption.DeleteCorruptedRows);
stopwatch.Stop();
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " Database Verify and Repair Completed in " + stopwatch.ElapsedMilliseconds + " msec");
LogFile.Log("Event Log Database", "Repair Complete");
}
}
}
private void CreateEmptyDatabase()
{
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " CreateEmptyDatabase Started");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (SqlCeEngine sqlCeEngine = new SqlCeEngine(_ConnectionString))
{
sqlCeEngine.CreateDatabase();
}
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " CreateEmptyDatabase Completed in " + stopwatch.ElapsedMilliseconds + " msec");
}
private void OpenConnection()
{
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " OpenConnection Started");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
_Connection = new SqlCeConnection(_ConnectionString);
_Connection.Open();
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " OpenConnection Completed in " + stopwatch.ElapsedMilliseconds + " msec");
}
private void CreateTables()
{
const string sqlCreateTableCommand =
@."CREATE TABLE " + TableName + " " +
@."(" +
@."[TimeStamp] bigint IDENTITY(1,1) PRIMARY KEY," +
@."[Name] nvarchar(255)," +
@."[DateTime] datetime," +
@."[EventType] integer," +
@."[SourceText] nvarchar(255)," +
@."[MessageText] nvarchar(255)" +
@.");";
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " CreateTables Started");
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (SqlCeCommand sqlCommand = new SqlCeCommand(sqlCreateTableCommand, _Connection))
{
sqlCommand.ExecuteNonQuery();
}
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " CreateTables Completed in " + stopwatch.ElapsedMilliseconds + " msec");
}
private void PrepareInsertEventCommand()
{
const string sqlInsertCommand =
@."INSERT INTO " + TableName + @." " +
@."([Name], [DateTime], [EventType], [SourceText], [MessageText]) " +
@."VALUES (@.Name, @.DateTime, @.EventType, @.SourceText, @.MessageText)";
_InsertEventCommand = _Connection.CreateCommand();
_InsertEventCommand.CommandText = sqlInsertCommand;
_InsertEventCommand.Parameters.Add("@.Name", SqlDbType.NVarChar, 255);
_InsertEventCommand.Parameters.Add("@.DateTime", SqlDbType.DateTime, 8);
_InsertEventCommand.Parameters.Add("@.EventType", SqlDbType.Int);
_InsertEventCommand.Parameters.Add("@.SourceText", SqlDbType.NVarChar, 255);
_InsertEventCommand.Parameters.Add("@.MessageText", SqlDbType.NVarChar, 255);
_InsertEventCommand.Prepare();
}
public void UpdateEventHistory(Event machineEvent)
{
// Start transaction
SqlCeTransaction transaction = _Connection.BeginTransaction();
_InsertEventCommand.Transaction = transaction;
try
{
// Update command parameters and write values to database
_InsertEventCommand.Parameters[0].Value = machineEvent.Name;
_InsertEventCommand.Parameters[1].Value = machineEvent.TimeStamp;
_InsertEventCommand.Parameters[2].Value = machineEvent.EventType;
_InsertEventCommand.Parameters[3].Value = machineEvent.SourceText;
_InsertEventCommand.Parameters[4].Value = machineEvent.MessageText;
_InsertEventCommand.ExecuteNonQuery();
transaction.Commit();
}
catch (Exception exception)
{
transaction.Rollback();
_Connection.Close();
throw exception;
}
}
#endregion
Thanks.
|||Maybe you should try changing the CommitMode as per http://msdn2.microsoft.com/en-us/library/esdw1h9d.aspx
(default CommitMode is deferred)
// Commit the changes to disk if everything above succeeded;
// Use Deferred mode for optimal performance; the changes will
// be flashed (sic!) to disk within the timespan specified in the
// ConnectionString 'FLUSH INTERVAL' property; ( = 10 seconds)
//
tx.Commit(CommitMode.Deferred);
// Alternatively, you could use:
// tx.Commit(CommitMode.Immediate);
Have you looked at this: http://support.microsoft.com/kb/296076/en-us ?
|||Erik,
I changed the code to use commit immediate and the test still fails after about 12 hours.
In my case the database is completely corrupt, since it has only 20k. I think trying to compact will do nothing.
After reading the article you pointed to, looks like I cannot use this database for this kind of application.
I might try just another test by limiting the size. Right now I keep writing to the database at a rate of about 2Mb per hour.
This means my database is about 24Mb when it becomes corrupted. I will try to copy the file and start over when I reach a certain size.
Any other suggestion other than 'don't reset during a transaction'?
Thanks.
|||What is the behavior of the SQL Express database when you power down during a transaction commit? Does SQL Express have the same possible issue of getting the database corrupt as the Compact does?
|||That likely indicates file system corruption- your file is just plain gone. Consider running chkdsk.exe before running database fix. That might restore the file to pre commit state.
|||Hi, Ilya;
I have database corruption problem as well.
I found a very strange issue: my application will write some log to a log file "log.txt", but I found a corrupted .sdf database file has my log information with plain text !!!
How can I tell there is file system corruption? How can this happen? How can I find chkdsk.exe?
Cheers.
|||Is this corruption problem still valid with 3.5 version ?Arnaud.
|||Sqlce is a standalone file . so if the file was corrupt.
It looks like no good way to repaire it .