2

https://github.com/linq2db/linq2db I need to use different connection strings and can't find how to make it.

reptile
  • 175
  • 1
  • 9
Anton Pavelyev
  • 469
  • 4
  • 20

3 Answers3

3

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.

Rafa Viotti
  • 9,998
  • 4
  • 42
  • 62
Anton Pavelyev
  • 469
  • 4
  • 20
2

You can use DataConnection.AddConfiguration(...) and DataConnection.SetConnectionString(...) to add new or change existing connection strings in linq2db.

0

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>

IndieTech Solutions
  • 2,527
  • 1
  • 21
  • 36