Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Changing the DataSource of a LINQ DataContext dynamically

Changing the DataSource of a LINQ DataContext dynamically

Scheduled Pinned Locked Moved LINQ
databasecsharpvisual-studiolinqsysadmin
2 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    conor20
    wrote on last edited by
    #1

    Hello, I have created an application that accesses an SQL database via LINQ. I designed the DataContext via the VS designer (DataContext1.dbml), and this generated all the XML etc. This application will run on several servers and so I need to have a method which changes the DataSource (eg. the Connection String) of the DataContext to the relavent Server. Is there any way of changing the Data Source / Connection String programmatically? The only way I can think of is to programmatically open the XML config files and change the connection string, before declaring the DataContext and running queries on it. The problem with this is that I'll be compiling the code into a DLL and the settings don't come in seperate files it seems, they're embedded in the DLL. Thanks, Conor.

    M 1 Reply Last reply
    0
    • C conor20

      Hello, I have created an application that accesses an SQL database via LINQ. I designed the DataContext via the VS designer (DataContext1.dbml), and this generated all the XML etc. This application will run on several servers and so I need to have a method which changes the DataSource (eg. the Connection String) of the DataContext to the relavent Server. Is there any way of changing the Data Source / Connection String programmatically? The only way I can think of is to programmatically open the XML config files and change the connection string, before declaring the DataContext and running queries on it. The problem with this is that I'll be compiling the code into a DLL and the settings don't come in seperate files it seems, they're embedded in the DLL. Thanks, Conor.

      M Offline
      M Offline
      murali_utr
      wrote on last edited by
      #2

      Datacontext constructor having option to pass connectionstring. this is one way. qryGenDataContext qryGen = new qryGenDataContext(connectionstring);

      Have A Nice Day! Murali.M Blog

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups