locked
How to Change a Connectstring in runtime? RRS feed

  • Question

  • I want to change a Connectstring in runtime in runtime. Is this possible? How?

    I have a LS application with a OTAP scenatio. So I want to select the Server at runtime.

    Friday, May 25, 2012 2:55 PM

Answers

  • You can't change the connection string at runtime.

    You can, however, create a custom RIA Service that will dynamically query different data sources depending on the logged in user. The RIA Service would expose the data using schema that is consistent across the data sources or in which the data sources can be projected into that schema. Then LightSwitch would consume that RIA Service as the data source for the application.


    Justin Anderson, LightSwitch Development Team

    Wednesday, June 6, 2012 5:47 AM
    Moderator

All replies

  • Hi

    Exactly i don't know for what you want to change the connection string dynamically. But this thread may help you...

    Regards


    Rashmi Ranjan Panigrahi

    Friday, May 25, 2012 4:21 PM
  • Thanks Rashme, but What i like to do is overwrite or change the server in the web.config file of the application to switch from a test to a production database.

    Friday, May 25, 2012 7:55 PM
  • You should be doing that in the Publish Wizard on the Other Connections page.

    Justin Anderson, LightSwitch Development Team

    Friday, May 25, 2012 10:42 PM
    Moderator
  • Thanks Justen for your response. I know that you can specify other connection during Publishing.
    But I need to change servers during Runtime after Login!

    Wednesday, May 30, 2012 9:21 AM
  • Can you explain why you want to do this? Perhaps there is another way to achieve what you want.


    Simon Jones
    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, please remember to "Mark as Answer". This will help other people find answers to their problems more quickly.

    Wednesday, May 30, 2012 9:35 AM
  • Hi,

    I have the same requirement and here's why.  We host data for our clients and would like to expose a UI with lightswitch.  We have several databases with exact same schema.  Once user is logged in, the app needs to change conn string to point to respective db based on user.

    How do you change a connection at runtime?

    Thanks in advance,

    Josh

    Tuesday, June 5, 2012 2:01 PM
  • I think I'd publish the application once for each client to separate addresses.

    Simon Jones
    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, please remember to "Mark as Answer". This will help other people find answers to their problems more quickly.

    Wednesday, June 6, 2012 5:40 AM
  • You can't change the connection string at runtime.

    You can, however, create a custom RIA Service that will dynamically query different data sources depending on the logged in user. The RIA Service would expose the data using schema that is consistent across the data sources or in which the data sources can be projected into that schema. Then LightSwitch would consume that RIA Service as the data source for the application.


    Justin Anderson, LightSwitch Development Team

    Wednesday, June 6, 2012 5:47 AM
    Moderator
  • Hi Justin,

    Could you please expand on this idea just for me to understand this a little more ... 

    Although I haven't yet used LS v2, I can think of solving this issue via OData instead of Ria. 

    I have a client that have three stores. Each one has its one database, which are identical among themselves. I'm thinking about making an application that allows to view/change those three databases using a centralized approach. 

    However, a mechanism should be implemented in the "central" LS app that allows the user to choose the store to work with. Then, the OData address should be changed in the app to be able to point the processes in that direction. 

    Of course, in each store there'd be a LS app (v2) that exposes its database via OData. 

    So, my question is: Can you change that OData adrees dynamically to allow the central LS (v2) app to "see" each different database upon user request? Or, better, is all this scheme possible altogether? 

    Many thanks in advance for your comments and bye ... 

    Thursday, June 7, 2012 1:29 PM