Hello,
I've got a question I hope someone could help me out with. I'm working on a SSIS project that basically synchronises logins of a Source and Destination server that are part of an AlwaysOn Cluster.
The idea is as followed: On the source server there are variable tables created named Logins_<SourceServerName>_To_<DestinationServerName> for example. This one is filled with all the login information from that server, then on the Destination server the same table is created and the data is transfered. The Source and Destination server names are project variables.
Once all data is copied I use a set of code from the dba_CopyLogins script I got from SQLSoldier (http://www.sqlsoldier.com/wp/sqlserver/transferring-logins-to-a-database-mirror) to create the missing logins on the Destination server.
What I've found is that I can't use expressions to handle the code, at least I haven't found a way yet, expression evaluation will give an error on (for example) the following code:
Begin Set @SQL = 'Create Login ' + quotename(@LoginName) If @Type In ('U', 'G') Begin Set @SQL = @SQL + ' From Windows;' End Else Begin Set @PasswordHashString = '0x' + Cast('' As XML).value('xs:hexBinary(sql:variable("@PasswordHash"))', 'nvarchar(300)'); Set @SQL = @SQL + ' With Password = ' + @PasswordHashString + ' HASHED, '; Set @SIDString = '0x' + Cast('' As XML).value('xs:hexBinary(sql:variable("@SID"))', 'nvarchar(100)'); Set @SQL = @SQL + 'SID = ' + @SIDString + ';'; End
I've tried various things to get this to work as an expression, however I seem to continue to get the error:
The expression might contain an invalid token, an incomplete token, or an invalid element. It might not be well-formed, or might be missing part of a required element such as a parenthesis.
So the next thing I tried was just using the script as Direct input with Parameter Mapping on the tables but I've got the error:
Must declare the table variable "@P1".
All the way up to @P12. Since we're talking about 12 variables that are in the script in total. But they are table variables and apparently Parameter mapping is not possible on table variables or am I wrong here? Pieces of code for example are:
Set @MaxID = (Select Max(LoginID) From ?) Set @CurrID = (Select Min(LoginID) From ?)
I hope there's someone who could help me out or at least can give me a direction to look into.
Yes we could use the script provided, but we don't want to work with LinkedServers, besides I'd have to make local jobs on the servers instead of controlling it all from 1 centralised server.
Thank for looking at the topic and I hope you have a clue about what to do...
Regards,
Danny