Send Row from one DataFlow Task to Another - ssis

In response to my deleted post
I am suspecting (I could be wrong) a way to transfer limited number of rows from 1 Dataflow Task to another is by using DataReader in the
first one and ScriptTask as Source in the second one.
I need to know how to derive Connection String to connect to that
DataReader if this is all done in one package.
I was looking for a way to send processed rows from one DataFlow Task to another to simplify my design and have better control.

Here is my remarkable solution to this problem!
Code For RecordSet Source with used example
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Linq;
using System.Data.DataSetExtensions;
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
private OleDbDataAdapter oleDA = new OleDbDataAdapter();
private DataTable table = new DataTable();
private DataRow[] result;
public override void PreExecute()
{
base.PreExecute();
oleDA.Fill(table, Variables.DatabaseObjects);
var query = from table_address in table.AsEnumerable()
select table_address;
result = query.ToArray<DataRow>();
}
public override void PostExecute()
{
base.PostExecute();
}
public override void CreateNewOutputRows()
{
if (result != null)
{
foreach (DataRow ro in result)
{
Output0Buffer.AddRow();
//----------------------------------------[CHANGE BELOW]-------------------------------------------------
// EXAMPLE:
if (ro["File"] != null && ro["Sequence_ID"] != null && ro["Execution_ID"] != null && ro["Object"] != null)
{
Output0Buffer.File = ro["File"].ToString();
Output0Buffer.SequenceID = Convert.ToInt64(ro["Sequence_ID"]);
Output0Buffer.Object = ro["Object"].ToString();
Output0Buffer.ExecutionID = Convert.ToInt64(ro["Execution_ID"]);
}
//--------------------------------------- [CHANGE ABOVE]------------------------------------------------
}
}
}
}

Related

Visual Studio 2015 MySql LinQ to Entities Get generated query

I am using MySql LinQ to entities with Visual Studio. The code works except for the part that is commented out. That works with SQL but not with MySQL. Does anyone know the MySql equivalent of the code that is commented out?
using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using MySql.Data;
using MySql.Data.MySqlClient;
namespace TestMySql_Nuget_etc
{
class Program
{
static void Main(string[] args)
{
worldEntities db = new worldEntities();
var countries = from c in db.countries
where c.Name.StartsWith("A")
select c;
//string query = ((ObjectQuery)countries.ToTraceString());
foreach(var c in countries)
{
Console.WriteLine(c.Name);
}
Console.ReadLine();
}
}
}
You need to explain in more details why it's not working and what kind of exceptions/error is throwing out, if it is.
At first, you can't unbox a string directly to another Type (like ObjectQuery).
You just can unbox from a base class to an inherited one, vice versa.
The following is something you can do:
int number = 30;
object obj = number;
number = (int) obj;// if it fails, will throw a cast exception
...
class A
{
public string Name {get;set;}
}
class B : A
{
public int Age {get;set;}
}
class C
{
public int Age {get;set;}
}
...
A objectA = new A();
A objectAAndB = new B();
B objectJustB = (B) objectAAndB;
B objectB = (B) A; // It'll throw a cast exception
And follows something you can not do:
A objectA = new A();
B objectB = new B();
C objectC = new C();
A objectC1 = new C(); // It won't compile
C objectC2 = (C) objectA; // It won't compile
C objectC3 = (C) objectB; // It won't compile
A objectA1 = (A) objectC; // It won't compile
B objectB1 = (B) objectC; // It won't compile
I hope it helps you.

Storing and getting data in windows phone app and using NavigationService.GoBack()

I have created a Windows phone app based on a quiz game. I want that when the user give the correct answer for some question then a small tick mark will be permanently on in the tab of the question.
I want to store score for every question so that i can display that in a place name as 'your score'. And that score will not be reset even if the app is closed.I have used IsolatedStorageFile to store the data for each page separately. In each page i have provided a back button which will navigate to category page using "NavigationService.GoBack()".
//mainpage
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using logic.Resources;
using System.IO;
using System.IO.IsolatedStorage;
namespace logic
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/logo.xaml", UriKind.Relative));
//Obtain a virtual store for application
IsolatedStorageFile fileStorage = IsolatedStorageFile.GetUserStoreForApplication();
int y = 0;
if (!fileStorage.FileExists("amazon.txt"))
{
//Create a new StreamWriter, to write the file to the specified location.
StreamWriter fileWriter = new StreamWriter(new IsolatedStorageFileStream("amazon.txt", FileMode.OpenOrCreate, fileStorage));
//Write the contents of our TextBox to the file.
fileWriter.WriteLine(y);
//Close the StreamWriter.
fileWriter.Close();
}
}
}
}
//category page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.IO;
using System.IO.IsolatedStorage;
namespace logic
{
public partial class logo : PhoneApplicationPage
{
public logo()
{
InitializeComponent();
int x = 0;
//Obtain a virtual store for application
IsolatedStorageFile fileStorage = IsolatedStorageFile.GetUserStoreForApplication();
//Create a new StreamReader
StreamReader fileReader = null;
if (fileStorage.FileExists("amazon.txt"))
{
//Read the file from the specified location.
fileReader = new StreamReader(new IsolatedStorageFileStream("amazon.txt", FileMode.Open, fileStorage));
//Read the contents of the file (the only line we created).
string textFile = fileReader.ReadLine();
x = Convert.ToInt32(textFile);
//Write the contents of the file to the TextBlock on the page.
fileReader.Close();
if (x == 1)
{
ama.Visibility = System.Windows.Visibility.Visible;
}
}
}
private void Image_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
NavigationService.Navigate(new Uri("/amazon.xaml", UriKind.Relative));
}
}}
//question page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.IO;
using System.IO.IsolatedStorage;
namespace logic
{
public partial class amazon : PhoneApplicationPage
{
public amazon()
{
InitializeComponent();
}
//check the answer is correct or not
int count = 0;
int x;
private void b1_Click(object sender, RoutedEventArgs e)
{
if (tb1.Text.Length == 0 || tb2.Text.Length == 0 || tb3.Text.Length == 0 || tb4.Text.Length == 0 || tb5.Text.Length == 0 || tb6.Text.Length == 0)
{
}
else
{
Char s1, s2, s3, s4, s5, s6;
s1 = Char.ToUpper(tb1.Text[0]);
s2 = Char.ToUpper(tb2.Text[0]);
s3 = Char.ToUpper(tb3.Text[0]);
s4 = Char.ToUpper(tb4.Text[0]);
s5 = Char.ToUpper(tb5.Text[0]);
s6 = Char.ToUpper(tb6.Text[0]);
if (s1 == 'A' && s2 == 'M' && s3 == 'A' && s4 == 'Z' && s5 == 'O' && s6 == 'N')
{
//Obtain a virtual store for application
IsolatedStorageFile fileStorage = IsolatedStorageFile.GetUserStoreForApplication();
//Create a new StreamReader
StreamReader fileReader = null;
//Read the file from the specified location.
fileReader = new StreamReader(new IsolatedStorageFileStream("amazon.txt", FileMode.Open, fileStorage));
//Read the contents of the file (the only line we created).
string textFile = fileReader.ReadLine();
x = Convert.ToInt32(textFile);
//Write the contents of the file to the TextBlock on the page.
fileReader.Close();
if (x == 0)
{
fileStorage.DeleteFile("amazon.txt");
//Create a new StreamWriter, to write the file to the specified location.
StreamWriter fileWriter = new StreamWriter(new IsolatedStorageFileStream("amazon.txt", FileMode.OpenOrCreate, fileStorage));
fileWriter.WriteLine("1");
//Close the StreamWriter.
fileWriter.Close();
}
ans.Text = "Correct!!!";
}
else
{
ans.Text = "\n\nINCORRECT";
}
}
}
//reset the value
private void reset_Click(object sender, RoutedEventArgs e)
{
tb1.Text = "";
tb2.Text = ""; tb3.Text = ""; tb4.Text = ""; tb5.Text = ""; tb6.Text = "";
}
private void Image_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
NavigationService.GoBack();
}
}
}
The problem is that when ever i gave the correct answer and press the back button which navigate to logo page the trick(named as "ama" in category code) do not show. But when again i navigate to mainpage then come back to category page the trick is shown. I want that when ever i give the correct answer and navigate back to category page using the back button provided in the app or back button of mobile the trick should be shown at that time only.
According to your code.
Your logic is in constructor of that class. Which is called once you navigate to it from main page and is not called again when you navigate back from question page.
So, you are logically not executing any code when it navigates back, hence displaying the same view as it was.
To make it update, write your logic code in Page_Loaded event.

Chrome_AutocompleteEditView gone in July 2013 from Chrome Browser

From 2011 to the July of 2013 i have been using FindWindowEx to get data from the Chrome Browser about current url. Today 25.09.2013 ,I've noticed that the class Chrome_AutocompleteEditView is gone... My currrent Chrome Version is 29.0.1547.76
Does anyone of you have idea how can i read this url right now ?
Below my code
Thanks
IntPtr handle = getforegroundWindow();IntPtr urlHandle = FindWindowEx(handle, IntPtr.Zero, "Chrome_AutocompleteEditView", null);
My problem have been solved
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Windows.Automation;
namespace ui_automation
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
foreach (Process process in Process.GetProcessesByName("chrome"))
{
string url = GetChromeUrl(process);
if (url == null)
continue;
MessageBox.Show(url);
}
}
public static string GetChromeUrl(Process process)
{
string out_url = null;
if (process == null) {
out_url = null;
} else if (process.MainWindowHandle == IntPtr.Zero) {
out_url = null;
} else {
AutomationElement element = AutomationElement.FromHandle(process.MainWindowHandle);
if (element == null)
return null;
Condition conditions = new AndCondition(
new PropertyCondition(AutomationElement.ProcessIdProperty, process.Id),
new PropertyCondition(AutomationElement.IsControlElementProperty, true),
new PropertyCondition(AutomationElement.IsContentElementProperty, true),
new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)
);
AutomationElement elementx = element.FindFirst(TreeScope.Descendants, conditions);
out_url = ((ValuePattern)elementx.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string;
}
return out_url;
}
}
}
But this is not what I want exaclty.
This code works but it still getting the URL from chrome to slow... 2 seconds or even 3 sometimes.I noticed that, when I change TreeScope.Descendant to TreeScope.Children this code is started to run lika a flash :) but return null - nothing found.
Any ideas ?

SSIS/C#: Script Task, C# script to look at directory and store the name of 1 file in a variable

Basically I've written a C# script for a Script task in SSIS that looks in a User::Directory for 1 csv, if & only if there is one file, it stores that in the instance variable which then maps to the package variables of SSIS.
When I exicute, it gives me the red filled in box of the Script task. I think it's related to how I'm looking at the directory, but I'm not sure.
Please help!
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.IO;
namespace ST_e8b4bbbddb4b4806b79f30644240db19.csproj
{
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
private String fileName = "";
private String RootDirictory;
private String FilePath;
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
public ScriptMain()
{
RootDirictory = Dts.Variables["RootDir"].Value.ToString();
FilePath = RootDirictory + "\\" + "SourceData" + "\\";
}
public void setFileName()
{
DirectoryInfo YDGetDir = new DirectoryInfo(FilePath);
FileInfo[] numberOfFiles = YDGetDir.GetFiles(".csv");
if (numberOfFiles.Length < 2)
{
fileName = numberOfFiles[0].ToString();
}
int fileNameLen = fileName.Length;
String temp = fileName.Substring(0, fileNameLen - 5);
fileName = temp;
}
public void mapStateToPackage()
{
if((fileName!=null)||(fileName!=""))
{
Dts.Variables["ExDFileName"].Value = fileName;
}
}
public void Main()
{
setFileName();
mapStateToPackage();
Dts.TaskResult = (int)ScriptResults.Success;
}
}
}
This could simply be done using Foreach loop container as explained in this Stack Overflow question, which was asked by you. :-)
Anyway, to answer your question with respect to Script Task code that you have provided. Below mentioned reasons could be cause of the issues:
You are looking for .csv. This won't return any results because you are looking for a file with no name but extension .csv. The criteria should be *.csv
If you are looking for exactly one file, then the condition if (numberOfFiles.Length < 2) should be changed to if (numberOfFiles.Length == 1)
The section of code after the if section which extracts the file name should be within the above mentioned if condition and not out side of it. This has to be done to prevent applying substring functionality on an empty string.
Modified code can be found under the Script Task Code section.
Sorry, I took the liberty to simplify the code a little. I am not suggesting this is the best way to do this functionality but this is merely an answer to the question.
Hope that helps.
Script Task Code:
C# code that can be used only in SSIS 2008 and above.
/*
Microsoft SQL Server Integration Services Script Task
Write scripts using Microsoft Visual C# 2008.
The ScriptMain is the entry point class of the script.
*/
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.IO;
namespace ST_3effcc4e812041c7a0fea69251bedc25.csproj
{
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
Variables varCollection = null;
String fileName = string.Empty;
String fileNameNoExtension = string.Empty;
String rootDirectory = string.Empty;
String filePath = string.Empty;
#region VSTA generated code
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
public void Main()
{
Dts.VariableDispenser.LockForRead("User::RootDir");
Dts.VariableDispenser.LockForWrite("User::ExDFileName");
Dts.VariableDispenser.GetVariables(ref varCollection);
rootDirectory = varCollection["User::RootDir"].Value.ToString();
filePath = rootDirectory + #"\SourceData\";
DirectoryInfo YDGetDir = new DirectoryInfo(filePath);
FileInfo[] numberOfFiles = YDGetDir.GetFiles("*.csv");
if (numberOfFiles.Length == 1)
{
fileName = numberOfFiles[0].ToString();
fileNameNoExtension = fileName.Substring(0, fileName.LastIndexOf("."));
}
if (!String.IsNullOrEmpty(fileNameNoExtension))
{
varCollection["User::ExDFileName"].Value = fileNameNoExtension;
}
Dts.TaskResult = (int)ScriptResults.Success;
}
}
}

sqlite Exception Identity Issue

I'm getting this error when the program executes mainDb.SubmitChanges():
INSERT INTO projects
VALUES (#p0)
SELECT CONVERT(Int, SCOPE_IDENTITY()) AS [value]
-- #p0: Input String (Size = 0; Prec = 0; Scale = 0) [test2]
-- Context: SqlProvider(Sql2008) Model: AttributeMetaModel Build: 3.5.30729.4926
My code has the following files:
Program.cs [this is the main program file]
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using blg.db;
namespace blg
{
class Program
{
static void Main(string[] args)
{
SQLiteConnectionStringBuilder csb = new SQLiteConnectionStringBuilder();
csb.Add("data source", "blg.sqlite");
using (SQLiteConnection connection = new SQLiteConnection(csb.ConnectionString))
{
connection.Open();
MainDb mainDb = new MainDb(connection);
mainDb.Log = Console.Out;
Project project = new Project();
project.projectName = "test2";
mainDb.projects.InsertOnSubmit(project);
mainDb.SubmitChanges();
//var query = from p in mainDb.projects
// select p;
//foreach (var row in query)
//{
// Console.WriteLine(row.projectName);
//}
Console.WriteLine(mainDb.Connection.State);
}
Console.ReadKey();
}
}
}
the other file is:
mainDb.cs [this file has the class that is inherited from DataContext]
using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Data.SQLite;
using System.Text;
namespace blg.db
{
class MainDb : DataContext
{
public Table<Project> projects;
public MainDb(SQLiteConnection connection) : base(connection) { }
}
}
the last file is
Project.cs [this is the class for mapping it to the sqlite database]:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq.Mapping;
using System.Text;
using System.Data.SQLite;
namespace blg.db
{
[Table(Name = "projects")]
class Project
{
private int _id;
private string _projectName;
private string _another;
[Column(Name = "id", Storage = "_id", DbType = "int",
IsPrimaryKey = true, IsDbGenerated = true)]
public int id
{
get {return _id;}
set {_id = value;}
}
[Column(Name = "project_name", Storage = "_projectName", DbType = "text")]
public string projectName
{
get {return _projectName;}
set {_projectName = value;}
}
}
}
the code is working well, except when it executes mainDb.SubmitChanges(); in the Program.cs, any idea?