MSSQL Restoring database giving error that unable to open physical file and operating system error 0 (null), I am unable to restore this data base - sql-server

I am trying to restore this database from
https://github.com/Microsoft/sql-server-samples/releases/tag/wide-world-importers-v1.0
but getting this below error. Help on this will much more appreciated.

The following Github issue suggests that the WorldWideImporters sample database requires the FILESTREAM capability: Restore database backup onto mounted directory with FILESTREAM #122
Error: Unable to open the physical file "C:\Temp\WideWorldImporters_InMemory_Data_1" Operating system error 0: "(null)"
...
nocentino commented on 6 Jan 2021
Hi there, Filestream is not supported in SQL Server on Linux and Docker containers. Check out this link for more details - https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-editions-and-components-2019?view=sql-server-ver15#Unsupported
From your screen shot it appears that you are using SQL Server Express's LocalDB which also does not support FILESTREAM, ref: SQL Server Express LocalDB:
Restrictions
LocalDB cannot be managed remotely via SQL Management Studio.
LocalDB cannot be a merge replication subscriber.
LocalDB does not support FILESTREAM.
LocalDB only allows local queues for Service Broker.
An instance of LocalDB owned by the built-in accounts such as NT AUTHORITY\SYSTEM can have manageability issues due to Windows file system redirection. Instead use a normal Windows account as the owner.

Related

Migrate SQL Server to Windows from Linux

I've been running SQL Server Express 2019 on our Linux Server, and I am currently planning our disaster recovery setup.
I was already able to backup the database automatically, but I can't seem to restore the database to a SQL Server on Windows. I've been using a localDB instance to test it, but I seem to be unable to restore the database to it
Note: the .bak file came from Linux SQL Server.
Every time I try to restore the database it says that the sysfiles1 is corrupted, but when I try to restore a database from a Windows SQL Server, it works fine. I also tried to restore the Linux database back to itself and that works, too.
There have been many articles that show how to migrate from Windows to Linux but I can't find any that shows how to migrate from Linux to Windows.
The reason I want to test if I can go back to Windows is that we only have one server that runs Linux in the office and a lot of Windows computers.
TLDR: I want to know if its possible to migrate database from Linux to Windows
The problem is LocalDB. I got same error each time I tried to restore database from linux. Then I made same restore in another server (SQL Server Standart is installed) and it successfully restored database. Then I restored to my local machine from that SQL Server Standart backup.

Restoring a running database in a different name in same server in SQL Server 2012 using Management Studio

I have SQL Server 2012 (64-bit) (MSSQL11)
running on Windows 2012 R2 (64-bit) (NT 6.3)
with .NET framework 4.0.
It has a database called db_X and since this is a live production database it is always running and stopping it is not an option.
This is the only SQL Server database server that I practically have.
I want to take a backup (i.e. a full backup) of db_X (which I know how to do) and restore that backup (that .bak file) under a different name (say db_Y) in the same SQL Server database server.
I created a new database called db_Y, then right clicked db_Y then went to Tasks --> Restore --> Database...
Then I gave the path to that .bak file (as source) and tried to restore it by giving db_Y as destination (with the option - overwrite the existing database i.e. WITH REPLACE)
But this is not working. It is giving an error.
It says restore of database db_Y failed. System.Data.SqlClient.SqlError: The file C:...\db_X1.mdf cannot be overwritten. It is being used by database db_X. Microsoft.SqlServer.SmoExtended.
But I still believe that this can be done using the Management Studio. Or at least using a script. (as this is a common requirement.)
Why is it trying to restore on db_X, when I have clearly given db_Y as my destination? Isn't this a bit scary as db_X is my live database (because I might lose some data)?
How is it possible to (have a copy of an existing and running database under a different name in SQL Server or in other words) restore a backup of an existing and running database with a different name in SQL Server 2012?
I am grateful if someone could kindly explain how this can be done using the Management Studio or at least using a script.
When you are restoring the database, you need to rename the database to something other than the name of the original:
And then click the Files section and makes sure the file names are different than the original database:

How to attach a SQL database created under a different account

I created several SQL databases on an external drive using the local admin account on my PC. This PC was then recalled and rebuilt by Head Office.
I have tried and failed to attach these databases to a new install of SSMS.
All of this was done using SQL Server 2016 Developer Edition.
I can created new DBS on the external drive.
I have given my local admin account and the SQL NT Service account (including the SQL Agent one) full access to the folders, the .MDF and the .LDF files.
The error is 'Create file encountered operating system error 5(access is denied.) while attempting to open or create the physical file 'D:|SQLDATA\TESTDB.mdf.' (Microsoft SQL Server, Error: 5123)
Could it be because I didn't detach the databases from the old SQL Server install, which no longer exists?
If anyone can help, I'll be very grateful.
Run Sql as administrator.
or
Right click on file. Propetries > Security.
change the security permissions of ldf , mdf file to full permissions.

xp_cmdshell on SQL Server Linux Public Preview

I am using the Public Preview of SQL Server 2016 on Linux.
I am trying to run xp_cmdshell and get the following error.
I suspect it has to do with permissions but have no idea how to fix this.
I have spent many hours searching for some answers but there seems to be little support for SQL Server on Linux.
I am running this using an administrator account.
SQL Server is installed on Ubuntu 16.4 (as recommended).
I connect to it with Microsoft SQL Management Studio running on Windows 10.
SQL code:
EXEC xp_cmdshell #SQLtext, no_output
Error message:
Msg 15121, Level 16, State 21, Procedure xp_cmdshell, Line 1 [Batch
Start Line 159] An error occurred during the execution of xp_cmdshell.
A call to 'CreateProcess' failed with error code: '2'.
According to Microsoft's Release Notes for SQL Server 2017 General Availability, the following are currently not available on Linux:
Database engine
Transactional replication
Merge replication
Stretch DB
Polybase
Distributed query with 3rd-party connections
System extended stored procedures (XP_CMDSHELL, etc.)
Filetable
CLR assemblies with the EXTERNAL_ACCESS or UNSAFE permission set
Buffer Pool Extension
SQL Server Agent
Subsystems: CmdExec, PowerShell, Queue Reader, SSIS, SSAS, SSRS
Alerts
Log Reader Agent
Change Data Capture
Managed Backup
High Availability
Database mirroring
Security
Extensible Key Management
AD Authentication for Linked Servers
AD Authenticatin for Availibility Groups (AGs)
Services
SQL Server Browser
SQL Server R services
StreamInsight
Analysis Services
Reporting Services
Data Quality Services
Master Data Services
Microsoft also has a list of Release notes and a list of unsupported features here.

Adventureworks restore failed

I've just installed MS SQL Server Express 2014 and SQL Server Management Studio 2014 under Windows 10. I'm following the official Microsoft tutorial on database fundamentals, which uses the Adventureworks DW2008 database. I have tried to restore this dB using the Restore GUI, but it fails every time, as shown here:
AdventureWorks restore failure
I have verified the backup media, but it still fails. I have also restored a different dB, and that worked fine, so I know I am following the correct procedure. I have the file (AdventureworksDW2008Big.bak) in the following location:
C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\Backup
Yes, I have thoroughly researched this, but still apologies if there is already an answer on here - I couldn't find it.
The DW in the filename is for Data Warehouse and only works on that edition of SQL Server. As you only installed SQL Express you cannot use it.
Why not try Adventure Works 2014 Full Database Backup.zip instead. If you really need 2008/R2 try the none-DW from here:
AdventureWorks2008R2_Database.zip
AdventureWorks2008_Database.zip
I do not know if it will solve your problem or not,
but I had same problem. I mean I am using SQL SERVER 2017 and I wanted to restore AdventureWorks2012.
I received restore failed error, and I decided to restore AdventureWorks2017. my queries on AdventureWorks2012 in an older system in university led to the same results as my queries in AdventureWorks2017 in my system. if you are using a version of SQL SERVER and trying to restore an older or another version of AdventureWorks, you can try the same way.
I mean restoring a version of AdventureWorks which is the same as the version of your SQL SERVER.
Best to run SSMS as an administrator to avoid access denied errors (do this by right click on SSMS and choose More -> administrator)
copy adventureworksxx.bak into the sql server DATA directory where by
default all databases are usually located. ( Note: if it is in other directory
the restore may not find it OR may cause errors later)
Restore the database

Resources