Using different databases

Using different databases

Postby gmitelman » Fri 22 Oct 2010 19:27

I'm working on a project that uses a different database for each deployment. However, the schema for each database is the same.
I don't want to have to create a diagram/set of classes for each database.
LinqConnect seems to hard-code database name as part of its generated code.
Can I set one up and then be able to either through configuration or runtime, switch to the correct database based on deployment?

Thank you.
gmitelman
 
Posts: 2
Joined: Fri 22 Oct 2010 19:24

Postby StanislavK » Tue 26 Oct 2010 10:33

Could you please specify the DBMS (e.g., SQL Server, Oracle, or SQLite) you are connecting to?

Generally, you can set the necessary database name in the connection string when creating a data context object:
http://www.devart.com/linqconnect/docs/Devart.Data.Linq~Devart.Data.Linq.DataContext~_ctor(String).html
StanislavK
Devart Team
 
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Linq To SQL

Postby gmitelman » Wed 27 Oct 2010 11:20

I'm using MySQL.
The problem is not setting the connection string. The issue is that the code that is automatically generated, has schema name as part of the table, so no matter what the connection string, all access ends up going to the schema used when generating the code, not the one I actually want to use.

For example:
I have 2 databases, db1 and db2 that are both identical in design. If I use db1 when generating the LinqConnect code, then db1 prefix is put into the generated code. So when I point connection string at db2, all my access still happens against db1, not db2.

I want to know how to override it or prevent schema name from being put into the generated code. I confirmed that if I take schema name out of generated code, it works as expected, but I don't want to be in the business of removing schema name every time I re-generate the data access code.

Thank you.
gmitelman
 
Posts: 2
Joined: Fri 22 Oct 2010 19:24

Postby StanislavK » Thu 28 Oct 2010 15:39

The schema name is always stored in order to handle the case of working with objects from several schemas in a single model.

The possible way to change this behaviour is to change the code generation template as it is described in the following topic:
http://www.devart.com/forums/viewtopic.php?t=17930

Please tell us if this helps.
StanislavK
Devart Team
 
Posts: 1710
Joined: Thu 03 Dec 2009 10:48


Return to LinqConnect (LINQ to SQL support)