Variable scope in SSIS config table - ssis

I'm trying to change the scope of some of my variables in my SSIS package. They rely on a config table in a database, and previously they got their values set with the following values in the database:
\Package.Variables[User::EmailAddress].Properties[Value]
And the value for that would be set in the ConfigurationValue column.
This worked like a charm, except once I changed the scope of the variable from package to a specific foreach loop container, I've gotten the following error:
Warning: The package path referenced an object that cannot be found: "\Package.Variables[User::EmailAddress].Properties[Value]". This occurs when an attempt is made to resolve a package path to an object that cannot be found.
The other, globally-scoped variables don't have this problem. Is there some value in this string that's telling SSIS to look at the package level, instead of in the entire package?

You can go one of two ways - either rebuild the DTSConfig using the wizard, or alter the path in file to include the ForEach Loop
\Package\ForEachLoopName.Variables[User::EmailAddress].Properties[Value]

Related

How to pass parameter to source command in mysql .The parameter is set before to file path

I am tring to import sql file from command prompt. where i use source command and the file path is set into one varible :
set #path='/home/xxx/Downloads/database script/adverise.sql';
source #path
And the error is
ERROR: Failed to open file '#path', error: 2
Thanks in advance
You can simply use the below command, you don't need to put the store into a variable and then use it.
source /home/xxx/Downloads/database script/adverise.sql
If you still need to store the path in a variable then store it into a variable but you can also pass the same path with "source /path/to/file" so that both scenarios will handle.

Access error when saving query

I am trying to save an Access query with the following statement.
INSERT INTO FOO( DES_MOTIVO, DES_TIPO, DES_SUBTIPO,
AGRUPACIÓN, SEMANA, CuentaDeCOD_ACCION_CLIENTE )
IN 'C:\Users\BAR\Desktop\03. Hola\DB STATIC INTERACCIONES MES.accdb'
I am getting an error when saving the query, saying the path is incorrect. Testing the path, i found out that the culprit is the period+whitespace in "03. Hola". Deleting the whitespace fixed the issue and the query saves properly.
Is there a way to escape the period so that access accepts the save path with period + whitespace?
Thank you in advance,
Nega.
Apparently this is not possible with SQL or VBA code.
Fun fact: You can do it in the query designer by setting the Destination database setting of the query properties. Set your path, the query can be saved and executed (and it works!).
But switch to SQL view and try to save: you get the "invalid bracketing" error. Same when trying to set the SQL from VBA.
And the DestinationDB property that the help file mentions isn't available via code. It seems to be derived from the IN clause.
So your database will have to moved to a better path. Or, if it's single user, copy to temp path, run the INSERT, copy back.
See also: https://support.microsoft.com/en-us/kb/132184
Try adding quotes around the path:
"INSERT INTO FOO( DES_MOTIVO, DES_TIPO, DES_SUBTIPO, AGRUPACIÓN, SEMANA, CuentaDeCOD_ACCION_CLIENTE ) IN '""C:\Users\BAR\Desktop\03. Hola\DB STATIC INTERACCIONES MES.accdb""'"
But why do you maintain such weird folder names as "03. Hola"?
Indeed on the Desktop, you should be able to create a simpler folder name.

SSIS --The expression was evaluated, but cannot be set on the property

I have package that I have been testing for the last 8 months. Today when I deployed the package on the client machine, it gave the following error:
MainContainer:Error: The result of the expression
"#[$Project::FilePath]+ #[System::PackageName]+".xml"" on property
"\Package.Properties[CheckpointFileName]" cannot be written to the
property. The expression was evaluated, but cannot be set on the
property.
#[$Project::FilePath] contains the file path. In this case the value is: C:\Verfication_Reports\
#[System::PackageName]:MainContainer
The package executes successfully but it generates the above error in the SSISDB. This property contains the path of checkpoint file. Please help.
a bit late, but anyway.
make sure the path also exists in the client's file system.

SSIS - Export multiple SQL Server tables to multiple text files

I have to move data between two SQL Server DBs. My task is to export the data as text (.dat) files, move the files and import into the destination. I have to migrate over 200 tables.
This is what I tried
1) I used a Execute SQL task to fetch my tables.
2) Used a For each loop to loop through the table names from the collection.
3) Used a script task inside the for each loop to build the text file destination path.
4) Called a DFT with the table name in a variable for the source ole db and the path name in a variable for the destination flat file.
First table extracts fine but the second table bombs with a synchronization error. I see this is numerous posts but could not find one that matches my scenario. Hence posting here.
Even if I get the package to work with multiple DFTs, the second table from the second DFT does not export columns because the flat file connection manager still remembers the first table columns. Is there a way to get it to forget the columns?
Any thoughts on how I can export multiple tables to multiple text files using one DFT using dynamic source and destination variable?
Thanks and appreciate your help.
Unfortunately Bulk Import Task only enable us to use format files effectively to map the columns between source and destinations. Bulk Import Task uses BULK INSERT TSQL command to import the data, to execute user should have the BULKADMIN server privilege.
Most of the companies would not allow BULKADMIN server privilege to enable due to security reasons.
Hence using the script task to construct BCP statements is a good and simple option to Export.
You does not require to construct .bat file as script itself can execute dos commands which runs under .NET security account.
I figured out a way to do this. I thought I will share if anybody is stuck in the same situation.
So, in summary, I needed to export and import data via files. I also wanted to use a format file if at all possible for various reasons.
What I did was
1) Construct a DFT which gets me a list of table names from the DB that I need to export. I used 'oledb' as a source and 'recordset destination' as target and stored the table names inside a object variable.
A DFT is not really necessary. You can do it any other way. Also, in our application, we store the table names in a table.
2) Add a 'For each loop container' with a 'For Each ADO Enumerator' which takes my object variable from the previous step into the collection.
3) Parse the variable one by one and construct BCP statements like below inside a Script task. Create variables as necessary. The BCP statement will be stored in a variable.
I loop through the tables and construct multiple BCP statements like this.
BCP "DBNAME.DBO.TABLENAME1" out "PATH\FILENAME2.dat" -S SERVERNAME -T -t"|" -r$\n -f "PATH\filename.fmt"
BCP "DBNAME.DBO.TABLENAME1" out "PATH\FILENAME2.dat" -S SERVERNAME -T -t"|" -r$\n -f "PATH\filename.fmt"
The statements are put inside a .bat file. This is also done inside the script task.
4) A execute process task will next execute the .BAT file. I had to do this because, I do not have the option to use the 'master..xp_cmdShell' command or the 'BULK INSERT' command in my company. If I had the option to execute cmdshell, I could have directly run the command from the package.
5) Again add a 'For each loop container' with a 'For Each ADO Enumerator' which takes my object variable from the previous step into the collection.
6) Parse the variable one by one and construct BCP statements like this inside a Script task. Create variables as necessary. The BCP statement will be stored in a variable.
I loop through the tables and construct multiple BCP statements like this.
BCP "DBNAME.DBO.TABLENAME1" in "PATH\FILENAME2.dat" -S SERVERNAME -T -t"|" -r$\n -b10000 -f "PATH\filename.fmt"
BCP "DBNAME.DBO.TABLENAME1" in "PATH\FILENAME2.dat" -S SERVERNAME -T -t"|" -r$\n -b10000 -f "PATH\filename.fmt"
The statements are put inside a .bat file. This is also done inside the script task.
The -b10000 was put so I can import in batches. Without this many of my large tables could not be copied due to less space in the tempdb.
7) Run the .bat file to import the file again.
I am not sure if this is the best solution. I still thought I will share what satisfied my requirement. If my answer is not clear, I would be happy to explain if you have any questions. We can also optimize this solution. The same can be done purely via VB Scripts but you have to write some code to do that.
I also created a package configuration file where I can change the DB name, server name, the data and format file locations dynamically.
Thanks.

SSIS The expression for variable 'Variable' failed evaluation. There was an error in the expression

So here we have an error I keep getting in my SSIS package but I can't see what is wrong with the statement. I have even tried another sql statement from a project that works and it still raises the error.
The system is VS 2005 running 64 bit debugger, on XP machine. The project has amongst other things a script task then a sql task, the script task outputs the month value to a variable (Dts.Variables("monthName").Value = month), which I then use to create dynamic table name in SQL statement. I haven't got to the excel sheet bit yet as I am trying to get the sql task stage working.
So i have a variable at package level called SQLTableCreate, and in that I have the properties set to:
Evaluate as Expression = true
Expression = "Create Table "+ #[user::monthName]+"(Column1 DATETIME,Column2 NVARCHAR(255),Column3 NVARCHAR(255),Column4 NVARCHAR(255),Column5 NVARCHAR(255),Column6 NVARCHAR(255),Column7 NVARCHAR(255),Column8 NVARCHAR(255),Column9 NVARCHAR(255),Column10 NVARCHAR(255))"
And when I build the package I get:
Nonfatal errors occurred while saving the package:
Error at Package: The variable "user::monthName" was not found in the Variables collection. The variable might not exist in the correct scope.
Error at Package: Attempt to parse the expression ""Create Table "+ #[user::MonthName]+"(Column1 DATETIME,Column2 NVARCHAR(255),Column3 NVARCHAR(255),Column4 NVARCHAR(255),Column5 NVARCHAR(255),Column6 NVARCHAR(255),Column7 NVARCHAR(255),Column8 NVARCHAR(255),Column9 NVARCHAR(255),Column10 NVARCHAR(255))"
" failed and returned error code 0xC00470A6. The expression cannot be parsed. It might contain invalid elements or it might not be well-formed. There may also be an out-of-memory error.Error at Package: The expression for variable "SQLTableCreate" failed evaluation. There was an error in the expression.
There is also a default SQL statement for the variable SQLTableCreate, which uses the current excel connection manager table name. When I put my dynamic statement in the expression section of properties it fills the value and valuetype property of the SQLTableCreate variable with the message:
The expression for variable "SQLTableCreate" failed evaluation. There was an error in the expression.
It's exactly as the error says
The variable "user::monthName" was not found in the Variables collection
Things in SSIS are case sensitive and Variables are one of those things. Make your expression
"Create Table "+ #[User::monthName]+"(Column1 DATETIME,Column2 NVARCHAR(255),Column3 NVARCHAR(255),Column4 NVARCHAR(255),Column5 NVARCHAR(255),Column6 NVARCHAR(255),Column7 NVARCHAR(255),Column8 NVARCHAR(255),Column9 NVARCHAR(255),Column10 NVARCHAR(255))"
Also, I hope this table design is just a sample and not real. Lack of column names and strong data types is technical debt you don't need to incur at this stage.