This is a migrated thread and some comments may be shown as answers.

simple way to change the connection at run time??

3 Answers 101 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Carlos G Ortiz
Top achievements
Rank 1
Carlos G Ortiz asked on 04 Oct 2009, 09:37 AM
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

3 Answers, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 07 Oct 2009, 09:09 AM
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.
0
Mark Reynolds
Top achievements
Rank 2
answered on 06 Sep 2013, 01:30 PM
The additional information link is a dead link.
0
Doroteya
Telerik team
answered on 09 Sep 2013, 08:26 AM
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.
Tags
General Discussions
Asked by
Carlos G Ortiz
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Mark Reynolds
Top achievements
Rank 2
Doroteya
Telerik team
Share this question
or