Amazon RDS SQL Server bring database online - sql-server

Having successfully taken a database instance offline using the Management Studio I then attempted it bring that same database back online both using the Management Studio and by executing the following script.
ALTER DATABASE [dbname] SET ONLINE
This results in the following error
User does not have permission to alter database 'dbname', the database does not exist, or the database is not in a state that allows access checks.

Turns out that on RDS you can use the standard SQL script above to take an instance offline, but Amazon require you to execute a stored procedure to bring it back online;
EXEC rdsadmin.dbo.rds_set_database_online dbname
See here for more http://docs.amazonwebservices.com/AmazonRDS/latest/UserGuide/Appendix.SQLServer.CommonDBATasks.html

Related

Azure SQL Automation stored procedures

I am migrating on premises SQL server database to Azure PaaS SQL database using Data Migration Tool. I am not using Data Migration Service Instance mechanism to migrate the database as it would require VPN on the corporate network and I do not see any benefit doing that way in my case.
There is one error which I am stuck on and a bit confused. When migrating a stored procedure which use automation stored procedures, I get the following error:
When I run Alter procedure script directly on Azure SQL database , I get this error;
Reference to database and/or server name in 'MASTER..sp_OACreate' is not supported in this version of SQL Server.A few answers to similar question on stackoverflow suggest that Azure SQL does not support automation stored procedures but the Microsoft link has a green tick against Azure SQL which suggest it does; https://learn.microsoft.com/en-us/sql/relational-databases/stored-procedures/ole-automation-sample-script?view=sql-server-2017.
A snippet of the sp is:
Is it true that automation stored procedures are not supported in Azure SQL and if thats hte case then what is hte workaround apart from rewriting the sp?
SQL Azure prevents you from calling server resources. sp_OACreate attempts to create a reference to an OLE object on the server; that's simply not allowed on Azure SQL Database. So you will need to redesign your solution to move this type of logic in a middle-tier of some kind, such as a Web Role in Windows Azure.

Deploy database to Azure SQL fails, sp_MSforeachtable not found

I am trying to publish a SQL Server database using a .dacpac and publish profile to an Azure SQL database. We have been using on premises SQL Server with no problems for quite some time, and now we are evaluating Azure and AWS to see which is best suited for our needs.
We have a SQL Server database project and want to deploy it to Azure SQL database, however it fails to execute the script generated by SSDT. This is because the generated script contains a call to the stored procedure sp_MSforeachtable which does not exist in Azure SQL.
I also have changed the target platform from SQL Server 2016 to Azure SQL V12. I am trying this from Visual Studio 2017's publish profile and from VSTS Release management using Azure SQL database deployment task. An of course by providing the necessary .dacpac and publish.xml files in the task.
I know I can manually add the stored procedure, however it doesn't seem that is what is intended by these publishing/deployment methods. Does anyone have any ideas?
Thanks
sp_MSforeachtable is an undocumented stored procedure in the Master database. This apparently hasn't been ported over to Azure SQL. I believe you'll need to add it manually to the Master database. Once that is done, your DACPAC should work just fine on your own Azure SQL database. I don't see a problem with manually adding sp_MSforeachtable. DACPACs are meant to keep your database in sync, not the Master database.
This feature is not implemented in SQL Database in Azure.
You can find a copy of it at this location: https://gist.github.com/metaskills/893599
Correct, sp_MSforeachtable stored procedure is still missing in Azure SQL, but you can easily create it manually. It is very helpful when you have to rebuild indexes for all tables at once:
exec sp_MSforeachtable #command1="DBCC DBREINDEX ('?', '', 80)"

Calling a stored procedure from another SQL Server Database Engine

From SQL Server Management Studio I have connected to an SQL Server database engine. This database engine has a lot of databases. From a store procedure defined in a database I am trying to call a store procedure in another database that it is in another SQL Server database engine. So I have done:
exec [MyDatabaseEngine].[MyDatabase].[MyStoreProcedure] param1, param2
But it is not working.
I do not know if I have explained it correctly. If not, please let me know.
You are missing the schema. The format is [LinkServer].[Database].[Schema].[Object]
You need to have linked server created with credentials access to the other database. More info
https://learn.microsoft.com/en-us/sql/relational-databases/linked-servers/create-linked-servers-sql-server-database-engine
Once you have it, you can run queries on another server
SELECT name FROM [SRVR002\ACCTG].master.sys.databases ;
GO

SQL Azure - How can I select sysdatabases table from master database in SQL Azure?

In SQL Azure, I try this:
select * From master.dbo.sysdatabases
And get this error:
Reference to database and/or server name in 'master.dbo.sysdatabases' is not supported in this version of SQL Server
What should I do to be able to run that query in SQL Azure?
You use the system view sys.databases (without the master qualification, it is not needed)
The system table sysdatabases has been deprecated since SQL Server 2005 (Azure is a later version) and in any case is not supported on Azure
You are getting this error because you are running this statement from another database than master. You cannot add "master." to your statements unless you are already on the master database. More generally speaking, you cannot issue statements that execute a command on another database than the one you are on.
You can run the statement without the database qualification, and it will run, as gbn is suggesting. Or you can connect to master and execute it as-is.

Backup MS SQL Server 2005?

I have a MS SQL Server 2005. It is very easy to backup individual databases, just right click on database then Tasks->Backup. My question is how to back up SQL server database objects outside the databases?
For example, under the Security->Logins, there are list of login users; under the SQL Server Agent->Jobs, there are list of jobs, and under the Server Objects->Linked Servers; ans so on.
Is there any way to do full-backup of SQL server? in TSQL? I tried to find out from SQL Server Management Studio but I could not find any.
Those items are stored in the system databases -- mostly master and msdb (under databases | System Databases). You can either back those up individually (like you do other databases) or, better yet, create a Maintenance plan (Management | Maintenance Plans) to do so on a regular schedule.
I recommend using this script. I spent much time looking after maint plan failures before it.
http://blog.ola.hallengren.com/
http://msdn.microsoft.com/en-us/library/ms187048.aspx
has more info on the standard procedure.
If you're responsible for these databases, I recommend to practice restoring the system databases on a new server, so when the time comes you are confident. The restore is not as simple as rightclicking restore.
database logins are stored in the user database, server logins are stored in master. msdb stores sql jobs and history. the simplest full backup you can do in T-SQL is:
BACKUP DATABASE dbname
TO DISK='C:\backupfile.bak' WITH INIT
WITH INIT means that it will overwrite the file.
Restoring the master database requires restart sql server in single user mode. You do this from the command line in the sql server directory with: sqlservr.exe -c - m
then connecting with SSMS or sqlcmd and run a restore.

Resources