April 14, 2019 at 10:02 am
I am using the following Script: MsgBox (Dts.Variables(0).Value, MsgBoxStyle.Information)
It gives an error, can anybody please tell me what is wrong? Thank You In Advance.
April 14, 2019 at 10:34 am
The script is included above,also see screenshot attached. When i close the script box it says "Script contain error"
April 14, 2019 at 10:52 am
The script is included above,also see screenshot attached. When i close the script box it says "Script contain error"
That won't be the whole script (if it is, that's your problem). Post the whole script, and not as an image.
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
April 14, 2019 at 11:10 am
April 14, 2019 at 11:27 am
I don't mean to be rude, but please do take the time to read the replies
That won't be the whole script (if it is, that's your problem). Post the whole script, and not as an image.
Those are images.
Looking at those images though, there are multiple syntax errors being highlighted in them; have you had a look at those? What are they saying is wrong?
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
April 14, 2019 at 11:43 am
MsgBox (Dts.Variables(0).Value, MsgBoxStyle.Information)
April 14, 2019 at 11:55 am
What is the goal your trying to achieve here? Normally using a script task to display a message box isn't actually a good idea. When running a deployed package you can't display things, and it would actually cause the package to fail. You're also referencing a package variables but aren't passing any in the script properties in the read only and read)write variables.
If we can understand your goal we can help you debug. I suspect that the combination of trying to display a message box, along with referencing a variable the script does have access to is the problem here.
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
April 14, 2019 at 12:08 pm
I appreciate your help dearly. I am self training by following the book: Microsoft SQL Server 2012 Integration Services: An Expert Cookbook.
That's why i included the page i am working from(which contain instructions and the script).
On another Question. When i get an exclamation mark(!) and the package still runs, is that a concern? See below:
April 14, 2019 at 12:40 pm
That symbol is a warning. Most likely the data types of your source and destination are identical and you aren't explicitly converting the value. In this case it's warning you of the possibility of truncation.
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
April 14, 2019 at 3:16 pm
Every script i copy from this book gives an error. Any reason for that? I am using a trial version of SQLSERVER 2017 and SSDT 2013.
public void Main() { MessageBox.Show( Dts.Variables["User::RowCount"].Value.ToString() ); Dts.TaskResult = (int)ScriptResults.Success; }
April 16, 2019 at 2:33 am
SSIS 2005 only supported VB.NET as your scripting language. I think 2008 or 2008 R2 allowed for C# to be used as the Scripting language in an SSIS Script Task. One of the authors (Andy Leonard) was/is a fan of VB and provided most of his examples using it if I recall correctly. When you add a new Script Task to the canvas, and only when you add a new script task do you get the opportunity to specify which language you would like to use.
Once you exit (it auto-saves) the second instance of Visual Studio that fires up to edit the task, you are committed (for that task at least) to the language selected. In your examples, you have selected C# as the language but are using VB.NET as the language. That is why it is failing. (Step 1)
VB code
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
<Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute()>
<System.CLSCompliantAttribute(False)> _
Partial Public Class ScriptMain
Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
Public Sub Main()
MsgBox(Dts.Variables(0).Value, MsgBoxStyle.Information)
Dts.TaskResult = ScriptResults.Success
End Sub
#Region "ScriptResults declaration"
'This enum provides a convenient shorthand within the scope of this class for setting the
'result of the script.
'This code was generated automatically.
Enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
End Enum
#End Region
End Class
C# version of code
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
namespace ST_ef785d203ac5456d8cb9874c3c063fc7
{
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
public void Main()
{
MessageBox.Show(Dts.Variables[0].Value.ToString(), string.Empty, MessageBoxButtons.OK);
Dts.TaskResult = (int)ScriptResults.Success;
}
#region ScriptResults declaration
/// <summary>
/// This enum provides a convenient shorthand within the scope of this class for setting the
/// result of the script.
///
/// This code was generated automatically.
/// </summary>
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
}
}
Either version of code attempts to access the zeroeth element of the Dts Variables collection, accesses its Value property and displays the string value of it. However, to do that, we have to tell the script task which variable we'd like to inspect. We do this on that first screen by finding our newly created variable in the ReadOnlyVariables section by clicking the ellipses. (Step 2)
It should now run fine as long as you use the correct sample code for the ScriptLanguage and specify your Variable in the ReadOnlyVariables collection.
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy