Willow Posted May 20, 2022 Share Posted May 20, 2022 (edited) In this script, the user is prompted for an email address to update a SQL database mail account named 'test' and saves the new email address to details.txt in which a SQLcmd script is created and saved for later. There are no problems getting the username ($username) but I cannot get all this to write to the file with the proper required syntax The first line is an example command prompt SQLCmd script which works without issue and of course, not part of the Autoit script. Autoit opens the required file and does the file write in the 3rd line. But this does not match the required syntax in line one, and SQL will error out on the syntax when pasted into a cmd prompt. I have spent quite a bit of time trying different syntax, but have had no luck. Any advise is appreciated. ** SqlCmd -E -Q "EXEC msdb.dbo.sysmail_update_account_sp @account_name = 'test', @username = 'email@example.com'" $file = FileOpen(@TempDir & "\details.txt", 1) FileWrite($file, "SQLcmd -e -q" & '"EXEC msdb.dbo.sysmail_update_account_sp @account_name = "test", @username = "' & $username & '"' & @CRLF) ** In the saved details.txt, note the different sytax (quotes) around "test" and "firstname.lastname@example.org" *** Need this to match the first line above SQLcmd -e -q"EXEC msdb.dbo.sysmail_update_account_sp @account_name = "test", @username = "email@example.com" Edited May 20, 2022 by Willow Link to comment Share on other sites More sharing options...
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!Register a new account
Already have an account? Sign in here.Sign In Now