Physcial Path of Reference

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Al

    Physcial Path of Reference

    Greetings,

    I have several data access class libraries referenced by a web project. I'm
    storing the connection string in the data access libraries. I would like an
    easier way of moving from my local database server to the production
    database than loading every library, changing the connection string to
    reflect the new database server address, and recompiling

    Since only the database server address would change. I was thinking of
    storing the desired database server address in an xml file located in the
    bin directory with the other references. When a database call is made, the
    correct server address is retrieved from the xml file. However, unlike web
    projects, it seems difficult for a class library to determine where it's
    located.

    Any ideas?

    My other concern is the frequency of file operations on the XML file. Any
    other ideas.

    Thanks in advance.

    --


    Regards,

    Al


  • Bruce Barker

    #2
    Re: Physcial Path of Reference

    web project don't really run from the bin, it copied to temp bin (and
    referebced dlls), then compiled, so knowning dir would not be much good, but
    you get it from the assembly classes.

    put the connection string in the web config (or appconfig if windows app).

    -- bruce (sqlwork.com)


    "Al" <gt5092a@hotmai l.com> wrote in message
    news:eOAwqfCeFH A.2736@TK2MSFTN GP12.phx.gbl...[color=blue]
    > Greetings,
    >
    > I have several data access class libraries referenced by a web project.
    > I'm storing the connection string in the data access libraries. I would
    > like an easier way of moving from my local database server to the
    > production database than loading every library, changing the connection
    > string to reflect the new database server address, and recompiling
    >
    > Since only the database server address would change. I was thinking of
    > storing the desired database server address in an xml file located in the
    > bin directory with the other references. When a database call is made,
    > the correct server address is retrieved from the xml file. However,
    > unlike web projects, it seems difficult for a class library to determine
    > where it's located.
    >
    > Any ideas?
    >
    > My other concern is the frequency of file operations on the XML file. Any
    > other ideas.
    >
    > Thanks in advance.
    >
    > --
    >
    >
    > Regards,
    >
    > Al
    >[/color]


    Comment

    • Mythran

      #3
      Re: Physcial Path of Reference


      "Bruce Barker" <brubar_nospamp lease_@safeco.c om> wrote in message
      news:ud4cekCeFH A.456@TK2MSFTNG P14.phx.gbl...[color=blue]
      > web project don't really run from the bin, it copied to temp bin (and
      > referebced dlls), then compiled, so knowning dir would not be much good,
      > but you get it from the assembly classes.
      >
      > put the connection string in the web config (or appconfig if windows app).
      >
      > -- bruce (sqlwork.com)
      >
      >
      > "Al" <gt5092a@hotmai l.com> wrote in message
      > news:eOAwqfCeFH A.2736@TK2MSFTN GP12.phx.gbl...[color=green]
      >> Greetings,
      >>[/color][/color]


      To further explain:

      Modify your web.config to add the appSettings section:

      <configuratio n>
      ...
      <appSettings>
      <add key="Connection String"
      value="server=P RODUCTION;datab ase=dbDatabase; trusted_connect ion=true;" />
      </appSettings>
      </configuration>


      Use something like the following to retrieve the ConnectionStrin g from code:

      using System.Configur ation;

      namespace YourName.Space. Here
      {
      internal sealed class Configuration
      {
      private static string mConnectionStri ng;

      internal static string ConnectionStrin g
      {
      get {
      return
      ConfigurationSe ttings.AppSetti ngs.Item("Conne ctionString");
      }
      }
      }
      }

      btw, off the top of my head here.

      HTH,
      Mythran

      Comment

      • Mythran

        #4
        Re: Physcial Path of Reference


        "Bruce Barker" <brubar_nospamp lease_@safeco.c om> wrote in message
        news:ud4cekCeFH A.456@TK2MSFTNG P14.phx.gbl...[color=blue]
        > web project don't really run from the bin, it copied to temp bin (and
        > referebced dlls), then compiled, so knowning dir would not be much good,
        > but you get it from the assembly classes.
        >
        > put the connection string in the web config (or appconfig if windows app).
        >
        > -- bruce (sqlwork.com)
        >
        >
        > "Al" <gt5092a@hotmai l.com> wrote in message
        > news:eOAwqfCeFH A.2736@TK2MSFTN GP12.phx.gbl...[color=green]
        >> Greetings,
        >>[/color][/color]


        To further explain:

        Modify your web.config to add the appSettings section:

        <configuratio n>
        ...
        <appSettings>
        <add key="Connection String"
        value="server=P RODUCTION;datab ase=dbDatabase; trusted_connect ion=true;" />
        </appSettings>
        </configuration>


        Use something like the following to retrieve the ConnectionStrin g from code:

        using System.Configur ation;

        namespace YourName.Space. Here
        {
        internal sealed class Configuration
        {
        private static string mConnectionStri ng;

        internal static string ConnectionStrin g
        {
        get {
        return
        ConfigurationSe ttings.AppSetti ngs.Item("Conne ctionString");
        }
        }
        }
        }

        btw, off the top of my head here.

        HTH,
        Mythran

        Comment

        • Al

          #5
          Re: Physcial Path of Reference

          Greetings,

          I was unaware that web.config files could be used in class library projects.
          I'll have to try this.

          But, each of the data access libraries points to a different SQL database,
          on the same database server. Also, some of these data access libraries are
          used by more than one project. If I store the predominant connectionstrin g
          in the .config file of the web application, how do I pass that on to the
          data access libraries.


          Thanks in advance.

          --


          Regards,

          Allen Anderson
          "Mythran" <kip_potter@hot mail.comREMOVET RAIL> wrote in message
          news:%234RGpeDe FHA.3280@TK2MSF TNGP09.phx.gbl. ..[color=blue]
          >
          > "Bruce Barker" <brubar_nospamp lease_@safeco.c om> wrote in message
          > news:ud4cekCeFH A.456@TK2MSFTNG P14.phx.gbl...[color=green]
          >> web project don't really run from the bin, it copied to temp bin (and
          >> referebced dlls), then compiled, so knowning dir would not be much good,
          >> but you get it from the assembly classes.
          >>
          >> put the connection string in the web config (or appconfig if windows
          >> app).
          >>
          >> -- bruce (sqlwork.com)
          >>
          >>
          >> "Al" <gt5092a@hotmai l.com> wrote in message
          >> news:eOAwqfCeFH A.2736@TK2MSFTN GP12.phx.gbl...[color=darkred]
          >>> Greetings,
          >>>[/color][/color]
          >
          >
          > To further explain:
          >
          > Modify your web.config to add the appSettings section:
          >
          > <configuratio n>
          > ...
          > <appSettings>
          > <add key="Connection String"
          > value="server=P RODUCTION;datab ase=dbDatabase; trusted_connect ion=true;" />
          > </appSettings>
          > </configuration>
          >
          >
          > Use something like the following to retrieve the ConnectionStrin g from
          > code:
          >
          > using System.Configur ation;
          >
          > namespace YourName.Space. Here
          > {
          > internal sealed class Configuration
          > {
          > private static string mConnectionStri ng;
          >
          > internal static string ConnectionStrin g
          > {
          > get {
          > return
          > ConfigurationSe ttings.AppSetti ngs.Item("Conne ctionString");
          > }
          > }
          > }
          > }
          >
          > btw, off the top of my head here.
          >
          > HTH,
          > Mythran
          >[/color]


          Comment

          • Mythran

            #6
            Re: Physcial Path of Reference


            "Al" <gt5092a@hotmai l.com> wrote in message
            news:Ol70B5DeFH A.228@TK2MSFTNG P12.phx.gbl...[color=blue]
            > Greetings,
            >
            > I was unaware that web.config files could be used in class library
            > projects. I'll have to try this.
            >
            > But, each of the data access libraries points to a different SQL database,
            > on the same database server. Also, some of these data access libraries
            > are used by more than one project. If I store the predominant
            > connectionstrin g in the .config file of the web application, how do I pass
            > that on to the data access libraries.
            >
            >
            > Thanks in advance.
            >
            > --[/color]

            Class library projects don't have config files themselves. When you use
            System.Configur ation.Configura tionSettings.Ap pSettings, it accesses the
            application's configuration file (the application calling the class library
            assembly). :)

            Mythran

            Comment

            • Al

              #7
              Re: Physcial Path of Reference

              This works. Thanks alot!!!

              --


              Regards,

              Allen Anderson
              "Mythran" <kip_potter@hot mail.comREMOVET RAIL> wrote in message
              news:ujl6g7DeFH A.2984@TK2MSFTN GP15.phx.gbl...[color=blue]
              >
              > "Al" <gt5092a@hotmai l.com> wrote in message
              > news:Ol70B5DeFH A.228@TK2MSFTNG P12.phx.gbl...[color=green]
              >> Greetings,
              >>
              >> I was unaware that web.config files could be used in class library
              >> projects. I'll have to try this.
              >>
              >> But, each of the data access libraries points to a different SQL
              >> database, on the same database server. Also, some of these data access
              >> libraries are used by more than one project. If I store the predominant
              >> connectionstrin g in the .config file of the web application, how do I
              >> pass that on to the data access libraries.
              >>
              >>
              >> Thanks in advance.
              >>
              >> --[/color]
              >
              > Class library projects don't have config files themselves. When you use
              > System.Configur ation.Configura tionSettings.Ap pSettings, it accesses the
              > application's configuration file (the application calling the class
              > library assembly). :)
              >
              > Mythran
              >[/color]


              Comment

              Working...