Chaning DataBase connection at runtime

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
drysg
Posts: 28
Joined: Fri 09 Mar 2012 15:10

Chaning DataBase connection at runtime

Post by drysg » Tue 29 May 2012 20:40

I can easily use LinqConnect at Design time to set a fixed connection string. But some of our users will need to change the port and login information at runtime.

This is no problem with ADO connections (see below) but how does one do this with LinqConnect where the only handle on has is the context that one created from the model

DBmodel context = new namespace.DBmodel();


ADO version:

Code: Select all

Devart.Common.DbConnectionStringBuilder csb = new Devart.Common.DbConnectionStringBuilder();
            csb["Host"] = "localhost";
            csb["Port"] = 5432;
            csb["User Id"] = "postgres";
            csb["Password"] = "*******";
            csb["Database"] = "GPL";
            csb["Max Pool Size"] = 150;
            csb["Connection Timeout"] = 30;
            PgSqlConnection conn = new PgSqlConnection(csb.ConnectionString);

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Chaning DataBase connection at runtime

Post by MariiaI » Wed 30 May 2012 13:30

The DataContext class has several overloads of the constructor, in particular, one taking the connection string.
For example:

Code: Select all

string connectionString = "User Id=user;Password=password;Host=host;Port=5432;Database=databasename;Persist Security Info=True";
PostgresDataContext dc = new PostgresDataContext(connectionString);

Post Reply