I need to set the connection string somewhere in one place in SSRS project in order to use it in Data Sources across all the reports. As SSRS doesn't support project params it's recommended to create Shared DataSet instead, e. g. HostParam.rds
SELECT 'localhost' AS GlobalParameter
The question is how to access it further in expression in Data Source connection string
="Data Source=" + HostParam.GlobalParameter + ";Initial Catalog=xxx"
gives an error 'HostParam' is not declared
You can setup a shared datasource at the project level, this contains just the connection to the database.
You then select this shared datasource when creating datasets (this works for both shared datasets or embedded datasets).
If you change the connection in the shared data source, this is reflected in all the datasets and therefore reports that reference it.
Related
There are 4 Connection strings with different SQL Servers (which I set up in SSIS Connection Managers section):
Database name is same in all the servers:
SERVER DATABASE
dbTestServer dbFees (Main Server and Database)
dbTestServer1 dbFees1
dbTestServer2 dbFees1
dbTestServer3 dbFees1
dbTestServer is the OLEDB Source and other Servers are OLEDB Destination that needs to be updated everytime we run package.
Now, I want to take data from dbTestServer-dbFees and copy to all the other databases. I created a Dataflow task to copy data from dbTestServer to dbTestServer1.
But I need to put this data flow task inside ForEach Loop container to change the connection/Server dynamically so that it will work like:
First run- By default OLEDB Source is set to dbTestServer and OLEDB Destination is set to dbServer1 and data is copied from dbFees to dbFees1.
Second run- OLEDB Source is set to dbTestServer and OLEDB Destination is set to dbServer2 and data is copied from dbFees to dbFees1
Third run- OLEDB Source is set to dbTestServer and OLEDB Destination is set to dbServer3 and data is copied from dbFees to dbFees1.
I need step by step solution as I am new to SSIS packages and I tried multiple solutions but NOTHING worked so far!
Appreciate your help!
Thank you
I suggest using FOR LOOP.
My logic is to increment variable on each loop and create an expression with a connection string and a number of iteration.
1st step is to create Connection Manager with server name dbTestServer1 and database name dbFees1
2nd step will be to add a connection manager to OLE DB Destination
3rd step is to create 2 variables: ConnString and Iteration.
For Iteration default value set to 1, because you need dbTestServer 1
ConnString you need to set like your initial connection string, just on place 1 in dbTestServer1 to set (DT_STR, 1, 65001)#[User::Iteration].
Like on next 2 pictures:
When you set variables, you need to set expression in OLE DB Connection Manager.
From drop-down select connection string and type #[User::ConnString].
And finally set FOR LOOP like on picture
NOTE: I can't test package because I don't have server names like you, but this is logic of how to solve your problem. And this is only solution for what you asked, you must create whole package on your own.
For main server and database, just add one OLE DB Source with static names for server name and database name.
And you don't need script task if you using my logic.
Here is the code I have used to dynamically change connection server/database inside C# Script task in SSIS:
Variables I pass to the C# Script task under ReadOnlyVariables:
(set these up in your Variables inside SSIS)
User::DatabaseListOnThisLoop_ConnectionString
User::DatabaseListOnThisLoop_DatabaseName
This is the name of the connection string I am dynamically change that is in my ConnectionMangers in SSIS:
SourceServerDBForClassification_Dynamic
FULL SCRIPT from my C# Script task inside SSIS. As long as you setup the variables and put the 2 in above in the ReadOnly section of the script task, you should be able to just copy/paste the entire code below into your C# Script task.
NOTE: The Namespace may give you an issue so may want to keep the one that is generated in your code when adding the script task.
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms; // dont think this is needed, I used this for message box for some testing, but leaving here just in case
namespace ST_f8d6dad17af541bbb0010c9fce3ccbb0
{
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
public void Main()
{
// get connection string from variable
string ServerConnectionStringOnThisLoop = Dts.Variables["DatabaseListOnThisLoop_ConnectionString"].Value.ToString();
string DatabaseOnThisLoop = Dts.Variables["DatabaseListOnThisLoop_DatabaseName"].Value.ToString();
// this could change depend on what type of connection you are using for provider and other settings
string DynamicConnectionString = "Data Source=" + ServerConnectionStringOnThisLoop + ";Initial Catalog=" + DatabaseOnThisLoop + ";Provider=SQLNCLI11.1;Integrated Security=SSPI;";
// Add the OLE DB connection manager set to existing connection
ConnectionManager SourceServerDBForClassification_Dynamic = Dts.Connections["SourceServerDBForClassification_Dynamic"];
// now set the dynamic connection above to the connection string passed in from SSIS package
SourceServerDBForClassification_Dynamic.ConnectionString = DynamicConnectionString;
// now set the package connection to the one we just created from using the variable from the SSIS package
Dts.Connections["SourceServerDBForClassification_Dynamic"].ConnectionString = SourceServerDBForClassification_Dynamic.ConnectionString;
Dts.TaskResult = (int)ScriptResults.Success;
}
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
}
}
how to create ssrs report that shows database names as a dropdown filter and user can select the database name and connect dynamically and run the report.
The Server name is same, just the databases must by dynamic.
Please let me know.
You need to create a datasource in your report, this will not work on a shared datasource.
Create a new datasource and then next to the connection string field, click the fx button. You can build your connection string using parameter values to change the database. The expression might look something like this..
="Data Source=MyServerName;Initial Catalog=" & Parameters!myDatabaseParameter.Value & ";Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
I am using SSRS reports and now I want to change data-source base on parameter. I had all ready tried to create a dynamic data source base on parameter and it works perfect on our local environment. But on production we are not able connect database due to security issue.
To overcome the security issue. we had created two data source "ProdDB" and "ArchDB" in reporting server and map with my report's data source
Now I want to know how we can Switch data source base on parameter like
Report parameter #dbsource = "Prod"
if #dbsource.value = "Prod" then
datasource = "ProdDB
Else
DataSource = "ArchDB"
Here is what you can do
Create two report parameters as databaseName and DatabaseServer
in datasource-> properties -> connection String -> expression write a connection string as below
="Data Source=" + Parameters!databaseServer.Value + ";Initial Catalog=" + Parameters!databaseName.Value
This will ask database name and database server as a report parameters, if you are running the report as data driven subscriptions you can pass these parameters dynamically from a query or static subscription parameters.
I want to use the same Reports(.rdl) to generate the reports for 24 databases.
For instance if there is a user table in my reports(.rdl), then the datasource for the report(.rdl) should change dynamically. Now, I'm making 24 different Reports for 24 databases.
I want a single report(.rdl) with the datasource changed at the runtime.
The way to achieve this could be adding 3 parameters to your report (.rdl) file
ServerName
DatabaseName
and if required
Password
Then change the connection string for the datasource like
="data source=" & Parameters!ServerName.Value & ";initial catalog=" & Parameters!DatabaseName.Value
Only small issue with this approach is the paramnames are visible in the URI so caveat emptor
I found an alternative solution to my problem. I created a single (.rdl) Report file which used the user which had a right in all the databases gave the datasource as this user, and the database as in which I made single procedure in a database, suppose admin database(used for all procedure which are common to all), In that procedure I executed the procedure which is present in other databases like this:
set #sSql='Execute '+ #databasename + '.'+ #username + '.'+'GetData'
EXEC (#sSql)
where username and Databasename are present in the table(for all database) and a column name sentDate which is update to todays date after executing the procedure for that databaseName, so that the datasource moves to next after username and databasename after executing the procedure. And made the subscription to run after 10 min, so that it can send the reports of all databases, by getting data form different database in each execution.
How to enumerate MS Access reports in windows dot net application.
I have a listbox that should show the available reports in a MS Access db. Tried following code, but it did not show anything.
oAccess = GetAccessDBObject(DBLocation);
Reports accessReports = oAccess.Reports; // oAccess.Reports.Count = 0!!! No data comes out here!!!
How do I iterate ms-access reports in .net?
I tried this example in C# and it works:
Access.Application oAccess = new Access.Application();
oAccess.OpenCurrentDatabase(#"D:\tmp\dbtest.mdb", false, "");
Access.AllObjects reports = oAccess.CurrentProject.AllReports;
Console.WriteLine(reports.Count);
foreach (Access.AccessObject report in reports)
{
Console.WriteLine(report.Name);
}
(you have to add a reference to Microsoft Access Object Library to your project, of course.)
As Tony Toews mentions, if Access is not installed, you can't automate. This SQL will work on any system:
SELECT MSysObjects.Name
FROM MSysObjects
WHERE (((MSysObjects.Type)=-32764))
ORDER BY MSysObjects.Name;
However, note that permissions can get in the way of accessing the Jet/ACE system tables.
Also, there's not much you can do with a list of Access reports without Access! But I thought it was good for completeness to mention this.
foreach ( Reports rprt in oAccess.Reports )
{
listbox.items.Add(rprt);
}
// Disclaimer: Wrote it off the top of my head, don't know if a Reports object has a name property to show it's name in your listbox.