SSIS Script Component Write to Variable - sql-server-2005

This is with SQL 2005.
I have a script component inside a Data Flow Task. I would like to read from the input columns and write the data to a global user variable.
I've set my input columns and added my global user variable as a ReadWriteVariable to the script component properties.
Here is my code, I'm just trying to alter the value of the global user variable here, but its not working. When I write out the value of the variable in another task it still has its default value:
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Public Class ScriptMain
Inherits UserComponent
Dim updateSQL As String
Public Sub Main()
Dim vars As IDTSVariables90
VariableDispenser.LockOneForWrite("SQL_ATTR_Update", vars)
vars("SQL_ATTR_Update").Value = "Test"
vars.Unlock()
End Sub
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
'updateSQL = Row.ITMID + Row.PRCCAT
End Sub
End Class
I have also tried with no luck:
Me.ReadWriteVariables("SQL_ATTR_Update").Value = "Test"

I figured it out.
From MS:
In Script component code, you use
typed accessor properties to access
certain package features such as
variables and connection managers.
The PreExecute method can access only
read-only variables. The PostExecute
method can access both read-only and
read/write variables.
For more information about these
methods, see Coding and Debugging the
Script Component.
http://msdn.microsoft.com/en-us/library/ms136031.aspx
It looks like Dts is only available in Script Task.
Here is what the code looks like:
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Public Class ScriptMain
Inherits UserComponent
Dim updateSQL As String
Public Overrides Sub PostExecute()
Me.ReadWriteVariables("SQL_ATTR_Update").Value = "Test"
End Sub
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
'updateSQL = Row.ITMID + Row.PRCCAT
End Sub
End Class

Here is how you could do it:
http://microsoft-ssis.blogspot.com/2011/01/how-to-use-variables-in-script.html

Use
Dts.Variables("SQL_ATTR_Update").Value = "Test"
And SQL_ATTR_Update needs to be a global variable and listed in your ReadWriteVariables for that script task.

Related

SSIS Script Task Destination Component Not Completing

I have an SSIS Data Flow that uses a script task to create a row, process the row, and then write the result of one of the columns to a variable in a destination script task.
Destination Script is simply:
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
'
Variables.CampaignId = Row.CampaignId
'
End Sub
DataFlow
Is there something I am missing here? Do I need to be calling the end of the component? or testing for the end of the rowset?
ReadWriteVariables need to be written to in PostExecute and cannot be written to in the RowBuffer.
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
<Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute> _
<CLSCompliant(False)> _
Public Class ScriptMain
Inherits UserComponent
Dim CampID As String
' This method is called after all the rows have passed through this component.
Public Overrides Sub PostExecute()
MyBase.PostExecute()
Variables.CampaignId = CampID
End Sub
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
CampID = Row.CampaignId
End Sub
End Class
Answered my own question, but hopefully this helps someone else whom the error code does not generate for them. After multiple runs I finally got an error code about readwrite variable outside of post execute which helped tremendously with troubleshooting. Gotta love Microsoft...

Expression of type 'System.Collections.Generic.IEnumerable(Of System.Xml.Linq.XElement)' is not queryable

My class gives me an error:
Error 4 Expression of type 'System.Collections.Generic.IEnumerable(Of System.Xml.Linq.XElement)' is not queryable. Make sure you are not missing an assembly reference and/or namespace import for the LINQ provider.
I searched similar questions and found out it may be problem with imports/references. However, I think I imported everything I need and it still gives me the error.
The class and project references are below:
Imports System.Data.SqlClient
Imports System.Collections
Imports System.Data
Imports System
Imports System.Xml
Imports System.Xml.Linq
Public Class Form1
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
Dim Result As Integer
Dim mxldDataParams As System.Xml.Linq.XDocument = XDocument.Load("mypath\myxml.xml")
Private Function GetProcedureName(ByVal Name As String) As String
Dim Result As String = String.Empty
'this line gives the error
Dim Elems As System.Collections.Generic.IEnumerable(Of XElement) = From Elem As XElement In mxldDataParams.Root.Elements Where Elem.Name.LocalName = "data" And Elem.#name = Name
For Each Elem As XElement In Elems
Result = Elem...<target>...<remote>...<source>.#name
Exit For
Next
Return Result
End Function
End Class
You don't have an import for System.Linq, which means the compiler can't find LINQ to Objects, which is the LINQ implementation you're trying to use.
Just add this to your imports:
Imports System.Linq
LINQ to XML isn't really a LINQ provider - it's just an XML API which also works well with LINQ to Objects.

Import/Call class vb.net from external .vb file

I have a pretty big VB.net code and I am trying to split it into different files. I want to create an external file containing different functions. I have read about partial class files but it is not working for me. Is there any option to call/import a vb.net file and do something as per below example?
Example
Form1.vb
' Imports Functions.vb (How can I call the file containing the class?)
Public Class Form1
Dim a,b,y As Double
Dim calculate As New MyFunctions
a=1
b=1
y=calculate.sum(a,b)
End Class
Functions.vb
Partial Class MyFunctions
Public Function sum(a As Double, b As Double) As Double
return a+b
End Function
End Class
If you want all the functions to be available to all your code, just create a module with the functions in them.
If you just want to split your form1 class into separate files, your form1 file should contain the class definition ..
Partial Public Class Form1
To create a new file for the bits you want to separate off, create a new class file and change the default definition to the above.
Please note that you might need to add Imports lines for each files as well.
In and old project of mine, I had a single form program but had the code split into several files such as ExcelFileHandling.vb, EmailHandling.vb etc. They were all actually partial definitions of Form1. Easy peasy :-)
You use the Imports statement when you don't want to fully qualify a namespace of a class. If the other class is in the same namespace as the class that is referencing it, there is no need to use Imports.
Note, that your example code has functionality that should exist in a method instead of in the body of the class.
'RootNamespace = Right click on project file and choose properties. You'll see it defined there.
Imports RootNamespace.SomeOtherNamespace
Namespace SomeNamespace
Public Class Form 1
Public Sub SomeMethod()
Dim objMyFunctions As New MyFunctions()
'If no Imports is used: As New SomeOtherNamespace.MyFunctions()
End Sub
End Class
End Namespace
Namespace SomeOtherNamespace
Public Class MyFunctions
End Class
End Namespace
Example if both classes are in the same Namespace:
Public Class MyFunctions
Public Sub SomeMethod()
'No need for Imports because they are in the same Namespace.
Dim objMyFunctions As New MyFunctions()
End Sub
End Class
Public Class MyFunctions
End Class

Entity Framework VB.net - Add-Migration New Model not generate database code

Hi all and thanks in advance,
I'm having a extrange issue with entity framework with VB.net in VS2017.
I don't know why, but now if I create a new model, when making "Add-Migration" EF don't generate anything. But if I change a previous model, EF generates (and update-database) correctly.
In Migrations configuration I have AutomaticMigrationsEnabled = True
I tried to use and old database, update it, and try to make the migration again, reinstall VS, apply some small change in a model and before add the new model, but no one of this works.
Any idea about what could be happening?
Best regards,
My new Model code:
Imports Pricing.Models
Imports System
Imports System.Data.Entity
Imports System.ComponentModel.DataAnnotations
Public Class TagLink
Public Property ID As Integer
<Display(Name:="Nombre")> <Required>
Public Property Name As String
End Class
Empty migration generated
Imports System
Imports System.Data.Entity.Migrations
Namespace Migrations
Public Partial Class AddTagLink
Inherits DbMigration
Public Overrides Sub Up()
End Sub
Public Overrides Sub Down()
End Sub
End Class
End Namespace
Previous Model Changed
Imports Pricing.Models
Imports System
Imports System.Data.Entity
Imports System.ComponentModel.DataAnnotations
Public Class Counterparty
Public Property ID As Integer
<Display(Name:="Nombre")> <Required>
Public Property Name As String
<Display(Name:="DescripciĆ³n")> <Required>
Public Property Description As String
End Class
Migration generated
Imports System
Imports System.Data.Entity.Migrations
Namespace Migrations
Public Partial Class CounterPartiesDescription
Inherits DbMigration
Public Overrides Sub Up()
AddColumn("dbo.Counterparties", "Description", Function(c) c.String(nullable := False))
End Sub
Public Overrides Sub Down()
DropColumn("dbo.Counterparties", "Description")
End Sub
End Class
End Namespace

"New": Too many arguments

I made a "custom" form as seen below. When I say:
Dim nSplash As New frmSplash(nBitmap)
It is telling me that there are "too many arguments for Public Sub New".
I do not see why it is mocking about it.
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Namespace AlphaWindow
Public Class frmSplash
Inherits Form
Public Sub New(ByRef uBitmap As Bitmap)
Me.Size = uBitmap.Size
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
APIHelp.ShowTopmost(Me)
Me.SelectBitmap(uBitmap)
End Sub
(...)
' Class to assist with Win32 API calls
Class APIHelp
Private Const SW_SHOWNOACTIVATE As Integer = 4
Private Const HWND_TOPMOST As Integer = -1
(...)
End Class
End Namespace
The problem is not the Namespace, but when a namespace is included, the form has to be called by "Namespace.Form" instead of just "Form".