473,402 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

application path

I want to access a development db at a known location (ie,
"MyApp\MyData\MyDb.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=Microsoft.Jet.OLEDB.4.0;D ata
Source={1}MyDb.mdb;Jet OLEDB:System Database={1}Security.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\MyData\bin\Debug") instead of the App (ie
"MyApp\MyData\bin\Debug") assembly.
public static string CurrentDevelopmentDirectory() {
var assembly = Assembly.GetAssembly(typeof (Connection)).CodeBase;
return Path.GetDirectoryName(assembly);
}

Thanks for the help! BH
Sep 23 '08 #1
2 1299
You should call Assembly.GetExecutingAssembly() to get the actually exe that
is running. Then you can get the CodeBase property of that to get the path
--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"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
"|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=Microsoft.Jet.OLEDB.4.0;D ata
Source={1}MyDb.mdb;Jet OLEDB:System Database={1}Security.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\MyData\bin\Debug") instead of the App (ie
"MyApp\MyData\bin\Debug") assembly.
public static string CurrentDevelopmentDirectory() {
var assembly = Assembly.GetAssembly(typeof (Connection)).CodeBase;
return Path.GetDirectoryName(assembly);
}

Thanks for the help! BH
Sep 24 '08 #2
Hi Ciaran & thanks for the reply, but that also gets me to
MyApp\*Tests*\bin\Debug.

According to the docs, it makes sense that GetExecutingAssembly() 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.GetAssembly(typeof (MyCoreClass)).CodeBase, I should have
MyApp\*Core*\bin\Debug even when the executing assembly is from Tests. This
is the problem I'm trying to solve.

"Ciaran O''Donnell" <Ci************@discussions.microsoft.comwrote in
message news:F4**********************************@microsof t.com...
You should call Assembly.GetExecutingAssembly() to get the actually exe
that
is running. Then you can get the CodeBase property of that to get the path
--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"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
"|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=Microsoft.Jet.OLEDB.4.0;D ata
Source={1}MyDb.mdb;Jet OLEDB:System Database={1}Security.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\MyData\bin\Debug") instead of the App (ie
"MyApp\MyData\bin\Debug") assembly.
public static string CurrentDevelopmentDirectory() {
var assembly = Assembly.GetAssembly(typeof
(Connection)).CodeBase;
return Path.GetDirectoryName(assembly);
}

Thanks for the help! BH

Sep 24 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Timothy Shih | last post by:
Hi, I am having a freezing issue with my application. My application serves several remotable objects, all of which must be initialized before their use. Furthermore, some of them depend on each...
3
by: ramonred | last post by:
Hi, I have two web apps. Lets say main and admin for the sake of simplicity. admin is a web app within main (as a subdomain). So the path for admin is http://admin.main.com within the admin...
2
by: mark | last post by:
Can't figure this one out. I appears to not be code related. After surfing my asp.net web app for a while 5 - 10 min. it fails to open any further connections to my access 2000 database. There...
1
by: Keith | last post by:
All, I have been told this is an ASP.NET issue and not an IIS issue, so I am posting this here. I have a problem with ASP.NET returning an HTTP 500 error when trying to run ASPX pages on...
2
by: Ross | last post by:
Hi I have an application using asp.net that I am running on my PC. The web form has a text box where you can enter a name for a new Photo category then click on the button. The code is...
4
by: JOHN MALONEY | last post by:
Hi Everybody, I have created a three-tiered db application in VB .NET but I can't get the deployment to work right. I have added a SetUp project to the existing application. I also selected...
6
by: Ben Finney | last post by:
Howdy all, I'm improving an existing application that's partly written using Python and the standard library. Many of the improvements I want to make can be done by using third-party free...
0
by: steve | last post by:
I am using vb.net 2005 Express Edition. Application Settings would be a very useful thing, as a global program database that persists; if only it would work! Does anyone know a hack or a...
4
by: =?Utf-8?B?VkIgSm9ubmll?= | last post by:
I am at my witless end here, please help! I have an ASP.Net aspx web page, hosted on Windows Server 2003, that receives a query string with the path to an autocad drawing file selected from a...
0
by: Steve | last post by:
Hello- Your assistance with this issue is greatly appreciated. Environment: - Load-balanced IIS 6.0 servers (Win2003) - web servers point (via UNC path) to a Microsoft File Cluster on...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.