Create Database Snapshot for remote database on local machine - sql-server

I am having a subtle problem in creating Database snapshot. I am connected to a remote database. I want to create a snapshot on my local machine. Is it possible or allowed?
I am typing the query below
> CREATE DATABASE SampleSnapshot ON ( NAME = 'Sample', FILENAME =
> 'C:\SampleFile' ) AS SNAPSHOT OF Sample; GO
and getting the exception
Msg 262, Level 14, State 1, Line 1
CREATE DATABASE permission denied in database 'master'.
I am having following questions:
When i specify the path in query the snapshot will be created on local machine or server machine? If local machine then how to create the snapshot on server machine itself.

No. Generally Client/Server means you send instructions to the server. Which execute on the server. Which means that your C:\ is relative TO THE SERVER, not your client machine.

Related

Unable to attach database in Amazon RDS SQL Server

I'm trying to detach and attach a database in AWS RDS. I'm able to detach the database without any issues. But while I try to attach the database, I'm getting few errors.
When I run the attach command for the first time, I get the following error:
Unable to create database: User, group, or role 'sa' already exists in the current database.
When I execute for the second time, I get this:
Msg 1802, Level 16, State 7.
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
Msg 5120, Level 16, State 101.
Unable to open the physical file "D:\RDSDBDATA\DATA\DBattachTest.mdf". Operating system error 2: "2(The system cannot find the file specified.)". (Line 6)
Please advise
I'm not sure what you are trying to do but you should be using backup and restore functionality to move DBs around. Attach and detach will not work as they do in a traditional SQL environment: RDS is a managed service and you have extremely limited access to the underlying OS.
From AWS docs:
Restoring a Database
To restore your database, you call the rds_restore_database stored procedure.
The following parameters are required:
#restore_db_name – The name of the database to restore.
#s3_arn_to_restore_from – The Amazon S3 bucket that contains the backup file, and the name of the file.
The following parameters are optional:
#kms_master_key_arn – If you encrypted the backup file, the key to use to decrypt the file.
Example Without Encryption
exec msdb.dbo.rds_restore_database
#restore_db_name='database_name',
#s3_arn_to_restore_from='arn:aws:s3:::bucket_name/file_name_and_extension';
Example With Encryption
exec msdb.dbo.rds_restore_database
#restore_db_name='database_name',
#s3_arn_to_restore_from='arn:aws:s3:::bucket_name/file_name_and_extension',
#kms_master_key_arn='arn:aws:kms:region:account-id:key/key-id';

sp_rda_reauthorize_db not creating remote database copy

I have a db which is stretch enabled in SQL server 2016 RC3.
I took local backup of that database, and restored successfully. As we know that after restore the link to Azure SQL Server will get break, therefore I am using the below mention T-SQL to resume the connectivity, additionally I am specifying #with_copy = 1, so that it create a copy of database in Azure SQL server. But below mention T-SQL always fails with error as
Copying remote database 'RDADB_A40A50B5B-386A-42C4-B19C-3C2516172CAF' to remote database 'RDADB_A_Clone74FF1F31-A689-4866-BDD1-F90D15C157BB'.
OLE DB provider "SQLNCLI11" for linked server "stretchserver-sc-server-dbstrech-20160314-114758814.database.windows.net" returned message "Query timeout expired".
Msg 7399, Level 16, State 1, Procedure sp_rda_reauthorize_db, Line 1 [Batch Start Line 5]
The OLE DB provider "SQLNCLI11" for linked server "stretchserver-sc-server-dbstrech-20160314-114758814.database.windows.net" reported an error. Execution terminated by the provider because a resource limit was reached.
Msg 7320, Level 16, State 2, Procedure sp_rda_reauthorize_db, Line 1 [Batch Start Line 5]
Cannot execute the query "CREATE DATABASE [RDADB_A_Clone74FF1F31-A689-4866-BDD1-F90D15C157BB] AS COPY OF [RDADB_A40A50B5B-386A-42C4-B19C-3C2516172CAF]" against OLE DB provider "SQLNCLI11" for linked server "stretchserver-sc-server-dbstrech-20160314-114758814.database.windows.net".
CREATE DATABASE SCOPED CREDENTIAL AzureCred WITH IDENTITY = 'AzureAdministrator',
SECRET = '****' Declare #credentialName nvarchar(128);
SET #credentialName = N'AzureCred';
EXEC sp_rda_reauthorize_db #credential = #credentialName, #with_copy = 1
Note :- I have configured the firewall of Azure SQL server to include my IP.
The create copy part is a regression. I believe the fix is still being worked on. Please file a bug on https://connect.microsoft.com/SQLServer/feedback/ if you want to track its progress. In the meantime, you can set the option to 0 or false to avoid creating a copy. If you do need to make copies, let us know what your scenario is and we'll see if we can find you temporary workarounds.

Error while restoring db from Enterprise to BI edition of SQL Server

Every day we restore backups from production on 3 different servers. Same process has been used for months and it always works. Recently we decided to start restoring backups from production server on the 4th server meant for BI. We are however unable to do it as database restores well at first and once the restore finishes database goes into "Suspect" mode and the following message is displayed:
Msg 3908, Level 16, State 1, Line 3
Could not run BEGIN TRANSACTION in database 'DatabaseName' because the database is in emergency mode or is damaged and must be restarted.
Msg 3314, Level 16, State 3, Line 3
During undoing of a logged operation in database 'DatabaseName', an error occurred at log record ID (205933:123232:2). Typically, the specific failure is logged previously as an error in the Windows Event Log service. Restore the database or file from a backup, or repair the database.
Msg 3013, Level 16, State 1, Line 3
RESTORE DATABASE is terminating abnormally.
Msg 934, Level 21, State 1, Line 3
SQL Server cannot load database 'DatabaseName' because Change Data Capture is enabled. The currently installed edition of SQL Server does not support Change Data Capture. Either disable Change Data Capture in the database by using a supported edition of SQL Server, or upgrade the instance to one that supports Change Data Capture.
Msg 933, Level 21, State 1, Line 3
Database 'DatabaseName' cannot be started because some of the database functionality is not available in the current edition of SQL Server.
Msg 3314, Level 21, State 5, Line 3
During undoing of a logged operation in database 'DatabaseName', an error occurred at log record ID (205933:123232:1). Typically, the specific failure is logged previously as an error in the Windows Event Log service. Restore the database or file from a backup, or repair the database.
From the error message it looks like we have the problem with one of the log entries, but if this is the case why are we able to restore same backups on different servers?
Our production server from where the backups are coming runs SQL Server 2014 Enterprise edition and has CDC enabled on 4 tables.
Our BI server on which I am trying to restore the backup runs SQL Server BI edition.
Is there any way to bypass this without disabling cdc? Unfortunately we are not allowed to disable this particular feature. I did my reading, but I was unable to find anything helpful.
The only way around that I see is to restore backup on another server, disable cdc and then back up new database and transfer backup to BI server. It more more complicated and hence more likely to break than direct backup transfer. If you see any better way please let me know. Any suggestions will be highly appreciated!

Error when creating DB with a Filestream

I'm executing the following sql on a windows 7 os with sql server 2012 express.
CREATE DATABASE Archive
ON
PRIMARY (
NAME = Arch1,
FILENAME = 'c:\data\archdat1.mdf'),
FILEGROUP FileStreamGroup1 CONTAINS FILESTREAM
(
NAME = Arch3,
FILENAME = 'c:\data\filestream1')
LOG ON ( NAME = Archlog1,
FILENAME = 'c:\data\archlog1.ldf')
GO
I receive this error:
Msg 5120, Level 16, State 106, Line 1
Unable to open the physical file "c:\data\filestream1". Operating system error 259: "259(No more data is available.)".
This is what I've done before I got here:
Enabled the service to allow filestream from "sql server configuration manager".
Enabled the instance to allow a filestream.
Gave full control on the 'c:\data\' folder to the "NT Service\MSSQL$SQLEXPRESS2012" account running the sql server service
I'm at a complete loss at this point and any help would be much appreciated.
UPDATE 1
I'm installing sql server express on a new windows 7 install to see if this fixes anything.
UPDATE 2
Tried running the same sql on a windows xp box with sql server 2008 installed and received this error:
Unable to open the physical file "c:\data\filestream1". Operating system error -2147024891: "0x80070005(Access is denied.)".
UPDATE 3
Install on a clean windows 7 machine gives me the exact same error:
Msg 5120, Level 16, State 106, Line 1
Unable to open the physical file "c:\data\filestream1". Operating system error 259: "259(No more data is available.)".
UPDATE 4
I was able to get this to work on the windows xp box by changing the "Log on as" to Local System.
UPDATE 5
I tried doing the same thing (changing the "Log on as" to Local System) on the windows 7 box and am still getting the same error.
I solved this. Turns out it was our internal disk encryption software causing this error. Disabling the software was not enough. It had to be completely removed.

MSSQL mirroring error 1499

I`ve got a problem with my mirroring. I have already uses this feature to make 2 db work.
But it was on test bases.
Now when I use my scripts on work DB it throws an error:
Msg 1499, Level 16, State 1, Line 1
Database mirroring error: status 1488, severity 16, state 1, string db_name.
Any suggestions?
you database may be in single user mode
right click the database -> options and select MULTI USER under restrict access
try to check the principal and mirror server names, dtabase name etc. It is possible that there is misprints.
This happened to us recently. We found that SQL set the restored database to single user mode during the restore process.
After some research, we simply restarted SQL server services on the mirror. When SQL started back up, the restored database was in multi-user mode and we were able to initialize mirroring without any issues.
There are other sites out there with answers as well, but they involve taking down the principle database. That was not really an option for us at the time. Here is one example in case restarting the mirror does not help the next person who runs into this.
http://blog.armgasys.com/?p=259
I had some what similar issue this is how I solved it. When I ran wizard for mirroring it created endpoints(first part) successfully but when i tried to turn on mirroring it gave me error.
So I solved it by running below command on both server
USE [master]
alter database [yourdatabase] set partner off;
go
--Secondary already had partner but primary did not
--- then i ran below commands on each server.
USE [master]
ALTER DATABASE [yourdatabase]
SET PARTNER = 'TCP://OtherMachineSQLname.domain.LOCAL:5022';
GO
-- then mirroring started to work.

Resources