1. Simone Olianti
  2. SnapObjects
  3. Monday, 23 September 2019 19:23 PM UTC

Hi there, i wonder if there is a way to pass the connection string which is written in the "appsettings.json" of a web api as an argument during a call from a PB app (i.e. maybe inside the url of a restclient call).

For example i have two ASA connection strings configured like this:

  "Logging": {
    "LogLevel": {
      "Default": "Warning"
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "start2": "Dsn=start2;uid=dba;pwd=sql",
    "s2": "Dsn=s2;uid=dba;pwd=sql"

in the Startup.cs i've configured the DataContext like this:
// Note: Replace "ContextName" with the configured context name; replace "key" with the database connection name that exists in appsettings.json. The sample code is as follows:
services.AddDataContext(m => m.UseOdbc(Configuration["ConnectionStrings:start2"]));

what i would like to do is to use "start2" or "s2" connection strings dynamically according to some arguments passed

inv_RestClient.sendgetrequest("http://xxx.xxx.xxx.xxx:82/api/dayfat/retrievedsdata?dataoggi=2019-03-29", ls_response)



Accepted Answer
Michael Kramer Accepted Answer Pending Moderation
  1. Monday, 23 September 2019 22:32 PM UTC
  2. SnapObjects
  3. # Permalink

Hi Simone,

It is certainly possible but it is complex for several reasons:

1. Security - Sending technical details in query-strings is an attack surface you have to protect.

2. Performance - Server apps typically handle many, many requests from many, many users. Server app therefore reuses existing DB connections to avoid spending time waiting for CONNECT/DISCONNECT for every call.

So you need to keep individual DbContext object connected to just one database as much as possible.

3. ASP.NET's "IOC container" - the dependency injection of ASP.NET MVC is great feature and so easy to use - until things get more complicated. And doing what you want requires more than basic "service registration".

My immediate thought is you need a separate service descriptor for each DB connection your app needs - and then send enough data over the wire to allow server app to request the right service descriptor.

HTH /Michael

  1. Logan Liu @Appeon
  2. Tuesday, 24 September 2019 00:38 AM UTC
Hi Simon,

This is also a similar topic for your reference:



  1. Helpful
  1. Simone Olianti
  2. Tuesday, 24 September 2019 06:41 AM UTC
Got it! thank you Michael and Logan
  1. Helpful
There are no comments made yet.

There are replies in this question but you are not allowed to view the replies from this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.