title: How to use session.contents as a variable in ASP SQLDataSource Visual Studio 2017
body: <p>I am using Visual Studio 2017 to build an ASP.NET website (using VB) and have set up a few different connection strings in my web config file for different user types (i.e. basic access, admin access, etc.). Each connection type has access to different rights as well as different schemas in the DB. I'm trying to call these different connections via a session contents variable that is generated at the time of a successful login (on the login page) and then used in other pages on the site.</p>
  
  <p>This is an example of the ASP connection string used on one of the other pages:</p>
  
  <pre><code> &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ 
  ConnectionStrings:DBSource1 %&gt;" SelectCommand="Stored_Proc" 
  SelectCommandType="StoredProcedure"&gt;&lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>Here's the part where I would like to call via session contents to use as a variable in the SQLDataSource:</p>
  
  <pre><code> ConnectionString="&lt;%$ ConnectionStrings:DBSource1 %&gt;"
  </code></pre>
  
  <p>Here's the Session content code I'd like to use as a variable:</p>
  
  <pre><code>Session("SqlConstrName").ToString()
  </code></pre>
  
  <p>I am able to put the session content into a text box in the ASP code and it gives the connection name as it's shown above </p>
  
  <pre><code>ConnectionStrings:DBSource1
  </code></pre>
  
  <p>I have done some research and know that I cannot use &lt;%= % for server side controls and have been unsuccessful using &lt;%# %, "&lt;%# %", or any other combination type to pass the variable through. I have also tried to bind just the name part and exclude the "ConnectionStrings:" part, but was still unsuccessful.</p>
  
  <p>I know that I can easily create a connection string in my VB code and then bind the data to the objects, but I am attempting to do this on the ASPX side so that my drop-downs, grid-views, etc. stay bound which lowers the amount of VB code needed on the backend and allows me to have more dynamic tables that link between other items on the page without having to write a bunch of on change events. Any suggestions or thoughts is greatly appreciated, thanks!</p>