I have a general question I'm hoping someone can answer about creating custom properties for use in a Data Flow Component.
Is it possible to create custom properties for use at the column level? I can create custom properties at the component level, no problem, but that does me no good.
I want to add two properties (Encrypt and Decrypt) to the Input Column metadata.
Say I have a collection of Input columns col1, col2, col3. As a developer, I would like to set col3's Encrypt value to true so, at run time, col3 gets encrypted before being loaded into a database.
I have successfully encrypted and decrypted using a custom component. Still, I used the values "e" and "d" in the column Description and then evaluated that Description during PreExecute. I set a state object based on the value of Description and add it to a collection that is processed during ProcessInput. I don't think using the Description is a good thing to do, and that is the need for the custom properties.
Do SSIS columns have custom properties?
The answer is yes. SSIS columns are objects that inherit the IDTSColumn130 interface. As mentioned in the SSIS documentation, this interface contains a property called CustomPropertyCollection that contains the collection of IDTSCustomProperty100 objects added to the input by the component.
Some components add some custom property to the SSIS columns such as the Derived Column Transformation. As I know, a custom component called FriendlyExpression is used to store the expression in plain text form. But, there is no way to add custom properties in the Integration Services package designer (Visual Studio).
How to add Custom Properties?
I think the only way is to create packages programmatically and edit those values or develop a custom SSIS component that adds these properties at runtime.
This is an example of reading the custom properties of a Derived Column transformation using C#. (Reference)
foreach (IDTSInputColumn localIColumn in localInput.InputColumnCollection)
{
if (localIColumn.CustomPropertyCollection.Count == 2)
{
repository.AddAttribute(componentRepositoryID, localInput.Name + " [" + localIColumn.Name + "] [ID: " + localIColumn.ID.ToString() + "]", "From [" + localIColumn.UpstreamComponentName + "] " + FormatColumnDescription(localIColumn.Name, localIColumn.DataType, localIColumn.Length, localIColumn.Precision, localIColumn.Scale) + " Expression " +
localIColumn.CustomPropertyCollection["FriendlyExpression"].Value != null ? localIColumn.CustomPropertyCollection["FriendlyExpression"].Value.ToString() : "Not Available"
);
}
else
{
repository.AddAttribute(componentRepositoryID, localInput.Name + " [" + localIColumn.Name + "] [ID: " + localIColumn.ID.ToString() + "]", "From [" + localIColumn.UpstreamComponentName + "] " + FormatColumnDescription(localIColumn.Name, localIColumn.DataType, localIColumn.Length, localIColumn.Precision, localIColumn.Scale) + " Expression (See Ouput Column)");
}
//repository.AddObject(localIColumn.Name, "", ColumnEnumerator.ObjectTypes.Column, componentRepositoryID);
}
Alternatives
You can store the columns metadata within an external data source (SQL, XML, ...) and load it at runtime. Or you can use the Description property as you mentioned in your question.
Related
I want to overwrite a zip file in a folder but when i tried the below expression, it is giving an error as:
The expression is not valid and could not be parsed. it might contain invalid elements.
Expression:
#[User::Command_Syntax] = " /c copy " + "\"" + #[User::Output_File_Path_Var] + substring(#[User::Output_Zip_Name_Var], 1, len(#[User::Output_Zip_Name_Var]) - 4) + REPLACE(right(#[User::Output_Zip_Name_Var], 4) , ".zip", "") + ".zip" + "\"" + " " + "\"" + #[User::Archive_File_Path_Var] + substring(#[User::Output_Zip_Name_Var], 1, len(#[User::Output_Zip_Name_Var]) - 4) + REPLACE(right(#[User::Output_Zip_Name_Var], 4) , ".zip", "") + ".zip" + "\""
Can any one please let me know why i'm getting error. Thanks in advance!
I use a tool, which is outside of Visual Studio, which helps troubleshoot expression building. The tool information is here: SQLIS | SSIS Expression Editor & Tester and the github is here: SSIS Expression GitHub
That being said, I copy/pasted your expression above into the editor, added in the # user variables with made-up values in the "Add Variable" ability of the tool, and I get this as my output when evaluating.
So it does seem to evaluate for me, could you verify your user variables are spelled correctly and they are the correct type (string)?
You could also verify the variable assignments during debugging. Here is a good article on how to debug, if needed: Debugging Control Flow in SSIS
I'm working on a WPF application and i cant seem to get this right. I am brand new to WPF.
I want to get the text from the database into text boxes but i tried it with only one textbox the first time and i get this error:
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: No value given for one or more required parameters.
This is the code i have so far, this is how it's done in winforms but i suppose not the same in WPF
dbconn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=ChampInfo1.accdb");
dbconn.Open();
string selectallSQL = "SELECT Passive " +
"FROM BChampInfo " +
"WHERE [Champ Name] = Aatrox";
dbcomm = new OleDbCommand(selectallSQL, dbconn);
OleDbDataReader dbread = dbcomm.ExecuteReader();
while (dbread.Read())
{
txtskillname1.Text = dbread["Passive"].ToString();
}
I don't know what is wrong though, any help will be appreciated.
All my oledb declaration are done at the top.
It can be the easy target for sql injection. The problem is in query. Try this
string selectallSQL = "SELECT Passive " +
"FROM BChampInfo " +
"WHERE [Champ Name] = ?";
dbcomm = new OleDbCommand(selectallSQL, dbconn);
dbcomm.Parameters.AddWithValue("#aat", "Aatrox");
I think a lot of developers are facing the problem of try to display page numbers by using SSRS 2008 R2.
There is an alternative solution which requires SSRS 2010 + version. Otherwise you will get 1 all the time.
Go to "Report" -> "Report Properties" -> "Code"
In the Custom Code section, enter the following:
Public Function PageNumber() as String
Dim str as String
str = Me.Report.Globals!PageNumber.ToString()
Return str
End Function
Public Function TotalPages() as String
Dim str as String
str = Me.Report.Globals!TotalPages.ToString()
Return str
End Function
Now you will be able to access these functions anywhere in the report (header, body, or footer). So, to output the page number and total pages in a textbox located in the body simply enter this for the value:
="Page " + Code.PageNumber() + " of " + Code.TotalPages()
This solution DOES NOT work with SSRS 2008 R2.
However there is a workaround, it will work with any version higher than 2008 R2 (include 2008 R2). I will post as an answer, hope it will help some people whoever struggling with this issue.
First you need to use report variables:
right click on the empty space of report -> Variables -> Create a variable such as PageCount (set default value to 0)
Then in you header or footer -> create a textbox and set expression ->
=Variables!PageCount.SetValue(Variables!PageCount.Value+1)
It will automatically increase for each page.
(IMPORTANT: DO NOT hide it from header or footer, the SetValue WON'T work if you hide the box, so change the font to 1 or text to white, do whatever, just DO NOT hide it (it will print 'True' as the setting took places))
Then you can use:
=Variables!PageCount.Value
at any part of your report body to access the page number.
IMPORTANT: Please NOTE that I tried to use Globals!PageNumber to set the variable but ends up it was NOT accessible from report body. So, it has to be something both accessible from Header/Footer OR Body.
In my case, I have to reset the Page number per each instance of my Group.
So I just set a trigger at the end of the group.
(e.g. I check if I have my Total value returns, because i know for each end of my group i will have a Total display.
Because of in function IIF both True and False part will be processed, so if you put setters in IIF such as below:
=IIF(IsNothing(ReportItems!TotalBox.Value),Variables!PageCount.SetValue(Variables!PageCount.Value+1),Variables!PageCount.SetValue(0))
)
you will ends up have value 0 all the time, because the report will Check the True Part then the False part, both setters will be executed (value will be set twice)
so we need 2 boxes and something like:
(You have to hide unnecessary box your checking conditions)
=IIF(IsNothing(ReportItems!TotalBox.Value),Variables!PageCount.SetValue(Variables!PageCount.Value+1),"")
)
You need to hide this box when NOT IsNothing(ReportItems!TotalBox.Value)
=IIF(NOT IsNothing(ReportItems!TotalBox.Value),Variables!PageCount.SetValue(0),"")
)
Again you need to hide this box when IsNothing(ReportItems!TotalBox.Value)
Of course you could use some other way to determine the end of a group instance, like:
make a textbox which ONLY contains a fixed value at the end of your group table. and hide it. when you checking the trigger just do the similar approach as I do.
It works fine for all versions above 2008 R2 (included).
If you are using SQL Server 2016 Report Builder, this expression worked with me.
=Globals!PageNumber.ToString() +"/" + Globals!TotalPages.ToString()
Here is working expression:
=Microsoft.VisualBasic.Interaction.Switch(Parameters!LANGUAGE.Value = "en-US", "Page " + code.PageNumber().ToString() + " of " + code.TotalPages().ToString(), Parameters!LANGUAGE.Value = "es-MX", "Hoja " + code.PageNumber().ToString() + " de " + code.TotalPages().ToString(), 1 = 1, "Page " +code.PageNumber().ToString() + " of " + code.TotalPages().ToString())
In Visual Studio 2013 Report variables will be Visible under Report menu.
From Main Menu - Report > ReportProperties > Variables > Add
First Follow the steps 1 below to do pagination:
1)
1.1. Click the Details group in the Row Groups pane.
1.2. From the Tablix member Properties pane, expand “Group”-> “PageBreak”.
1.3. Set the “BreakLocation” to “End” and set the “Disable” property to the expression like below:
=IIF(rownumber(nothing) mod 40=0,false,true)
The above point 1 is use to do pagination in Report output(Display only 40 records per page in output)
2) use custom code:
Public Function PageNumberno(val as integer) as String
Dim str as String
str =(val/40)
Return str
End Function
3) Create Calculated column in Dataset and enter =0 in expression
4) In 2 Calculated Column
1)Pageno
2)No
in Dataset
In Report Body use Expression for PageNo :
=code.PageNumberno(Rownumber("DataSet1"))
use Expression for No :
=IIF(Instr(code.PageNumberno(Rownumber("DataSet1"))
,".")<>0,
(Left(code.PageNumberno(Rownumber("DataSet1")),
(Instr(code.PageNumberno(Rownumber("DataSet1")),".")-1))+1)
,code.PageNumberno(Rownumber("DataSet1"))
)
5)Right click and insert column on Right Side and in Column name add code in Text box
=ReportItems!No.Value
Note: No is calculated Field column name.
6)Under AdvancedMode IN Row Group select Static and Set RepeatOnNewPage Properties to True
In the Above Column created under point 5 will display correct page no in every page in body of the report
I have Tried and its working Fine..Try it.
I have a variable that concatenates a file path into a string , and i can't get it to evaluate the concatenation. when i display the value of the variable in a script task, i still see all the double quote marks (see below). I have set the evaluateasexpression for the variable to true.
When i try to use this variable as a sql command, the error is:
"invalid syntax near the +"
(i believe this is the plus sign below the redactedcol3 below)
BTW, is property expressions the only place where you can evaluate a variable's value as you are developing? (expression builder).
This is how the variable displays in the message box in the script component:
"SELECT redactedcol1,redactedcol2,rtrim(" + "'" + #user::LocalPath + " + "'" + "+[redactedcol3]) AS Path FROM dbo.SF_redacted where id=1"
Not entirely sure this is what you want, but I think it is:
"SELECT redactedcol1,redactedcol2,rtrim("
+ "'"
+ #user::LocalPath
+ "'"
+ " + [redactedcol3]) AS Path FROM dbo.SF_redacted where id=1"
Note the removed extraneous plus sign and double-quote. (I find it helps when concatenating in SSIS to put each part on its own line.)
And I also recommend BIDS Helper, a free tool that includes a better (IMO) expression building GUI, as well as Konesans' Expression Editor which is a like a mini-Intellisense workbench for expressions.
There's also a Variables window in SSIS Projects (View -> Other Windows -> Variables) where you can see the evaluated value of a variable expression.
For others wondering why their expression is not evaluating...
http://www.sqlchicken.com/2012/02/ssis-expressions-not-evaluating-correctly/
Click on the Variable. Make sure "EvaluateAsExpression" is True
I am using asp.net 2.0 and c#.
I have a dataset, which is getting the employee info. Now I want to filter the gridview based on a name that the user has put in the search textbox.
I am doing this:
DataSet ds = new DataSet("EmployeeInformation");
//........ loading DataSet ds with emploee info
string strExpr;
strExpr = "Name LIKE %" + txtSearchEmployee.Text.Trim() + "%";
ds.Tables[0].Select(strExpr);
I am getting an error in the last step, that the operator is missing.
Please guide me how can I achieve this. Thanks in advance.
You just need to add single quotes around your LIKE criteria:
strExpr = "Name LIKE '%" + txtSearchEmployee.Text.Trim() + "%'";
ds.Tables[0].Select(strExpr);