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?
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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
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 ConnectWise

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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.