Flo s
Flo s

Reputation: 51

linq2db with 2 different Databases to migrate a database

I want to migrate a database from Firebird to MSSQL using linq2db in C#.

I thought I could load the structure using T4 Models from Firebird and then create the tables and BulkCopy the the data to MSSQL.

So far so good, but it is copying data back to Firebird instead of to MSSQL

here is my app.config:

<connectionStrings>
    <add name="Firebird__" connectionString="Data Source=localhost;Initial Catalog=MyDatabase;User Id=xxx;Password=yyy" providerName="Firebird" />
    <add name="MSSQL__" connectionString="Data Source=192.168.1.x,12345;Initial Catalog=myOtherDatabase;User Id=yyy;Password=xxx" providerName="MSSQL" />
  </connectionStrings>
  <system.data>
        <DbProviderFactories>
            <remove invariant="FirebirdSql.Data.FirebirdClient" />
            <add name="FirebirdClient Data Provider" invariant="FirebirdSql.Data.FirebirdClient" description=".NET Framework Data Provider for Firebird" type="FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient" />
        </DbProviderFactories>
    </system.data></configuration>

Then in my program I'm using this:

using (var db = new FirebirdDB())
        {
        var employeeQuery =
              from m in db.employee
              orderby m.NAME
              select m;

            liste = employeeQuery.ToList();
        }
      //using (var db_MSSQL = new MSSQL())
        using (var db_MSSQL = new FirebirdDB("MSSQL__")) 
        {
            db_MSSQL.CreateTable<MSSQL_.MA_DATEN_NAME>();
            //db_MSSQL.BulkCopy(liste);

I read the last using statement here (How to use more than one SQLite databases using LinqToDB)

always the same problem, program uses the firebird connection and not the mssql. any ideas?

Upvotes: 1

Views: 1489

Answers (1)

Flo s
Flo s

Reputation: 51

now I found the answer, thanks Arioch!

App.config

the providerName is obviously very important and I needed "SqlServer.2012"

<connectionStrings>
<add name="Firebird__" connectionString="Data Source=localhost;Initial Catalog=MyDatabase;User Id=yy;Password=xx" providerName="Firebird" />
<add name="MSSQL__" connectionString="Data Source=192.168.1.x,12345;Initial Catalog=MyOtherDatabase;User Id=yy;Password=xx" providerName="SqlServer.2012" />
</connectionStrings>

in my program:

this did the trick: you give the connection a name with the parameter "name" in your connection settings, which makes sense if you have more than one...

using (var db_MSSQL = new MSSQL("MSSQL__"))
        {
            db_MSSQL.CreateTable<MSSQL_.MA_DATEN_NAME>();

Upvotes: 1

Related Questions