application path

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

    application path

    I want to access a development db at a known location (ie,
    "MyApp\MyData\M yDb.mdb") but an unknown machine. I've used
    "|DataDirectory |\MyDb.mdb" in app.config with some limited success before
    but it's not working out well here.

    As a string with substitution variables, the connection (to a legacy MS
    Access db w/ security) is basically:
    string.Format(@ "Provider=Micro soft.Jet.OLEDB. 4.0;Data
    Source={1}MyDb. mdb;Jet OLEDB:System Database={1}Sec urity.mdw;User
    ID={2};Password ={3};",
    PROVIDER_JET,
    directoryPath,
    userID,
    password);

    I thought I might be able to get what I wanted by IO and reflection easier,
    but am stuck. The code below looks like what I want but when I run it from
    test code (in a separate assembly) it gives me the path to debug in the Test
    assembly (ie "MyApp\Tests\My Data\bin\Debug" ) instead of the App (ie
    "MyApp\MyData\b in\Debug") assembly.
    public static string CurrentDevelopm entDirectory() {
    var assembly = Assembly.GetAss embly(typeof (Connection)).C odeBase;
    return Path.GetDirecto ryName(assembly );
    }

    Thanks for the help! BH


  • =?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?=

    #2
    RE: application path

    You should call Assembly.GetExe cutingAssembly( ) to get the actually exe that
    is running. Then you can get the CodeBase property of that to get the path
    --
    Ciaran O''Donnell
    try{ Life(); } catch (TooDifficultException) { throw Toys(); }



    "Berryl Hesh" wrote:
    I want to access a development db at a known location (ie,
    "MyApp\MyData\M yDb.mdb") but an unknown machine. I've used
    "|DataDirectory |\MyDb.mdb" in app.config with some limited success before
    but it's not working out well here.
    >
    As a string with substitution variables, the connection (to a legacy MS
    Access db w/ security) is basically:
    string.Format(@ "Provider=Micro soft.Jet.OLEDB. 4.0;Data
    Source={1}MyDb. mdb;Jet OLEDB:System Database={1}Sec urity.mdw;User
    ID={2};Password ={3};",
    PROVIDER_JET,
    directoryPath,
    userID,
    password);
    >
    I thought I might be able to get what I wanted by IO and reflection easier,
    but am stuck. The code below looks like what I want but when I run it from
    test code (in a separate assembly) it gives me the path to debug in the Test
    assembly (ie "MyApp\Tests\My Data\bin\Debug" ) instead of the App (ie
    "MyApp\MyData\b in\Debug") assembly.
    public static string CurrentDevelopm entDirectory() {
    var assembly = Assembly.GetAss embly(typeof (Connection)).C odeBase;
    return Path.GetDirecto ryName(assembly );
    }
    >
    Thanks for the help! BH
    >
    >
    >

    Comment

    • Berryl Hesh

      #3
      Re: application path

      Hi Ciaran & thanks for the reply, but that also gets me to
      MyApp\*Tests*\b in\Debug.

      According to the docs, it makes sense that GetExecutingAss embly() would do
      that when the executing assembly is in fact Tests. The frustrating part is
      that it makes sense that if MyCoreClass is located in MyApp\Core, and I call
      Assembly.GetAss embly(typeof (MyCoreClass)). CodeBase, I should have
      MyApp\*Core*\bi n\Debug even when the executing assembly is from Tests. This
      is the problem I'm trying to solve.

      "Ciaran O''Donnell" <CiaranODonnell @discussions.mi crosoft.comwrot e in
      message news:F4AF3F2E-D12C-408A-90B0-D90554DFAD54@mi crosoft.com...
      You should call Assembly.GetExe cutingAssembly( ) to get the actually exe
      that
      is running. Then you can get the CodeBase property of that to get the path
      --
      Ciaran O''Donnell
      try{ Life(); } catch (TooDifficultException) { throw Toys(); }

      >
      >
      "Berryl Hesh" wrote:
      >
      >I want to access a development db at a known location (ie,
      >"MyApp\MyData\ MyDb.mdb") but an unknown machine. I've used
      >"|DataDirector y|\MyDb.mdb" in app.config with some limited success before
      >but it's not working out well here.
      >>
      >As a string with substitution variables, the connection (to a legacy MS
      >Access db w/ security) is basically:
      > string.Format(@ "Provider=Micro soft.Jet.OLEDB. 4.0;Data
      >Source={1}MyDb .mdb;Jet OLEDB:System Database={1}Sec urity.mdw;User
      >ID={2};Passwor d={3};",
      > PROVIDER_JET,
      > directoryPath,
      > userID,
      > password);
      >>
      >I thought I might be able to get what I wanted by IO and reflection
      >easier,
      >but am stuck. The code below looks like what I want but when I run it
      >from
      >test code (in a separate assembly) it gives me the path to debug in the
      >Test
      >assembly (ie "MyApp\Tests\My Data\bin\Debug" ) instead of the App (ie
      >"MyApp\MyData\ bin\Debug") assembly.
      > public static string CurrentDevelopm entDirectory() {
      > var assembly = Assembly.GetAss embly(typeof
      >(Connection)). CodeBase;
      > return Path.GetDirecto ryName(assembly );
      > }
      >>
      >Thanks for the help! BH
      >>
      >>
      >>

      Comment

      Working...