Typed DataSet in DLL points to wrong database!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?TWF4R3J1dmVu?=

    Typed DataSet in DLL points to wrong database!

    I have a DLL that implements the Business and Data Layers for a number of
    different websites. That DLL uses a Strongly Typed DataSet to interface to
    the Data Source which is SQL Server.

    There is a connection string in the DLL that is causes me grief. It points
    at a particular instance of database. I hae to recompile the DLL for each
    WebSite.

    How can I re-use that DLL on different websites and have it point to
    different instances of the Database without recompiling it?? Perhaps
    configurable in Web.Config??

    TIA,
    George
  • =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?=

    #2
    RE: Typed DataSet in DLL points to wrong database!

    set up a connection string in the web config of each site
    <connectionStri ngs>
    <add name="MyConnect ionString" connectionStrin g="Data
    Source=sqlhost. server.com;Init ial Catalog=trepidu scom;Persist Security
    Info=True;User ID=MYID;Passwor d=XXXX" providerName="S ystem.Data.SqlC lient"/>

    </connectionStrin gs>

    then create an appconfig name space:
    using System.Configur ation;

    namespace MyCompany.MyNam e.Dal
    {
    /// <summary>
    /// The AppConfiguarati on class for the web.config file connection
    string.
    /// </summary>
    public static class AppConfiguratio n
    {
    #region Public Properties

    /// <summary>
    /// Returns the connectionstrin g for the application.
    /// </summary>
    public static string ConnectionStrin g
    {
    get
    {
    return
    ConfigurationMa nager.Connectio nStrings["MyConnectionSt ring"].ConnectionStri ng;
    }
    }
    }
    }
    then in your connection
    area
    using (SqlConnection Con = new
    SqlConnectionAp pConfiguration. ConnectionStrin g))
    {
    ......
    ......
    ......
    }
    just be sure to includ a using MyCompany.MyNam e.Dal; at the top
    --
    Share The Knowledge. I need all the help I can get and so do you!


    "MaxGruven" wrote:
    I have a DLL that implements the Business and Data Layers for a number of
    different websites. That DLL uses a Strongly Typed DataSet to interface to
    the Data Source which is SQL Server.
    >
    There is a connection string in the DLL that is causes me grief. It points
    at a particular instance of database. I hae to recompile the DLL for each
    WebSite.
    >
    How can I re-use that DLL on different websites and have it point to
    different instances of the Database without recompiling it?? Perhaps
    configurable in Web.Config??
    >
    TIA,
    George

    Comment

    • =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?=

      #3
      RE: Typed DataSet in DLL points to wrong database!

      There is a paren missing
      it should be
      using (SqlConnection Con = new
      SqlConnection(A ppConfiguration .ConnectionStri ng))
      {
      --
      Share The Knowledge. I need all the help I can get and so do you!


      "Yankee Imperialist Dog" wrote:
      set up a connection string in the web config of each site
      <connectionStri ngs>
      <add name="MyConnect ionString" connectionStrin g="Data
      Source=sqlhost. server.com;Init ial Catalog=trepidu scom;Persist Security
      Info=True;User ID=MYID;Passwor d=XXXX" providerName="S ystem.Data.SqlC lient"/>
      >
      </connectionStrin gs>
      >
      then create an appconfig name space:
      using System.Configur ation;
      >
      namespace MyCompany.MyNam e.Dal
      {
      /// <summary>
      /// The AppConfiguarati on class for the web.config file connection
      string.
      /// </summary>
      public static class AppConfiguratio n
      {
      #region Public Properties
      >
      /// <summary>
      /// Returns the connectionstrin g for the application.
      /// </summary>
      public static string ConnectionStrin g
      {
      get
      {
      return
      ConfigurationMa nager.Connectio nStrings["MyConnectionSt ring"].ConnectionStri ng;
      }
      }
      }
      }
      then in your connection
      area
      using (SqlConnection Con = new
      SqlConnectionAp pConfiguration. ConnectionStrin g))
      {
      .....
      .....
      .....
      }
      just be sure to includ a using MyCompany.MyNam e.Dal; at the top
      --
      Share The Knowledge. I need all the help I can get and so do you!
      >
      >
      "MaxGruven" wrote:
      >
      I have a DLL that implements the Business and Data Layers for a number of
      different websites. That DLL uses a Strongly Typed DataSet to interface to
      the Data Source which is SQL Server.

      There is a connection string in the DLL that is causes me grief. It points
      at a particular instance of database. I hae to recompile the DLL for each
      WebSite.

      How can I re-use that DLL on different websites and have it point to
      different instances of the Database without recompiling it?? Perhaps
      configurable in Web.Config??

      TIA,
      George

      Comment

      • Peter Bromberg [C# MVP]

        #4
        Re: Typed DataSet in DLL points to wrong database!

        Since each web site would have its own web.config, set up the connection
        string in the <connectionStri ngs... element
        in the Assembly, you would get the proper connection string with:

        ConfigurationMa nager.Connectio nStrings["myConn"].ConnectionStri ng;

        Your assembly would need to have a reference to System.Configur ation.

        Peter

        "MaxGruven" <MaxGruven@news group.nospamwro te in message
        news:0469A4C4-85DA-4D70-9912-ADA86D1075C4@mi crosoft.com...
        >I have a DLL that implements the Business and Data Layers for a number of
        different websites. That DLL uses a Strongly Typed DataSet to interface
        to
        the Data Source which is SQL Server.
        >
        There is a connection string in the DLL that is causes me grief. It
        points
        at a particular instance of database. I hae to recompile the DLL for each
        WebSite.
        >
        How can I re-use that DLL on different websites and have it point to
        different instances of the Database without recompiling it?? Perhaps
        configurable in Web.Config??
        >
        TIA,
        George

        Comment

        • =?Utf-8?B?TWF4R3J1dmVu?=

          #5
          Re: Typed DataSet in DLL points to wrong database!

          Where do I put the reference to connection string in the BL/DL Assembly?

          Does it go in Project/Properties/Settings or app.config or in code somewhere?

          AND

          What Connection String gets used when just working on the BL/DL Assembly
          when there is no website (during development)??

          TIA,
          George

          "Peter Bromberg [C# MVP]" wrote:
          Since each web site would have its own web.config, set up the connection
          string in the <connectionStri ngs... element
          in the Assembly, you would get the proper connection string with:
          >
          ConfigurationMa nager.Connectio nStrings["myConn"].ConnectionStri ng;
          >
          Your assembly would need to have a reference to System.Configur ation.
          >
          Peter
          >
          "MaxGruven" <MaxGruven@news group.nospamwro te in message
          news:0469A4C4-85DA-4D70-9912-ADA86D1075C4@mi crosoft.com...
          I have a DLL that implements the Business and Data Layers for a number of
          different websites. That DLL uses a Strongly Typed DataSet to interface
          to
          the Data Source which is SQL Server.

          There is a connection string in the DLL that is causes me grief. It
          points
          at a particular instance of database. I hae to recompile the DLL for each
          WebSite.

          How can I re-use that DLL on different websites and have it point to
          different instances of the Database without recompiling it?? Perhaps
          configurable in Web.Config??

          TIA,
          George
          >

          Comment

          • Steven Cheng [MSFT]

            #6
            Re: Typed DataSet in DLL points to wrong database!

            Hi George,

            As for the TypedDataSet(in class library project)'s connectionstrin g
            problem, it is a common question I've seen. Actually, you can override the
            connectionstrin g in your consumer application(asp .net or other desktop)'s
            app.config file.

            For example, in your class library, when you created type dataset, it will
            generate the following section in the class library's app.config file:

            ===============

            <connectionStri ngs>
            <add
            name="ClassLibr ary1.Properties .Settings.MYASP DBConnectionStr ing"
            connectionStrin g="Data Source=localhos t;Initial
            Catalog=MYASPDB ;Integrated Security=True"
            providerName="S ystem.Data.SqlC lient" />
            </connectionStrin gs>
            ===============

            this is generated by the IDE for your typedataset. You can try adding such
            a connectionstrin g entry in your calling application( the asp.net )'s
            app.config file to override the default value(compiled in class library
            assembly).

            here are some former threads where I've mentioened something else about
            such customziation of class library's project properties:

            #app.config

            /thread/cba21e1cfca4585 a/d3b4969cae7a600 e

            #Question on how to manage SQL Server connection string Options

            /browse_thread/thread/e8b06265ba1c2b3 3/3c2a56cc046e4b1 c

            Sincerely,

            Steven Cheng

            Microsoft MSDN Online Support Lead


            Delighting our customers is our #1 priority. We welcome your comments and
            suggestions about how we can improve the support we provide to you. Please
            feel free to let my manager know what you think of the level of service
            provided. You can send feedback directly to my manager at:
            msdnmg@microsof t.com.

            =============== =============== =============== =====
            Get notification to my posts through email? Please refer to
            Gain technical skills through documentation and training, earn certifications and connect with the community

            ications.

            Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
            where an initial response from the community or a Microsoft Support
            Engineer within 1 business day is acceptable. Please note that each follow
            up response may take approximately 2 business days as the support
            professional working with you may need further investigation to reach the
            most efficient resolution. The offering is not appropriate for situations
            that require urgent, real-time or phone-based interactions or complex
            project analysis and dump analysis issues. Issues of this nature are best
            handled working with a dedicated Microsoft Support Engineer by contacting
            Microsoft Customer Support Services (CSS) at
            http://msdn.microsoft.com/subscripti...t/default.aspx.
            =============== =============== =============== =====
            This posting is provided "AS IS" with no warranties, and confers no rights.


            --------------------
            >From: =?Utf-8?B?TWF4R3J1dmV u?= <MaxGruven@news group.nospam>
            >References: <0469A4C4-85DA-4D70-9912-ADA86D1075C4@mi crosoft.com>
            <53FCEEA2-B544-480D-B22C-8F635093E598@mi crosoft.com>
            >Subject: Re: Typed DataSet in DLL points to wrong database!
            >Date: Thu, 5 Jun 2008 15:41:02 -0700
            >
            >Where do I put the reference to connection string in the BL/DL Assembly?
            >
            >Does it go in Project/Properties/Settings or app.config or in code
            somewhere?
            >
            AND
            >
            >What Connection String gets used when just working on the BL/DL Assembly
            >when there is no website (during development)??
            >
            >TIA,
            >George
            >
            >"Peter Bromberg [C# MVP]" wrote:
            >
            >Since each web site would have its own web.config, set up the connection
            >string in the <connectionStri ngs... element
            >in the Assembly, you would get the proper connection string with:
            >>
            >ConfigurationM anager.Connecti onStrings["myConn"].ConnectionStri ng;
            >>
            >Your assembly would need to have a reference to System.Configur ation.
            >>
            >Peter
            >>
            >"MaxGruven" <MaxGruven@news group.nospamwro te in message
            >news:0469A4C 4-85DA-4D70-9912-ADA86D1075C4@mi crosoft.com...
            >I have a DLL that implements the Business and Data Layers for a number
            of
            different websites. That DLL uses a Strongly Typed DataSet to
            interface
            to
            the Data Source which is SQL Server.
            >
            There is a connection string in the DLL that is causes me grief. It
            points
            at a particular instance of database. I hae to recompile the DLL for
            each
            WebSite.
            >
            How can I re-use that DLL on different websites and have it point to
            different instances of the Database without recompiling it?? Perhaps
            configurable in Web.Config??
            >
            TIA,
            George
            >>
            >

            Comment

            • =?Utf-8?B?TWF4R3J1dmVu?=

              #7
              Re: Typed DataSet in DLL points to wrong database!

              That was it Steven!

              Thanks for your help,
              George

              "Steven Cheng [MSFT]" wrote:
              Hi George,
              >
              As for the TypedDataSet(in class library project)'s connectionstrin g
              problem, it is a common question I've seen. Actually, you can override the
              connectionstrin g in your consumer application(asp .net or other desktop)'s
              app.config file.
              >
              For example, in your class library, when you created type dataset, it will
              generate the following section in the class library's app.config file:
              >
              ===============
              >
              <connectionStri ngs>
              <add
              name="ClassLibr ary1.Properties .Settings.MYASP DBConnectionStr ing"
              connectionStrin g="Data Source=localhos t;Initial
              Catalog=MYASPDB ;Integrated Security=True"
              providerName="S ystem.Data.SqlC lient" />
              </connectionStrin gs>
              ===============
              >
              this is generated by the IDE for your typedataset. You can try adding such
              a connectionstrin g entry in your calling application( the asp.net )'s
              app.config file to override the default value(compiled in class library
              assembly).
              >
              here are some former threads where I've mentioened something else about
              such customziation of class library's project properties:
              >
              #app.config

              /thread/cba21e1cfca4585 a/d3b4969cae7a600 e
              >
              #Question on how to manage SQL Server connection string Options

              /browse_thread/thread/e8b06265ba1c2b3 3/3c2a56cc046e4b1 c
              >
              Sincerely,
              >
              Steven Cheng
              >
              Microsoft MSDN Online Support Lead
              >
              >
              Delighting our customers is our #1 priority. We welcome your comments and
              suggestions about how we can improve the support we provide to you. Please
              feel free to let my manager know what you think of the level of service
              provided. You can send feedback directly to my manager at:
              msdnmg@microsof t.com.
              >
              =============== =============== =============== =====
              Get notification to my posts through email? Please refer to
              Gain technical skills through documentation and training, earn certifications and connect with the community

              ications.
              >
              Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
              where an initial response from the community or a Microsoft Support
              Engineer within 1 business day is acceptable. Please note that each follow
              up response may take approximately 2 business days as the support
              professional working with you may need further investigation to reach the
              most efficient resolution. The offering is not appropriate for situations
              that require urgent, real-time or phone-based interactions or complex
              project analysis and dump analysis issues. Issues of this nature are best
              handled working with a dedicated Microsoft Support Engineer by contacting
              Microsoft Customer Support Services (CSS) at
              http://msdn.microsoft.com/subscripti...t/default.aspx.
              =============== =============== =============== =====
              This posting is provided "AS IS" with no warranties, and confers no rights.
              >
              >
              --------------------
              From: =?Utf-8?B?TWF4R3J1dmV u?= <MaxGruven@news group.nospam>
              References: <0469A4C4-85DA-4D70-9912-ADA86D1075C4@mi crosoft.com>
              <53FCEEA2-B544-480D-B22C-8F635093E598@mi crosoft.com>
              Subject: Re: Typed DataSet in DLL points to wrong database!
              Date: Thu, 5 Jun 2008 15:41:02 -0700
              >

              Where do I put the reference to connection string in the BL/DL Assembly?

              Does it go in Project/Properties/Settings or app.config or in code
              somewhere?

              AND

              What Connection String gets used when just working on the BL/DL Assembly
              when there is no website (during development)??

              TIA,
              George

              "Peter Bromberg [C# MVP]" wrote:
              Since each web site would have its own web.config, set up the connection
              string in the <connectionStri ngs... element
              in the Assembly, you would get the proper connection string with:
              >
              ConfigurationMa nager.Connectio nStrings["myConn"].ConnectionStri ng;
              >
              Your assembly would need to have a reference to System.Configur ation.
              >
              Peter
              >
              "MaxGruven" <MaxGruven@news group.nospamwro te in message
              news:0469A4C4-85DA-4D70-9912-ADA86D1075C4@mi crosoft.com...
              I have a DLL that implements the Business and Data Layers for a number
              of
              different websites. That DLL uses a Strongly Typed DataSet to
              interface
              to
              the Data Source which is SQL Server.

              There is a connection string in the DLL that is causes me grief. It
              points
              at a particular instance of database. I hae to recompile the DLL for
              each
              WebSite.

              How can I re-use that DLL on different websites and have it point to
              different instances of the Database without recompiling it?? Perhaps
              configurable in Web.Config??

              TIA,
              George
              >
              >
              >

              Comment

              • Steven Cheng [MSFT]

                #8
                Re: Typed DataSet in DLL points to wrong database!

                You're welcome George,

                Have a nice day!

                Sincerely,

                Steven Cheng

                Microsoft MSDN Online Support Lead


                Delighting our customers is our #1 priority. We welcome your comments and
                suggestions about how we can improve the support we provide to you. Please
                feel free to let my manager know what you think of the level of service
                provided. You can send feedback directly to my manager at:
                msdnmg@microsof t.com.

                =============== =============== =============== =====
                Get notification to my posts through email? Please refer to
                Gain technical skills through documentation and training, earn certifications and connect with the community

                ications.
                =============== =============== =============== =====
                This posting is provided "AS IS" with no warranties, and confers no rights.
                --------------------
                >From: =?Utf-8?B?TWF4R3J1dmV u?= <MaxGruven@news group.nospam>
                >References: <0469A4C4-85DA-4D70-9912-ADA86D1075C4@mi crosoft.com>
                <53FCEEA2-B544-480D-B22C-8F635093E598@mi crosoft.com>
                <A069E54D-F462-4C5C-8CA5-019392C6DFB0@mi crosoft.com>
                <fMtbAw4xIHA.45 64@TK2MSFTNGHUB 02.phx.gbl>
                >Subject: Re: Typed DataSet in DLL points to wrong database!
                >Date: Fri, 6 Jun 2008 06:54:01 -0700
                >
                >That was it Steven!
                >
                >Thanks for your help,
                >George
                >
                >"Steven Cheng [MSFT]" wrote:
                >
                >Hi George,
                >>
                >As for the TypedDataSet(in class library project)'s connectionstrin g
                >problem, it is a common question I've seen. Actually, you can override
                the
                >connectionstri ng in your consumer application(asp .net or other
                desktop)'s
                >app.config file.
                >>
                >For example, in your class library, when you created type dataset, it
                will
                >generate the following section in the class library's app.config file:
                >>
                >============== =
                >>
                ><connectionStr ings>
                > <add
                >name="ClassLib rary1.Propertie s.Settings.MYAS PDBConnectionSt ring"
                > connectionStrin g="Data Source=localhos t;Initial
                >Catalog=MYASPD B;Integrated Security=True"
                > providerName="S ystem.Data.SqlC lient" />
                > </connectionStrin gs>
                >============== =
                >>
                >this is generated by the IDE for your typedataset. You can try adding
                such
                >a connectionstrin g entry in your calling application( the asp.net )'s
                >app.config file to override the default value(compiled in class library
                >assembly).
                >>
                >here are some former threads where I've mentioened something else about
                >such customziation of class library's project properties:
                >>
                >#app.config
                >>
                http://groups.google.com/group/micro.../browse_thread
                >/thread/cba21e1cfca4585 a/d3b4969cae7a600 e
                >>
                >#Question on how to manage SQL Server connection string Options
                >>
                http://groups.google.com/group/micro...rk.webservices
                >/browse_thread/thread/e8b06265ba1c2b3 3/3c2a56cc046e4b1 c
                >>
                >Sincerely,
                >>
                >Steven Cheng
                >>
                >Microsoft MSDN Online Support Lead
                >>
                >>
                >Delighting our customers is our #1 priority. We welcome your comments
                and
                >suggestions about how we can improve the support we provide to you.
                Please
                >feel free to let my manager know what you think of the level of service
                >provided. You can send feedback directly to my manager at:
                >msdnmg@microsof t.com.
                >>
                >============== =============== =============== ======
                >Get notification to my posts through email? Please refer to
                >>
                http://msdn.microsoft.com/subscripti...ult.aspx#notif
                >ications.
                >>
                >Note: The MSDN Managed Newsgroup support offering is for non-urgent
                issues
                >where an initial response from the community or a Microsoft Support
                >Engineer within 1 business day is acceptable. Please note that each
                follow
                >up response may take approximately 2 business days as the support
                >professional working with you may need further investigation to reach
                the
                >most efficient resolution. The offering is not appropriate for
                situations
                >that require urgent, real-time or phone-based interactions or complex
                >project analysis and dump analysis issues. Issues of this nature are
                best
                >handled working with a dedicated Microsoft Support Engineer by
                contacting
                >Microsoft Customer Support Services (CSS) at
                >http://msdn.microsoft.com/subscripti...t/default.aspx.
                >============== =============== =============== ======
                >This posting is provided "AS IS" with no warranties, and confers no
                rights.
                >>
                >>
                >--------------------
                >From: =?Utf-8?B?TWF4R3J1dmV u?= <MaxGruven@news group.nospam>
                >References: <0469A4C4-85DA-4D70-9912-ADA86D1075C4@mi crosoft.com>
                ><53FCEEA2-B544-480D-B22C-8F635093E598@mi crosoft.com>
                >Subject: Re: Typed DataSet in DLL points to wrong database!
                >Date: Thu, 5 Jun 2008 15:41:02 -0700
                >>
                >
                >Where do I put the reference to connection string in the BL/DL Assembly?
                >
                >Does it go in Project/Properties/Settings or app.config or in code
                >somewhere?
                >
                AND
                >
                >What Connection String gets used when just working on the BL/DL
                Assembly
                >when there is no website (during development)??
                >
                >TIA,
                >George
                >
                >"Peter Bromberg [C# MVP]" wrote:
                >
                >Since each web site would have its own web.config, set up the
                connection
                >string in the <connectionStri ngs... element
                >in the Assembly, you would get the proper connection string with:
                >>
                >ConfigurationM anager.Connecti onStrings["myConn"].ConnectionStri ng;
                >>
                >Your assembly would need to have a reference to System.Configur ation.
                >>
                >Peter
                >>
                >"MaxGruven" <MaxGruven@news group.nospamwro te in message
                >news:0469A4C 4-85DA-4D70-9912-ADA86D1075C4@mi crosoft.com...
                >I have a DLL that implements the Business and Data Layers for a
                number
                >of
                different websites. That DLL uses a Strongly Typed DataSet to
                >interface
                to
                the Data Source which is SQL Server.
                >
                There is a connection string in the DLL that is causes me grief.
                It
                points
                at a particular instance of database. I hae to recompile the DLL
                for
                >each
                WebSite.
                >
                How can I re-use that DLL on different websites and have it point to
                different instances of the Database without recompiling it??
                Perhaps
                configurable in Web.Config??
                >
                TIA,
                George
                >>
                >
                >>
                >>
                >

                Comment

                Working...