Script Error

  • yrstruly

    SSCrazy

    Points: 2805

    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.

  • Thom A

    SSC Guru

    Points: 98269

    You forgot to include the script and the error, so this is impossible for us to help you on this right now.

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.

  • yrstruly

    SSCrazy

    Points: 2805

    The script is included above,also see screenshot attached. When i close the script box it says "Script contain error"

  • Thom A

    SSC Guru

    Points: 98269

    yrstruly wrote:

    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.

  • yrstruly

    SSCrazy

    Points: 2805

     

  • Thom A

    SSC Guru

    Points: 98269

    I don't mean to be rude, but please do take the time to read the replies

    Thom A wrote:

    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.

  • yrstruly

    SSCrazy

    Points: 2805

    MsgBox (Dts.Variables(0).Value, MsgBoxStyle.Information)

  • Thom A

    SSC Guru

    Points: 98269

    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.

  • yrstruly

    SSCrazy

    Points: 2805

    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:

     

  • Thom A

    SSC Guru

    Points: 98269

    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.

  • yrstruly

    SSCrazy

    Points: 2805

    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; }

     

  • William J. Fellows

    SSC Journeyman

    Points: 88

    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)

     

    Change Language (or not) and specify the ReadOnlyVariables

    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 12 (of 12 total)

You must be logged in to reply to this topic. Login to reply