Convert Script to C# from Visual Basic

I am trying to convert the attached Visual Basic script to C#, but am running into some issues. Any ideas?
Public Sub Main()
'
' Add your code here
'
Dts.Variables.Item("ssas_backup_script").Value = _"<Backup xmlns=""http://schemas.microsoft.com/analysisservices/2003/engine"">" 
+ _
" <Object>" + _
" <DatabaseID>" + Dts.Variables.Item("ssas_database_name").Value.ToString + "</DatabaseID>" + _
" </Object>" + _
" <File>" + Dts.Variables.Item("ssas_database_name").Value.ToString + ".abf</File>" + _
" <AllowOverwrite>true</AllowOverwrite>" + _
" <Password>password</Password>" + _
"</Backup>"
Dts.TaskResult = Dts.Results.Success
End Sub

Open in new window

LVL 3
computerstreberAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

silemoneCommented:
What exactly is Dts.Variables.Item?  What type of object?

0
computerstreberAuthor Commented:
It is a string variable. I tried this:

Dts.Variables["ssas_backup_script"].Value = "test";
string test = Dts.Variables["ssas_backup_script"].Value.ToString();
MessageBox.Show(test);
0
silemoneCommented:
oops...should have asked:

Dts is  a static class...Variables is an array? or Dts a Dataset?  please explain?
0
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

computerstreberAuthor Commented:
This is a snippet from a script task I am doing in SSIS. DTS is a class, I believe. I created a user variable and am using a C# script to assign its value. After a little bit of testing, I think I got this to work:

Dts.Variables["ssas_backup_script"].Value = "test";
string test = Dts.Variables["ssas_backup_script"].Value.ToString();
MessageBox.Show(test);
0
computerstreberAuthor Commented:
It seems to work when I do the simple declaration of "test", but the compiler doesn't like it when I add the rest of the stuff in it.
0
computerstreberAuthor Commented:
It appears the issue is with the addition of the variable name in code.

Currently, I have this:

Dts.Variables["ssas_backup_script"].Value = @"string stuff" + Dts.Variables["ssas_database_name"] + @"more string stuff";

The compiler is complaining about the "+".
0
silemoneCommented:
you only need one @ symbol...
0
silemoneCommented:
you should first put the string together and then use '@' once at the beginning
0
computerstreberAuthor Commented:
In code (a) below, I get the following errors:

Unrecognized escape sequence


(a) public void Main()
        {
            Dts.Variables["ssas_backup_script"].Value = @"<Backup xmlns=""http://schemas.microsoft.com/analysisservices/2003/engine""><Object><DatabaseID>" + Dts.Variables["ssas_database_name"].Value.ToString() + "</DatabaseID></Object><File>J:\SQLServer\test.abf</File><AllowOverwrite>true</AllowOverwrite></Backup>";
            string showme = Dts.Variables["ssas_backup_script"].Value.ToString();
            MessageBox.Show(showme);
            // Dts.TaskResult = (int)ScriptResults.Success;
        }

Open in new window

0
computerstreberAuthor Commented:
I don't know what I did, but I was able to get this to work:

public void Main()
        {
            Dts.Variables["ssas_backup_script"].Value = @"<Backup xmlns=""http://schemas.microsoft.com/analysisservices/2003/engine""><Object><DatabaseID>" + Dts.Variables["ssas_database_name"].Value.ToString() + @"</DatabaseID></Object><File>J:\SQLServer\test.abf</File><AllowOverwrite>true</AllowOverwrite></Backup>";
            string showme = Dts.Variables["ssas_backup_script"].Value.ToString();
            MessageBox.Show(showme);
            // Dts.TaskResult = (int)ScriptResults.Success;
        }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.