%3CLINGO-SUB%20id%3D%22lingo-sub-1502030%22%20slang%3D%22en-US%22%3ELesson%20Learned%20%23132%3A%20Delays%20connecting%20to%20Azure%20SQL%20Database%20from%20SQL%20Server%20Management%20Studio.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1502030%22%20slang%3D%22en-US%22%3E%3CP%3EToday%2C%20I%20worked%20on%20a%20service%20request%20that%20our%20customer%20reported%20some%20delays%20when%20they%20are%20connecting%20to%20Azure%20SQL%20Database%20using%20SQL%20Server%20Management%20Studio.%20In%20this%20article%20I%20would%20like%20to%20share%20with%20you%20an%20explanation%20about%20it.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20know%20that%20in%20Azure%20SQL%20Database%20we%20have%20two%20different%20user%20types%3A%20Login%20and%20Contained%20Users%20and%20following%20I%20would%20like%20to%20explain%20what%20is%20the%20impact%20using%20both%20of%20them%20connecting%20to%20Azure%20SQL%20Database%20from%20SQL%20Server%20Management%20Studio.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBefore%20doing%20anything%2C%20I'm%20going%20to%20enable%20SQL%20Auditing%20that%20allow%20us%20to%20understand%20the%20different%20delays%20and%20what%20is%20hapenning%20behind%20the%20scenes%20when%20we%20are%20connecting%20using%20SQL%20SERVER%20Management%20Studio%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E1)%20Login%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EI%20created%20a%20login%20using%20the%20following%20TSQL%20command%3A%3C%2FSTRONG%3E%20CREATE%20LOGIN%20LoginExample%20with%20Password%3D'Password123%25'%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EI'm%20going%20to%20give%20the%20permissions%20to%20a%20specific%20database%20that%20I%20created%3C%2FSTRONG%3E%2C%20let's%20give%20the%20name%20DotNetExample.%26nbsp%3B%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EConnected%20to%20this%20database%20I%20run%20the%20following%20TSQL%20command%20to%20create%20the%20user%20and%20provide%20the%20permission%3C%2FSTRONG%3E.%26nbsp%3B%3CUL%3E%0A%3CLI%3ECREATE%20USER%20LoginExample%20FOR%20LOGIN%20LoginExample%3C%2FLI%3E%0A%3CLI%3Eexec%20sp_addrolemember%20'db_owner'%2C'LoginExample'%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3EUsing%20SQL%20Server%20Management%20Studio%20with%20the%20this%20user%20and%20specify%20the%20database%20in%20the%20connection%20string%2C%20t%3CSTRONG%3Ehe%20login%20process%20took%20around%2015%2F20%20seconds.%20Why%3F%3C%2FSTRONG%3E%3CUL%3E%0A%3CLI%3EIn%20order%20to%20explain%20it%2C%20let's%20try%20to%20review%20the%20SQL%20Auditing%20file%20and%20see%20what%20is%20happening.%26nbsp%3B%3C%2FLI%3E%0A%3CLI%3EAll%20points%20to%20a%20normal%20login%20time%20and%20connection%20if%20we%20review%20the%20SQL%20Auditing%20of%20the%20user%20database.%26nbsp%3B%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EBut%2C%20what%20is%20happening%20in%20the%20master%20database%3F.%3C%2FSTRONG%3E%3CUL%3E%0A%3CLI%3EIn%20this%20situation%2C%20I%20saw%20many%20DATABASE%20AUTHENTITICATION%20FAILED%2C%20several%20times%2C%20with%20this%20error%20message%3A%26nbsp%3Badditional_information%20%3CLOGIN_INFORMATION%3E%3CERROR_CODE%3E18456%3C%2FERROR_CODE%3E%3CERROR_STATE%3E38%3C%2FERROR_STATE%3E%3C%2FLOGIN_INFORMATION%3E%20%22Cannot%20open%20a%20specified%20database%20master%22%3C%2FLI%3E%0A%3CLI%3EWhy%3F%20because%20as%20we%20defined%20as%20a%20Login%2C%20SQL%20Server%20Management%20Studio%20is%20trying%20to%20obtain%20information%2C%20most%20probably%2C%20about%20the%20databases%20list%2C%20information%20of%20the%20server%2C%20...%20and%20in%20every%20retry%20is%20waiting%20some%20seconds.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CDIV%20id%3D%22tinyMceEditorJose_Manuel_Jurado_0%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Capture.PNG%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F202701iD1DAE310BC434F18%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Capture.PNG%22%20alt%3D%22Capture.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E2)%20Contained%20User%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EI%20created%20an%20user%20the%20following%20TSQL%20command%3A%3C%2FSTRONG%3E%20CREATE%20USER%20LoginExampleC%20with%20Password%3D'Password123%25'%20and%20gave%20the%20db_owner%20permissions.%26nbsp%3B%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EBut%2C%20Is%20the%20connection%20time%20the%20same%3F...In%20this%20situation%3C%2FSTRONG%3E%2C%20not%2C%20because%20as%20there%20is%20a%20contained%20user%20of%20this%20database%2C%20there%20is%20not%20needed%20to%20review%20any%20parameter%20of%20master%20database.%26nbsp%3B%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESo%2C%20%3CSTRONG%3Ebased%20on%20this%20situation%20and%20as%20Azure%20SQL%20Database%20is%20oriented%20to%20Database%20engine%20the%20best%20approach%20to%20reduce%20this%20time%20is%20to%20use%20a%20Contained%20User%3C%2FSTRONG%3E.%20However%2C%20if%20you%20want%20to%20reduce%20the%20time%20using%20login%2C%20you%20could%20do%20the%20following%20under%20the%20master%20database%2C%26nbsp%3BCREATE%20USER%20LoginExample%20FOR%20LOGIN%20LoginExample%2C%20to%20allow%20the%20permission%20to%20connect%20to%20this%20master%20database.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EEnjoy!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1502030%22%20slang%3D%22en-US%22%3E%3CP%3EToday%2C%20I%20worked%20on%20a%20service%20request%20that%20our%20customer%20reported%20some%20delays%20when%20they%20are%20connecting%20to%20Azure%20SQL%20Database%20using%20SQL%20Server%20Management%20Studio.%20In%20this%20article%20I%20would%20like%20to%20share%20with%20you%20an%20explanation%20about%20it.%3C%2FP%3E%3C%2FLINGO-TEASER%3E

Today, I worked on a service request that our customer reported some delays when they are connecting to Azure SQL Database using SQL Server Management Studio. In this article I would like to share with you an explanation about it.

 

We know that in Azure SQL Database we have two different user types: Login and Contained Users and following I would like to explain what is the impact using both of them connecting to Azure SQL Database from SQL Server Management Studio. 

 

Before doing anything, I'm going to enable SQL Auditing that allow us to understand the different delays and what is hapenning behind the scenes when we are connecting using SQL SERVER Management Studio:

 

1) Login:

 

  • I created a login using the following TSQL command: CREATE LOGIN LoginExample with Password='Password123%'
  • I'm going to give the permissions to a specific database that I created, let's give the name DotNetExample. 
  • Connected to this database I run the following TSQL command to create the user and provide the permission
    • CREATE USER LoginExample FOR LOGIN LoginExample
    • exec sp_addrolemember 'db_owner','LoginExample'
  • Using SQL Server Management Studio with the this user and specify the database in the connection string, the login process took around 15/20 seconds. Why?
    • In order to explain it, let's try to review the SQL Auditing file and see what is happening. 
    • All points to a normal login time and connection if we review the SQL Auditing of the user database. 
  • But, what is happening in the master database?.
    • In this situation, I saw many DATABASE AUTHENTITICATION FAILED, several times, with this error message: additional_information <login_information><error_code>18456</error_code><error_state>38</error_state></login_information> "Cannot open a specified database master"
    • Why? because as we defined as a Login, SQL Server Management Studio is trying to obtain information, most probably, about the databases list, information of the server, ... and in every retry is waiting some seconds.
 

Capture.PNG

 

2) Contained User:

 

  • I created an user the following TSQL command: CREATE USER LoginExampleC with Password='Password123%' and gave the db_owner permissions. 
  • But, Is the connection time the same?...In this situation, not, because as there is a contained user of this database, there is not needed to review any parameter of master database. 

 

So, based on this situation and as Azure SQL Database is oriented to Database engine the best approach to reduce this time is to use a Contained User. However, if you want to reduce the time using login, you could do the following under the master database, CREATE USER LoginExample FOR LOGIN LoginExample, to allow the permission to connect to this master database.

 

Enjoy!