Alpha Video Training
Results 1 to 9 of 9

Thread: Set connection string from argument

  1. #1
    VAR
    Real Name
    Bill Parker
    Join Date
    Apr 2000
    Location
    Dallas, TX
    Posts
    1,699

    Default Set connection string from argument

    I don't think I can use the multi-tenant dynamic connection string since it uses a session variable. Can a connection string in a list control be set to the value of an argument?

    I will have both multiple databases for tenant type and multiple tenants per database. A user may be in multiple databases. At login they will pick which database to view from their available options and go directly to a master UX. I plan to set a session variable just long enough to launch the master UX and set an argument. This is because it is possible they might launch another browser tab and login to a second database.

    Bill.

  2. #2
    Moderator Steve Workings's Avatar
    Real Name
    Steve Workings
    Join Date
    Apr 2000
    Location
    The Dreaded Chair
    Posts
    5,595

    Default Re: Set connection string from argument

    Bill - a session variable is tied to the browser instance. A browser - whether you have one or two tabs, uses the same session on the server. Are you suggesting a user can have two different logins to two different databases/applications in one browser?
    -Steve


  3. #3
    VAR
    Real Name
    Bill Parker
    Join Date
    Apr 2000
    Location
    Dallas, TX
    Posts
    1,699

    Default Re: Set connection string from argument

    Yes, only one session per browser is the problem. I don't mind using session variable for quick temporary use in order to set argument, which will then stay "stuck" to that UX while it exists.

    Then if a user happens to login again and open a second database, the session var will be reset, and argument created for the master UX on the additional browser tab. The two arguments should be independent.

    Bill.

  4. #4
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,567

    Default Re: Set connection string from argument

    Bill... you'd have to test this, but you could use an Argument in the myConnection.MultiTenant XBasic Class.

    In the function named "query"... args are passed in. One of those arguments could be your Argument. You'd need to extract your argument from args and then modify the class a bit.

    In the class... _tenantId is set to the session variable. Instead, set it to your argument.

    You must be careful about the XBasic code in this created class. There are 2 options for Tenant ID field type... Numeric and Character. If Alpha tested Character, they never tested is fully. If your List SQL statement includes a WHERE clause... and your Tenant ID field type is Character, your SQL Statement will blow up. This is because Alpha is not taking care of _tenantdId in this scenario.

  5. #5
    VAR
    Real Name
    Bill Parker
    Join Date
    Apr 2000
    Location
    Dallas, TX
    Posts
    1,699

    Default Re: Set connection string from argument

    That gives me something to start looking at. However, my tenant id is a guid, which in sql server is binary? The lists setup will probably not have additional Where, but the user will certainly add runtime filters. Could I override the filtering at runtime and not use the built in tenant id? This would also let me have a "super user" that can see all records.

    Bill.

  6. #6
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,567

    Default Re: Set connection string from argument

    I guess it depends where you get your guid from. Some are strings. If you're using the AlphaDAO Connection String Multi-Tenant setup then, by default, the tenantid is added to the SQL Select within the class xbasic.

    No reason why you can't client-side filter at runtime.

  7. #7
    VAR Pat Bremkamp's Avatar
    Real Name
    Pat Bremkamp
    Join Date
    Apr 2000
    Location
    Oregon, USA
    Posts
    2,595

    Default Re: Set connection string from argument

    Bill, here's one way you can do it, but it is limited. If you have multiple instances of the WAS, then in the configuration you can set separate sessions, and the session variables in one will not conflict with the session variables in the others. The limit, of course, is if you have enough instances for one per database. In this case, the user logs in to separate instances.
    Pat Bremkamp
    MindKicks Consulting

  8. #8
    Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,827

    Default Re: Set connection string from argument

    You could build the values (JSON or CRLF) for your List component in the server-side OnDialogInit event (or maybe OnExecute) or an xbasic callback, and then push those to the List, which would be set to Custom rather than SQL.​
    Steve Wood
    Join the ALPHA DEVELOPERS NETWORK
    There is no Cloud. It's just someone else's computer.
    Web - Mobile - Hosting - Products - Frameworks - Developer Resources
    AlphaToGo | IADN (100% Alpha Anywhere Websites)

  9. #9
    Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,827

    Default Re: Set connection string from argument

    Here is some pseudocode xbasic that would 1) select the correct connection string, 2) populate the list

    function getListnames as c (e as p)

    dim db as c

    ' set db to the correct database based on login or other settings

    something = 1 'debug value

    select
    case something = 1
    db = "mydatabase_1" ' test example
    case something = 2
    db = "mydatabase_2" ' test example

    'etc, including error trapping

    end select

    dim lst as c

    dim cn as sql::Connection
    dim args as sql::Arguments
    dim rs as sql::ResultSet

    conn = "::name::" + db ' e.g., "::name::db1"

    cn.open(conn) ' opens the correct database

    vsql = <<%txt%
    SELECT top 100
    id,
    name,
    address
    %txt%
    cn.execute(vsql,args)

    rs = cn.ResultSet
    lst = rs.tostring(-1,-1,.t.,"|")
    cn.close()

    'lst will contain crlf delimited list of values from database

    lst = "field1|field2|field3" + crlf() + lst

    getListnames = lst

    end function
    Steve Wood
    Join the ALPHA DEVELOPERS NETWORK
    There is no Cloud. It's just someone else's computer.
    Web - Mobile - Hosting - Products - Frameworks - Developer Resources
    AlphaToGo | IADN (100% Alpha Anywhere Websites)

Similar Threads

  1. Set textbox default value to query string argument
    By Jane1234 in forum Mobile & Browser Applications
    Replies: 1
    Last Post: 06-05-2015, 09:57 AM
  2. publish grid w/ different connection string from Project Named AlphaDAO connection
    By KYBiggs in forum Application Server Version 10 - Web/Browser Applications
    Replies: 4
    Last Post: 01-22-2012, 12:40 PM
  3. string?Connection String Explanation
    By Turnbullca in forum Application Server Version 11 - Web/Browser Applications
    Replies: 2
    Last Post: 11-06-2011, 02:33 PM
  4. Error converting named connection to connection string
    By michaelxcampbell in forum Application Server Version 10 - Web/Browser Applications
    Replies: 2
    Last Post: 09-21-2011, 02:38 PM
  5. Use of query string as argument in filter
    By FrankR in forum Application Server Version 9 - Web/Browser Applications
    Replies: 7
    Last Post: 04-09-2009, 05:01 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •