How can I "connect to the master database" (Azure SQL Database) - azure

(This is for an Azure SQL Database)
Just about every article says at the start to "connect to the master database" before creating a new DB.
I have connected to my Azure SQL Database server with SSMS 2014 with no problems. I see the master DB under System Databases. I right-click on Databases (this is above System Databases) in the tree on the LHS and click New Database...
The template query comments area says among other things "...connect to master..." which implies to me that I am not connected to the master.
I am obviously missing something very fundamental and obvious regarding basics.
Can someone please put me out of my misery :)
PS When I click "New Database..." when connected to my non-Azure SQL Server 2012 I get a GUI and I am able to create a DB no problem.

You do not need to explicitly connect to master to create a database in Azure SQL DB. Please follow the steps here to create a database in Azure SQL DB.
https://azure.microsoft.com/en-us/documentation/articles/sql-database-get-started/
Also, can you please give me links to the articles that mention "Connect to master" so I can take a look and correct them if needed? Thanks.

I believe you are referring to the below template. You are actually connected to the master database and this is just a template instructions. If you are in doubt query select db_name() This should return 'master' for the master database.
If your connection string either specified database name as master / nothing it will be connected to master database.
-- ==========================================================================================================
-- Create database template for Azure SQL Database
-- This script will only run in the context of the master database. To manage this database in
-- SQL Server Management Studio, either connect to the created database, or connect to master.

Related

not able to find master database under azure SQL server (dw)

I am trying to scale Azure SQLDW by following this document => azure link but help guide says, to run query under master DB.
I am logging in using system admin credential,
what am i missing.
Azure SQL DW master DB is the same with Azure SQL Server.
Please run the query in Database--System Database--master.
Login your Azure SQL DW with admin account, set the connect to database.
Step 1
Step 2
Step3
Hope this helps.
Given the first screen shot, it appears that you've connected to the user database and not the server with the default database. When connecting to your server in SSMS, click on the Connection Properties tab and make sure the Connect to database: value is set to <default>.
Connection Properties

create linked server in azure sql database

Want to create linked server in azure sql. I want to use local DB views in sql azure using linked server. Is it possible or is there any alternate way. All suggestions are welcome.
yes you can create linked servers in SQLAZURE...Assuming you have local on premises server A and database in azure say AZ_b..you can create a linked server for azure on your local on premise instance...
since you want to do this I want to use local DB views in sql azure using linked server. after creating linked server you need to run queries from server A which is your local onpremises server and this is the only way name resolution of linked server can happen and you can't do the other way
below are the steps
-- Supporse your database on Azure is named 'Azure_Test_DB'
EXEC sp_addlinkedserver
#server='myLinkedAzureServer', -- specify the name of the linked server
#srvproduct='',
#provider='sqlncli',
#datasrc='azure-test-db.database.windows.net', -- add here your server name
#location='',
#provstr='',
--------Change it by your need ------------------------------------------------------------------
#catalog='Azure_Test_DB' -- specify the name of database on your Azure DB you want to link
-------------------------------------------------------------------------------------------------
-- Configure credentials for Azure linked server
EXEC sp_addlinkedsrvlogin
#rmtsrvname = 'myLinkedAzureServer',
#useself = 'false',
--------Change it by your need ------------------------------------------------------------------
#rmtuser = 'yourLoginName', -- add here your login on Azure DB
#rmtpassword = 'yourPassword' -- add here your password on Azure DB
-------------------------------------------------------------------------------------------------
-- Configure options for Azure linked server
EXEC sp_serveroption 'myLinkedAzureServer', 'rpc out', true;
-- Now you can query the data using 4-part names
select * from myLinkedAzureServer.[Azure_Test_DB].[dbo].[Students];
once you create linked server , you can connect to server A and can run below queries
select * from
myLinkedAzureServer.[Azure_Test_DB].[dbo].[Students] az
join
localdb.dbo.table1 tbl
on tbl.somecol=az.somecol
References:
https://gallery.technet.microsoft.com/scriptcenter/How-to-create-linked-cb98fa7d
https://www.mssqltips.com/sqlservertip/3630/connect-an-azure-sql-database-to-an-onpremises-sql-server/
The above steps works for most of machines..incase it doesn't work, you need to setup a ODBC DSN by following the steps here..
https://blogs.msdn.microsoft.com/sqlcat/2011/03/07/linked-servers-to-sql-azure/
You cannot create a linked server in Azure SQL Database.
Microsoft does have a preview available of a new Instance as a Service offering that will allow you to perform cross database queries. It may also allow for linked servers. It's not yet widely available.
Now, you can use Elastic Query to set up something pretty similar. Here's a blog post I wrote on it. However, it's not the same as a linked server.
As a workaround to the limitation of linked servers not available on SQL Azure databases, you can replicate objects from on-premises SQL Server databases to SQL Azure or use SQL Data Sync to sync data between on-premises SQL Server and a SQL Azure server.
Hope this helps.

Azure SqlDatabase can't access after copy

I copied many times an sqlDatabase but i can only access with my user.
As read in the documentation, the principal became the user who started the operation.
So i tried using the sql statement to copy the database logged as the sql server administrator, but invain.
I can't access to copied database with the original sql server principal.
I need to keep this super user on all the server databases.
There is no problem. I can connect to all the databases copied.
There is only a visible difference in Sql Server Management Studio.
It is a connection option:
if I connect with Connect to Database: default, I can see all the databases on my server.
if i choose a single one, i can see only it.

Is it possible to restore a deleted Sql Server instance in Azure?

I recently deleted a SQL server instance (with 2 sql databases) on my azure portal. I would like to know if there is a way for me to restore the deleted SQL server and the corresponding Sql databases.
I would appreciate any help/direction in this regard.
Thanks
Uma
When you delete SQL Server from portal, you will get a warning : Warning! Deleting xxx is irreversible. So the best solution to this is to open a support ticket.
You could also refer to Can we recover a deleted server for Azure SQL Database? for more information.
Microsoft might be able recover the databases under these conditions:
Another SQL Server with the same name was NOT created
Less than 7 days passed since the deletion
The Region, SQL Server and Resource Group name must be known
You need to log a support ticket. If the server can be recovered, it will be restored. The databases were not restored in my case, but could be recovered using the normal method for recovering a deleted SQL Database within a SQL server.
I was able to restore an sql server by contacting MS support through a support ticket in the Azure portal.
Key things that must be available:
The name of the Sql server and database
The resource group name and time of deletion.
You should not have created another sql server resource with the same name in an attempt to recover the sql server.
I had an ARM template of the resource group that I exported from the portal. Without this I would not have remembered the names of the resources above.
Key takeaways:
Ensure that users that is not the subscription holder cannot delete resources.
Export ARM templates for all RG's - this saved my b**.
Thanks to the MS team for helping me out so quickly! They helped me out within an hour! Great service!

Strange "invisible database bug" on SQL Azure?

I have a project (say project1) which runs with the following SQL Azure connection string:
Server=tcp:....database.windows.net,1433;Database=project1;User ID=...
The database project1 exists and everything on project1 runs fine.
Then I was working on a second project (project2), and uploaded it as a second Cloud Service in Azure. I intended to store its data in the database project1 under a different schema (since there is a plan to merge the two projects), but accidentally I deployed the project with the following connection string:
Server=tcp:....database.windows.net,1433;Database=project2;User ID=...
Everything on project2 was working fine, but then I noticed that project2's tables in the database project1 were empty, although I have entered data in the cloud service. Then I noticed that the connection string pointed to a database project2.
To make it clear, there is no SQL database with the name project2. I checked in SQL Management Studio, as well as in the Silverlight SQL Azure database client.
I cannot explain this. Somehow Windows Azure or SQL Azure must have implicitly created a database project2, since I was able to work on the Cloud Service. There must be some 'hidden place', where project2 had stored its data.
Is this a bug, or am I missing something?
If you try to connect to a database that does not exist, you will automatically be connected to the master database, at least that was the case last time I tried. However master is read-only in the cloud, so I would expect most apps to fail when connecting to master. SQL Database will not create a database automatically for you, so that can't be it either. Could it be that you are trapping/silencing errors in your code and as a result you could not tell you were really connected to master?

Resources