https://github.com/linq2db/linq2db I need to use different connection strings and can't find how to make it.
3 Answers
I found a solution. It's not very nice. (I use firebird
):
public FirebirdDatabaseContext(IDataProvider provider, string connectionString):base(provider, connectionString){}
Used an overload with IDataProvider
. When creating a FirebirdDatabaseContext
need to directly pass new FirebirdDataProvider()
as first argument, and a connection string as second.

- 9,998
- 4
- 42
- 62

- 469
- 4
- 20
You can use DataConnection.AddConfiguration(...)
and DataConnection.SetConnectionString(...)
to add new or change existing connection strings in linq2db.
You can provide different connection strings as long as you gave them different names:
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=yourdatabasesource;User ID=User;Password=Yourpassword" />
<add name="Northwind"
connectionString = "Server=.\;Database=Northwind;Trusted_Connection=True;Enlist=False;"
providerName = "SqlServer" />
</connectionStrings>
EDIT 1:
Another way to do it , is to create an external config file and reference it in your web.config
.
In your solution , add a new config file and create all of your connection strings (This file should have only the connection string syntax and nothing else):
<connectionStrings> Conenction name 1 Connection name 2 ...... </connectionStrings>
In your web.config reference to this config file :
<connectionStrings configSource="Youconfigfilename.config"></connectionStrings>

- 2,527
- 1
- 21
- 36
-
1I don't want to place over 200 connection string in config, because they differ only by ID. – Anton Pavelyev Apr 09 '15 at 14:19
-
You can create a config file , where you can store all of your connection strings and reference it once in your web.config Check my edits – IndieTech Solutions Apr 09 '15 at 14:28