Skip to main content
Announcements
Meet the 2024 Qlik Luminaries and Partner Ambassadors! READ ON!
cancel
Showing results for 
Search instead for 
Did you mean: 
iahamedabdullah
Partner - Contributor II
Partner - Contributor II

Dynamically Changing "Data Connections" based on "Streams"

Hi Everyone,

Is there an option to Dynamically change data source in Qlik sense? 

For example, I have three streams(DEV, UAT, PROD ) and I need to connect to three different data sources(DEV, UAT, PROD),

Is there a way like I should not change the connection string but it should pick up the data source dynamically when I deploy in respective streams(DEV, UAT, PROD)? Can you please reply. Thanks in advance!

Thank you,

Ahamed

5 Replies
chadwatson
Contributor III
Contributor III

Hi Ahamed, did you figure out a way to do this? I am am looking to do the same thing.

Demlet
Contributor III
Contributor III

Hi Ahamed,

I personally haven't tried anything regarding this, but the first thing comes to mind is an IF ELSE statement using a source-path that would be included in the script. Then when you "deploy" to a stream the files would change locations/paths. Therefore the script would automatically account for it.

A few functions that come to mind to get a path...

-GetFolderPath

-DirList

-FileList

-DocumentName

-DocumentPath

-DocumentTitle

Please let me know if you end up finding a viable solution. If I end up finding time to test this I will reply back.

-Derek

iahamedabdullah
Partner - Contributor II
Partner - Contributor II
Author

Hi Derek,

If the Source is file system, then we can apply IF ELSE and use the functions which you mentioned.

-GetFolderPath

-DirList

-FileList

-DocumentName

-DocumentPath

-DocumentTitle

what if we are using OLEDB conection to connect to SQL server?

the ideal solution for this would be, We need some qlik function to identify the stream Name, that way we can apply IF ELSE and swap the connections.

thanks.

kaanerisen
Creator III
Creator III

Hi,

First of all you need to create 4 data connection. DEV, UAT, PROD and POSTGRE_QSR(qlik sense database). We need QSR connection to fetch the stream name of the app.


Untitled.png


let appId = DocumentName();

LIB CONNECT TO 'POSTGRE_QSR';

Temp_App_Stream:

load

ID as AppID,

    Name as StreamName;

SELECT app."ID",str."Name"

FROM public."Apps" app

left join public."Streams" str on app."Stream_ID"=str."ID"

where app."ID"='$(appId)';      

   

let DataSourceName = peek('StreamName');

DROP TABLE Temp_App_Stream;

LIB CONNECT TO '$(DataSourceName)';

If you get the logic, you are able to modify this script based on your needs.

Hope it helps.

hewemel1
Partner - Contributor II
Partner - Contributor II

Thanks for this solution. I plan to use it for the same problem the OP has described.

Does it bring a security issue in your opinion? And if yes, how could this be handled?

(In my environment, many apps with several developers would profit from using this mechanism in their scripts: Based on the stream, folder connections for include commands and for QVD data read/write could be switched when an app goes from a DEV stream to a PROD stream. But then, the qliksense service user need to have access to the repository db connection. Using this, any developer can fully read the repository, after its app has been published... We have just started the migration from QlikView to Qlik Sense. So, my knowledge is still very limited. Please excuse if my question does not make sense...)