views:

46

answers:

1

I'm just beginning to use Linq-to-SQL and it's just wonderful to use. The problem is, this software is going to be run on a lot of machines and each machine will have a unique connection string.

Is there a way for me to manually set the connection the Linq-to-SQL (.dbml) uses?

The way I'm doing things now is creating the .dbml file, and in the graphic designer I'm dragging tables from the Server Explorer to the white board of the .dbml.

+6  A: 

Yes. Just pass the connection string you want to use to the DataContext constructor:

MyDbContext _context = MyDbContext(connString);
Justin Niessner
This is so great! What would happen is the .dbml recieves a connection string, but a table in the database has 2 more fields than it was expecting. What would occur?
Sergio Tapia
@Sergio Tapia - LINQ to SQL would just ignore the extra columns.
Justin Niessner
Thanks, great answer!
Sergio Tapia