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. C#
  4. C# linq to sql default problem

C# linq to sql default problem

Scheduled Pinned Locked Moved C#
databasecsharplinqcomxml
5 Posts 3 Posters 0 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.
  • S Offline
    S Offline
    sc steinhayse
    wrote on last edited by
    #1

    In a C# 2010 application, I used linq to sql to setup my database connections. Now when I move the application to a different database, the original database is still being used. Basically the connection string is hard coded into theapplication. I tried to follow the linq listed below, but everything did not work. http://goneale.com/2009/03/26/untie-linq-to-sql-connection-string-from-application-settings/ The part that says, "1.Open up the LINQ to SQL designer, and open the Properties tab of the designer (the schema itself), expand Connection and set Application Settings to False. ", I did not see this option. The closest thing I found was connection and I set that value. Here is the way the code looks now in the *designer.cs file.

    namespace e_ClScripts
    {
    using System.Data.Linq;
    using System.Data.Linq.Mapping;
    using System.Data;
    using System.Collections.Generic;
    using System.Reflection;
    using System.Linq;
    using System.Linq.Expressions;
    using System.ComponentModel;
    using System;

    [global::System.Data.Linq.Mapping.DatabaseAttribute(Name="DEV")]
    public partial class eDataContext : System.Data.Linq.DataContext
    {

    private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();

    #region Extensibility Method Definitions
    partial void OnCreated();
    partial void Inserte\_Detail(e\_Detail instance);
    partial void Updatee\_Detail(e\_Detail instance);
    partial void Deletee\_Detail(e\_Detail instance);
    partial void InsertIBook(IBook instance);
    partial void UpdateIBook(IBook instance);
    partial void DeleteIBook(IBook instance);
    partial void InsertIPackage(IPackage instance);
    partial void UpdateIPackage(IPackage instance);
    partial void DeleteIPackage(IPackage instance);
    partial void InsertIError\_Tran(instance);
    partial void UpdateIError\_Tran(IError\_Tran instance);
    partial void DeleteIError\_Tran(IError\_Tran instance);
    partial void InsertTransaction\_Type(Transaction\_Type instance);
    partial void UpdateTransaction\_Type(Transaction\_Type instance);
    partial void DeleteTransaction\_Type(Transaction\_Type instance);
    partial void Inserte\_Tracking(e\_Tracking instance);
    partial void Updatee\_Tracking(e\_Tracking instance);
    partial void Deletee\_Tracking(e\_Tracking instance);
    #endregion
    

    public eDataContext() :
    base(global::e_ClScripts.Properties.Settings.Default.DEVConnectionString, mappingSource)
    {
    OnCreated();
    }

    public eDataContext(string connection) :
    base(conne

    M J 2 Replies Last reply
    0
    • S sc steinhayse

      In a C# 2010 application, I used linq to sql to setup my database connections. Now when I move the application to a different database, the original database is still being used. Basically the connection string is hard coded into theapplication. I tried to follow the linq listed below, but everything did not work. http://goneale.com/2009/03/26/untie-linq-to-sql-connection-string-from-application-settings/ The part that says, "1.Open up the LINQ to SQL designer, and open the Properties tab of the designer (the schema itself), expand Connection and set Application Settings to False. ", I did not see this option. The closest thing I found was connection and I set that value. Here is the way the code looks now in the *designer.cs file.

      namespace e_ClScripts
      {
      using System.Data.Linq;
      using System.Data.Linq.Mapping;
      using System.Data;
      using System.Collections.Generic;
      using System.Reflection;
      using System.Linq;
      using System.Linq.Expressions;
      using System.ComponentModel;
      using System;

      [global::System.Data.Linq.Mapping.DatabaseAttribute(Name="DEV")]
      public partial class eDataContext : System.Data.Linq.DataContext
      {

      private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();

      #region Extensibility Method Definitions
      partial void OnCreated();
      partial void Inserte\_Detail(e\_Detail instance);
      partial void Updatee\_Detail(e\_Detail instance);
      partial void Deletee\_Detail(e\_Detail instance);
      partial void InsertIBook(IBook instance);
      partial void UpdateIBook(IBook instance);
      partial void DeleteIBook(IBook instance);
      partial void InsertIPackage(IPackage instance);
      partial void UpdateIPackage(IPackage instance);
      partial void DeleteIPackage(IPackage instance);
      partial void InsertIError\_Tran(instance);
      partial void UpdateIError\_Tran(IError\_Tran instance);
      partial void DeleteIError\_Tran(IError\_Tran instance);
      partial void InsertTransaction\_Type(Transaction\_Type instance);
      partial void UpdateTransaction\_Type(Transaction\_Type instance);
      partial void DeleteTransaction\_Type(Transaction\_Type instance);
      partial void Inserte\_Tracking(e\_Tracking instance);
      partial void Updatee\_Tracking(e\_Tracking instance);
      partial void Deletee\_Tracking(e\_Tracking instance);
      #endregion
      

      public eDataContext() :
      base(global::e_ClScripts.Properties.Settings.Default.DEVConnectionString, mappingSource)
      {
      OnCreated();
      }

      public eDataContext(string connection) :
      base(conne

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      I don't use Linq to SQL but we have different config files for each environment. The UAT config file will have a different connection string pointing to the UAT server, when you compile for deployment you chose the config you want to use and make sure the config file has the correct connection string.

      Never underestimate the power of human stupidity RAH

      S 1 Reply Last reply
      0
      • M Mycroft Holmes

        I don't use Linq to SQL but we have different config files for each environment. The UAT config file will have a different connection string pointing to the UAT server, when you compile for deployment you chose the config you want to use and make sure the config file has the correct connection string.

        Never underestimate the power of human stupidity RAH

        S Offline
        S Offline
        sc steinhayse
        wrote on last edited by
        #3

        You are correct that each database has a different connection. However in code, can you show me how to change the connection string and how to change the app.config file to point to the different databases? The way that linq to sql works is it hard codes the connection string. I want avoid this hardcoded connection string.

        M 1 Reply Last reply
        0
        • S sc steinhayse

          You are correct that each database has a different connection. However in code, can you show me how to change the connection string and how to change the app.config file to point to the different databases? The way that linq to sql works is it hard codes the connection string. I want avoid this hardcoded connection string.

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          It is not a coding problem take a look at ConfigurationManager[^]

          Never underestimate the power of human stupidity RAH

          1 Reply Last reply
          0
          • S sc steinhayse

            In a C# 2010 application, I used linq to sql to setup my database connections. Now when I move the application to a different database, the original database is still being used. Basically the connection string is hard coded into theapplication. I tried to follow the linq listed below, but everything did not work. http://goneale.com/2009/03/26/untie-linq-to-sql-connection-string-from-application-settings/ The part that says, "1.Open up the LINQ to SQL designer, and open the Properties tab of the designer (the schema itself), expand Connection and set Application Settings to False. ", I did not see this option. The closest thing I found was connection and I set that value. Here is the way the code looks now in the *designer.cs file.

            namespace e_ClScripts
            {
            using System.Data.Linq;
            using System.Data.Linq.Mapping;
            using System.Data;
            using System.Collections.Generic;
            using System.Reflection;
            using System.Linq;
            using System.Linq.Expressions;
            using System.ComponentModel;
            using System;

            [global::System.Data.Linq.Mapping.DatabaseAttribute(Name="DEV")]
            public partial class eDataContext : System.Data.Linq.DataContext
            {

            private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();

            #region Extensibility Method Definitions
            partial void OnCreated();
            partial void Inserte\_Detail(e\_Detail instance);
            partial void Updatee\_Detail(e\_Detail instance);
            partial void Deletee\_Detail(e\_Detail instance);
            partial void InsertIBook(IBook instance);
            partial void UpdateIBook(IBook instance);
            partial void DeleteIBook(IBook instance);
            partial void InsertIPackage(IPackage instance);
            partial void UpdateIPackage(IPackage instance);
            partial void DeleteIPackage(IPackage instance);
            partial void InsertIError\_Tran(instance);
            partial void UpdateIError\_Tran(IError\_Tran instance);
            partial void DeleteIError\_Tran(IError\_Tran instance);
            partial void InsertTransaction\_Type(Transaction\_Type instance);
            partial void UpdateTransaction\_Type(Transaction\_Type instance);
            partial void DeleteTransaction\_Type(Transaction\_Type instance);
            partial void Inserte\_Tracking(e\_Tracking instance);
            partial void Updatee\_Tracking(e\_Tracking instance);
            partial void Deletee\_Tracking(e\_Tracking instance);
            #endregion
            

            public eDataContext() :
            base(global::e_ClScripts.Properties.Settings.Default.DEVConnectionString, mappingSource)
            {
            OnCreated();
            }

            public eDataContext(string connection) :
            base(conne

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #5

            sc steinhayse wrote:

            connectionString="Data Source=instance1\DEV;Initial Catalog=dev3;Integrated Security=True"

            Err...That is your connection string. It is in your app.config. So if you want it to point to a different database then you change that. If however that is not where your connection string is coming from then it is certainly coming from somewhere so use a text editor to search ALL files you in your source tree for the connection information.

            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