MDF File not Opening in SQL Server - sql-server-2012

My database file of SQL Server 2012 cannot be opened, it causes the following error.
Msg 824, Level 24, State 2, Line 1
SQL Server detected a logical consistency-based I/O error: incorrect pageid (expected 1:903; actual 0:0). It occurred during a read of page (1:903) in database ID 6 at offset 0x0000000070e000 in file 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\inventoryDB.mdf'. Additional messages in the SQL Server error log or system event log may provide more detail. This is a severe error condition that threatens database integrity and must be corrected immediately. Complete a full database consistency check (DBCC CHECKDB). This error can be caused by many factors; for more information, see SQL Server Books Online.
I also checked it by using
DBCC CHECKDB(inventoryDB, REPAIR_ALLOW_DATA_LOSS)
But the result is given below
DBCC results for 'inventoryDB'.
CHECKDB found 0 allocation errors and 0 consistency errors in database 'inventoryDB'.
Is any possibilities to recover my data from that database file? I am also done many methods in many of the sites. But it not working and shows same error messages.

Do you have any mdf backup after this error occurred? If yes, you should try to create a table and restore from it using your backup.
Or try reading this article:
https://support.microsoft.com/en-ph/kb/2152734
See if it helps with your error.

You've got corruption in your DB. Either the DB was corrupt before you tried working it and you didn't notice, or it was damaged in the work.
Here. We have few options.
Solution one - If you have a backup file, You can restore your database.
Solution two - If you do not have a backup file, you can use DBCC CHECKDB to repair it. (Resource : https://www.stellarinfo.com/blog/how-to-repair-sql-database-using-dbcc-checkdb-command/)
Thanks :)

Related

SQLVDI error when backing up to Azure Storage BLOB

I'm running a patched SQL 2014 trying to backup a database to one of our Azure Storage BLOBs, using:
BACKUP DATABASE [DB]
TO URL = N'https://storage.blob.core.windows.net/server-mssqlserver/DB.bak'
WITH CREDENTIAL = N'AzureCredential'
,NOFORMAT
,NOINIT
,NAME = N'DBA_DB-Full Database Backup'
,NOSKIP
,NOREWIND
,NOUNLOAD
,COMPRESSION
,STATS = 5
GO
but the query throws the following error:
Msg 3292, Level 16, State 9, Line 1
A failure occurred while attempting to execute Backup or Restore with a URL device specified. Consult the Windows Event Log for details.
Msg 3013, Level 16, State 1, Line 1
BACKUP DATABASE is terminating abnormally.
Checking the server's Event Logs shows the actual error as:
SQLVDI: Loc=IdentifySQLServer. Desc=MSSQLSERVER. ErrorCode=(5)Access is denied.
. Process=4668. Thread=6596. Client. Instance=MSSQLSERVER. VD=.
I have made sure that the SQL Server Agent service's account has the Create global objects policy, and also made sure the SQL VSS Writer service is running under the Local System account. The error keeps happening!
Is there something I can do to fix it, or just log some more detailed error messages than the "SQLVDI: Loc=IdentifySQLServer" one above?
Crikey, this is one of those "no idea how I fixed it" things.
Before I went to lunch, I could reliably generate the error in question by running the provided T-SQL, yet when I came back from lunch the BACKUP command completed fine!
The main thing I remember changing was on the Azure side, where I created a SAS (Shared Access Signature).
This is supposedly not required for SQL 2014 as it uses an actual Azure Credential to connect to the storage instead. I actually created the SAS for an instance of SQL Server 2016 that I want backing up to the same container, and that may have opened the access pathway to the container for SQL Server 2014 too!
Many thanks to Sean Gallardy for recommending ProcMon, which showed a whole ton more error log information than the "ErrorCode=(5)Access is denied" message did.

Can't restore SQL Server database to another server

I'm trying to migrate databases from an old, dying server, to the new one.
All over the internet, I found two handy scripts by Andrew Morgan, for saving and restoring databases. The backup part works well; I get my db.bak on my local pc by sharing the folder over the network and having the script backup the db to the unc path.
Unfortunately, the restoring part won't work, and I don't know why (and my senior DEV doesn't know either, and he's the one knowing SQL aorund here).
I'm calling it this way:
Restore-SQLdatabase -SQLServer "NEWSERVER\MSSQLSERVER" -SQLDatabase "DBToMigrate" -Path "C:\Backup\DBToMigrate.bak" -SQLusername "sa" -SQLpassword "IMAPLAINTEXTPASSWORD"
sa has complete power over the database.
It fails with the following message:
Attempting to connect to the Specified SQL server: Success
WARNUNG: An Exception was caught while restoring the database!
WARNUNG: Ausnahme beim Aufrufen von "ExecuteNonQuery" mit 0 Argument(en): "Incorrect syntax near '‘'.
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon."
WARNUNG: attempting to recover the database
The part in question is:
ALTER DATABASE $SQLDatabase
SET SINGLE_USER WITH ROLLBACK IMMEDIATE
RESTORE DATABASE $SQLDatabase
FROM DISK = '$path'
WITH REPLACE
When it gets executed, the scipt gets the exception.
I tried putting a CREATE DATABASE $SQLDatabase in front of the ALTER part, but then it says something along the lines of "that database name already exists", after creating that db.
Also, when omitting the altering part and changing that part to
RESTORE DATABASE $SQLDatabase FROM DISK = '$path' WITH REPLACE
It says something about the database files, giving me the path on the old server (which I'd like to be completely irrelevant, but it seems there may be my next problem), cannot be found (of course, since I'm on my local machine now, which doesn't have those).
I'm doing it with a script, because there are around 15 databases we need to migrate, and also because I want to learn how to do this stuff without just using the SSMS wizard.
Update: I changed the apostrophes to normal ones, that was indeed the mistake. Now I just need to get the file name of the db files so I can MOVE them to the new server.
All you need is to write a new destinations to your files, you can check the syntax of RESTORE here: RESTORE Statements (Transact-SQL)
And your code will be like this:
RESTORE DATABASE AdventureWorks2012
FROM AdventureWorksBackups
WITH MOVE 'AdventureWorks2012_Data' TO
'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Data\NewAdvWorks.mdf',
MOVE 'AdventureWorks2012_Log'
TO 'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Data\NewAdvWorks.ldf';

SQL Server Restore Error - Write on ??? failed

I'm trying to restore a full backup (SQL Server 2008) from a network drive and I'm getting the error message:
Msg 3202, Level 16, State 1, Line 1
Write on "???" failed: 1(Incorrect function.)
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
I've tried twice with the most recent full backup, I then went to an older full backup, they all fail with the same message at around 90%
My first guess is that this is an issue with one of the drives it's restoring to, however chkdsk seems happy and I'm not getting any other related errors in the Event Logs or SQL Server.
Anyone have any suggestions of what to look into?
EDIT: command being used:
restore database CustomerData
from disk = '\\server\SQL Archive\CustomerData - 20170225.bak'
with file = 1,
move 'CustomerData_Data' to 'C:\MSSQL\Data\CustomerData_Data.mdf',
move 'CustomerData_Index' to 'D:\Program Files\Microsoft SQL Server\MSSQL10_50.VDI01P\MSSQL\DATA\CustomerData_Index.ndf',
move 'CustomerData_Log' to 'D:\Program Files\Microsoft SQL Server\MSSQL10_50.VDI01P\MSSQL\DATA\CustomerData_Log.ldf',
password = '',
mediapassword = '',
norecovery;
Just a guess, but do you have sufficient space left on the target drive ?
Also, this thread is potentially relevant to your situation: SQL Server backup fails on disk space error

Oracle 01033 Initialization or shutdown in progress

I've been receiving Oracle 01033 Initialization or shutdown in progress error when I try to log in to Oracle database using TOAD. When I try in SQLPlus I can connect to the database. I tried "alter database open" command and I got the following errors:
ORA-01122: database file 7 failed verification check
ORA-01110: data file 7: 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\STAJ.DBF'
ORA-01203: wrong incarnation of this file - wrong creation SCN
I looked up the answers for the same problem in stackoverflow but they did not help me.
Your database needs to be recovered. The file fails the verification checks and so the database won't open, hence the message in TOAD. SQLPlus works (locally at least) because you use that to start and stop the database, hence why you don't get the message when you use that otherwise you wouldn't be able to do anything. Get your DBA to perform a recovery (via RMAN or the method of their choice).

SQL Server 2008 R2, cant create a new DB

Having real problems creating a DB on my version of SQL Server 2008 R2 Express.
I've followed the links to the below but no info provided.
Thanks in advance for any help.
TITLE: Microsoft SQL Server Management Studio
Create failed for Database 'test'.
(Microsoft.SqlServer.Smo)
For help, click:
http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.1600.1+((KJ_RTM).100402-1539+)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Create+Database&LinkId=20476
ADDITIONAL INFORMATION:
An exception occurred while executing
a Transact-SQL statement or batch.
(Microsoft.SqlServer.ConnectionInfo)
Directory lookup for the file
"D:\DATA\test.mdf" failed with the
operating system error 2 (failed to
retrieve text for this error. Reason:
15100). CREATE DATABASE failed. Some
file names listed could not be
created. Check related errors.
(Microsoft SQL Server, Error: 5133)
For help, click:
http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.1600&EvtSrc=MSSQLServer&EvtID=5133&LinkId=20476
I would assume the issue has to do with the creation of the mdf file in your D:\Data folder. Can you verify that you have the permissions you need to that location and that you have enough free space? Also, be sure there isn't already an mdf file by that name at that location.
open the DB properties and on the files page (on the right panel) make sure that you dont have database files with duplicate names. if there are change their names