%3CLINGO-SUB%20id%3D%22lingo-sub-1225542%22%20slang%3D%22en-US%22%3ELesson%20Learned%20%23124%3A%20Improving%20the%20Linked%20Server%20connectivity%20performance%20using%20Azure%20SQL%20Database%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1225542%22%20slang%3D%22en-US%22%3E%3CP%3EToday%2C%20I've%20worked%20on%20an%20interesting%20service%20request%20that%20I%20would%20like%20to%20share%20with%20you.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOur%20customer%20reported%20that%20connecting%20to%20Azure%20SQL%20Database%20using%20SQL%20Server%20Management%20Studio%20and%20running%20a%20query%20that%20retrieves%20400.000%20rows%20is%20much%20faster%20that%20using%20a%20Linked%20Server%20connecting%20to%20the%20same%20server%20and%20database.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAfter%20multiple%20troubleshooting%20steps%20using%20collations%20(server%20OnPremises%20has%20a%20different%20collation%20that%20Azure%20SQL%20Database)%2C%20I%20noticed%20that%20the%20packet%20size%20that%20is%20using%20SQL%20Server%20Management%20Studio%20when%20it%20connects%20to%20Azure%20SQL%20Database%20is%20%3CSTRONG%3E8096%3C%2FSTRONG%3E%2C%20however%2C%20connecting%20using%20Linked%20Server%20the%20packet%20size%20is%20%3CSTRONG%3E4170%3C%2FSTRONG%3E.%20I%20found%20this%20executing%20the%20following%20query%3A%26nbsp%3B%3CSTRONG%3Eselect%20*%20from%20sys.dm_exec_connections%20A%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3EINNER%20JOIN%20SYS.DM_EXEC_SESSIONS%20B%20ON%20A.session_id%3DB.session_id%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3Ewhere%20net_transport%3D'TCP'%20and%20program_name%20%3D%20'Microsoft%20SQL%20Server'%3C%2FSTRONG%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20added%20in%20the%20connection%20string%26nbsp%3Bof%20the%20linked%20server%20the%20packet%20size%20%22'Server%3Dtcp%3Ayourservername.database.windows.net%2C1433%3BPersist%20Security%20Info%3DFalse%3BMultipleActiveResultSets%3DFalse%3BConnection%20Timeout%3D30%3B%3CSTRONG%3EPACKETSIZE%3D8096%3C%2FSTRONG%3E%22%26nbsp%3B%20and%20the%20performance%20is%20very%20similar%20in%20both%20scenarios.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EEnjoy!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1225542%22%20slang%3D%22en-US%22%3E%3CP%3EToday%2C%20I've%20worked%20on%20an%20interesting%20service%20request%20that%20I%20would%20like%20to%20share%20with%20you.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOur%20customer%20reported%20that%20connecting%20to%20Azure%20SQL%20Database%20using%20SQL%20Server%20Management%20Studio%20and%20running%20a%20query%20that%20retrieves%20400.000%20rows%20is%20much%20faster%20that%20using%20a%20Linked%20Server%20connecting%20to%20the%20same%20server%20and%20database.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E

Today, I've worked on an interesting service request that I would like to share with you. 

 

Our customer reported that connecting to Azure SQL Database using SQL Server Management Studio and running a query that retrieves 400.000 rows is much faster that using a Linked Server connecting to the same server and database. 

 

After multiple troubleshooting steps using collations (server OnPremises has a different collation that Azure SQL Database), I noticed that the packet size that is using SQL Server Management Studio when it connects to Azure SQL Database is 8096, however, connecting using Linked Server the packet size is 4170. I found this executing the following query: select * from sys.dm_exec_connections A
INNER JOIN SYS.DM_EXEC_SESSIONS B ON A.session_id=B.session_id
where net_transport='TCP' and program_name = 'Microsoft SQL Server' 

 

I added in the connection string of the linked server the packet size "'Server=tcp:yourservername.database.windows.net,1433;Persist Security Info=False;MultipleActiveResultSets=False;Connection Timeout=30;PACKETSIZE=8096"  and the performance is very similar in both scenarios.

 

Enjoy!