simple way to change the connection at run time??

4 posts, 0 answers
  1. Carlos G Ortiz
    Carlos G Ortiz avatar
    1 posts
    Member since:
    Aug 2009

    Posted 04 Oct 2009 Link to this post

    there any property to change the connection string???
    From what I see in your documentation sought more complicated and inefficient way of doing this.
    Besides the fact that I failed to change the connection to a server in production
     Everything is fine if you play with a fixed connection
    but in the real world in products ranging to final consumers
    normally do not have the slightest idea of the server name.
    in most cases neither the name of the BD,user or password only tables index keys  are generated by scripts ..

    It is illogical to think that these data are not changed by parameters within the program, you can not compile one application for each customer of  the same product.

     30 days ago about, the ORM was acquired at the suggestion of a programmer
    do some consulting all fine until I asked him to connect to another server with another user etc.
       perhaps neither he nor I understand the product , and I guess not understand 
    until we can dynamically connect to the server we choose by parameters.
    20 days and are trying to do this that would linqtosql matter of 30 seconds really do not understand.
    Any help will be appreciated
    best regards

  2. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 07 Oct 2009 Link to this post

    Hello Carlos G Ortiz,

    You can replace the connection string that is loaded from the app.config file during runtime with some custom XML of yours. Here is an example:
    string myDatabase = "Northwind"
    string serverName = "(LOCAL)\SQLEXPRESS"
    string myuser = "user"
    string mypassword = "pass"
    const string myconfig =  
            "<openaccess>"
                "<references>"
                    "<reference assemblyname='ClassLibrary1' />"
                "</references>"
                "<connections>"
                    "<connection id='DatabaseConnection1'>"
                            "<databasename>"+myDatabase+"</databasename>"
                        "<servername>"+serverName+"</servername>"
                        "<user>"+myuser+"</user>"
                        "<password>"+mypassword+"</password>"
                        "<backendconfigurationname>mssqlConfiguration</backendconfigurationname>"
                    "</connection>"
                "</connections>"
                "<backendconfigurations>"
                    "<backendconfiguration id='mssqlConfiguration' backend='mssql'>"
                        "<mappingname>mssqlMapping</mappingname>"+                       
                    "</backendconfiguration>"
                "</backendconfigurations>"
                "<mappings current='mssqlMapping'>"
                    "<mapping id='mssqlMapping' />"
                "</mappings>"
            "</openaccess>";     
    XmlDocument xmlDoc = new XmlDocument(); 
    xmlDoc.LoadXml(myconfig); 
    Database db = Database.Get("DatabaseConnection1", xmlDoc.DocumentElement); 
    Additional information can be found here.

    All the best,
    Petar
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
  4. Mark Reynolds
    Mark Reynolds avatar
    2 posts
    Member since:
    May 2010

    Posted 06 Sep 2013 Link to this post

    The additional information link is a dead link.
  5. Doroteya
    Admin
    Doroteya avatar
    502 posts

    Posted 09 Sep 2013 Link to this post

    Hello Mark,

    Excuse us for the inconvenience caused.

    Generally, the article you are looking for was deprecated.

    Perhaps you could share a little bit more information about the scenario you need to implement and the setup on your machine and we could suggest to you relevant resources.

    Additionally, here is the latest OpenAccess ORM documentation.

    I am looking forward to your feedback.


    Regards,
    Doroteya
    Telerik
    OpenAccess ORM Q2 2013 brings you a more powerful code generation and a unique Bulk Operations support with LINQ syntax. Check out the list of new functionality and improvements shipped with this release.
Back to Top