Page 1 of 1

Azure CREATE LOGIN fails

Posted: Sun 07 Aug 2016 18:53
by djb
I'm using SDAC version 6.10.21 with an Azure SQL Database.

When I issue the following query I get an error:

Code: Select all

aLoginName := 'NewUserName';
aPassword := 'NewUserPassword1!';
Query.SQL.Text := 'CREATE LOGIN :LoginName WITH PASSWORD = :Password';
Query.ParamByName('LoginName').AsString := aLoginName;
Query.ParamByName('Password').AsString := aPassword;
Query.Execute;
Incorrect param near '@P1'.

HOWEVER, this code DOES work:

Code: Select all

Query.SQL.Text := 'CREATE LOGIN NewUserName WITH PASSWORD = ''NewUserPassword1!''';
Query.Execute;
Any ideas why passing parameters to this query would be causing a problem?

The code is in exactly the same place and is connected to the master database.

As a side note, calls to Query.FinalSQL don't seem to give the full query with the parameters expanded.

Thanks!

Re: Azure CREATE LOGIN fails

Posted: Mon 08 Aug 2016 11:17
by ViktorV
This question is not related to SDAC functionality, but to specificities of Azure SQL Database architecture.
The issue is that CREATE LOGIN and ALTER LOGIN won't take the variable. The way around this is to use Dynamic SQL:https://social.msdn.microsoft.com/Forum ... ransactsql

Re: Azure CREATE LOGIN fails

Posted: Wed 10 Aug 2016 23:58
by djb
Thanks, I couldn't find that information anywhere else. Absolute nonsense, but that's Azure...

Re: Azure CREATE LOGIN fails

Posted: Thu 11 Aug 2016 08:03
by ViktorV
Thank you for being interested in our products.
If you have any questions concerning our products, please don't hesitate to contact us - and we will try to help you resolve them.