SQL and friends

I woke up at 6am after a restful 8 hours of sleep. Read for a bit, installed SQL Express on my laptop, ate a bowl of Raisin Bran, met up with a friend for coffee, called another friend, then came home to start the exercises in my Exam Reference book. The first exercise went well - it only used tempdb. The second exercise used a database called WideWorldImporters. I assumed it was a sample database that one can download through some Microsoft site. Found it!

https://github.com/Microsoft/sql-server-samples/releases/tag/wide-world-importers-v1.0

Yep. Downloaded WideWorldImporters-Full.bak and set to work restoring the backup to my machine. I'd done that at work plenty of times. Heck, I can just use the GUI if I'm feeling lazy. GUI it is!!!

The operating system returned the error '3(The system cannot find the path specified.)' while attempting 'CreateDirectoryW' on '\?\D:\Program Files\Microsoft SQL Server\MSSQL15.SQLEXPRESS\MSSQL\DATA\WideWorldImporters_2.$FSLOG'.

Yikes! But, sure, \?\ doesn't start any drives I know of on my computer, so I should double check what the options are for the paths for the data and the logs.  It's listing  E:\Log\WideWorldImporters.ldf as the path for the logs, but I don't have an E drive, so I change that and retry. 

The operating system returned the error '3(The system cannot find the path specified.)' while attempting 'RemoveContainer' on 'D:\Program Files\Microsoft SQL Server\MSSQL15.SQLEXPRESS\MSSQL\DATA\WideWorldImporters_2.'.

...What... what the heck? It can't find the path? That is the path. I only have two drives. One holds the application.The other holds the data and transaction logs (if I had more drives, I would split the data and logs into different drives, but no option here). I look further at the GUI to see if it's putting something in the incorrect path. I open up Windows Explorer to see what files I have in my DATA folder and notice that I don't actually have an mdf (data) file! How do I have an ndf (user data) and ldf (log) and no mdf file? I head back to SQL Server Management Studio and find that WideWorldImporters database is a thing but stuck in a restoring state. I just decide to get rid of it and start fresh. I attempt to delete the database.

Drop failed for Database 'WideWorldImporters'.  (Microsoft.SqlServer.Smo)
------------------------------

SQL Server detected a logical consistency-based I/O error: incorrect pageid (expected 1:9; actual 0:0). It occurred during a read of page (1:9) in database ID 5 at offset 0x00000000012000 in file 'D:\Program Files\Microsoft SQL Server\MSSQL15.SQLEXPRESS\MSSQL\DATA\WideWorldImporters.mdf'.  Additional messages in the SQL Server error log or operating system error 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).


Are you kidding me? I can't even drop it? Disappointingly, hours later now that I'm writing this, I've forgotten how I eventually dropped it. After it was gone, I did more searching. Google/StackOverflow/mssqltips seemed to agree it was necessary to move the file when you restore it. That could be a possibility - after all, I don't see my mdf file, and it's gotta be here in the bak file somewhere, right? I stumble upon this page: https://www.mssqltips.com/sqlservertip/4394/download-and-install-sql-server-2016-sample-databases-wideworldimporters-and-wideworldimportersdw/

And that has this code:

USE [master]
GO
RESTORE DATABASE [WideWorldImportersDW] FROM  DISK = N'R:\SQLbackups\WideWorldImportersDW-Full.bak' 
WITH  FILE = 1,  
MOVE N'WWI_Primary' TO N'F:\SQL_Data\WideWorldImportersDW.mdf',  
MOVE N'WWI_UserData' TO N'F:\SQL_Data\WideWorldImportersDW_UserData.ndf',  
MOVE N'WWI_Log' TO N'L:\SQL_Logs\SQL2016\WideWorldImportersDW.ldf', 
MOVE N'WWIDW_InMemory_Data_1' TO N'F:\SQL_Data\WideWorldImportersDW_InMemory_Data_1',  
NOUNLOAD,  
REPLACE,  
STATS = 5
GO

I replace the paths here to paths that reflect my data drive, and success!! I have a working database! Two hours after I start a 'simple 2 minute restore', I can move onto the second exercise in the book, on page 7. Whew!

Comments

Popular posts from this blog

Board games and near the end of the gym challenge

December Challenge has ended!

Surprising success with Ham and Bean soup