"Jessard" <Je*****@discussions.microsoft.com> wrote:
Hi Guys and Girls,
I have a situation where I am wishing to deploy a .NET dll onto a number of
servers. The classes in the DLL will be used by VBScripts. When one of the
classes - Connection - is instantiated from a VBScript the code looks to a
simple text file for initialisation of certain variables. I want this text
file to reside with the dll when it is installed (via a setup project) and
have the file opened by the Connection class in the installation directory.
At the moment I have:
StreamReader sr = new StreamReader(@"config.ini");
and I use this stream to read in values. However, the path I have specified
here will be looking, when the object is made in the VBscript, where the
VBScript is located. How can I get it to look at the installation directory?
Any suggestions would be good,
Thanks,
Jesse
If I understand you scenario correctly you could simply use
..NET's built-in ConfigurationSettings functionality. If your
assembly is called "MyConnection.dll" create a configuration
file "MyConnection.dll.config" that resides in the same
directory as the assembly. Add your connection string to it:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="MyDatabase.Connection"
value="server=(local);database=mydatabase;Trusted_ Connection=true"
/>
</appSettings>
</configuration>
So here the "key" (whatever you name it) merely gives you a
handle to the "value" which happens to contain your
connection string.
In your class simply use:
using System.Configuration;
...
string connectionString =
ConfigurationSettings.AppSettings.Get("MyDatabase. Connection");
or even
private SqlConnection connection =
new SqlConnection(
ConfigurationSettings.AppSettings.Get("MyDatabase. Connection")
);
connection.Open();
or whatever the equivalent VB.NET is.
"HOW TO: Store and Retrieve Custom Information from an
Application Configuration File by Using Visual C# .NET"
http://support.microsoft.com/default...b;en-us;815786
"How To Store and Retrieve Custom Information from an
Application Configuration File by Using Visual Basic .NET"
http://support.microsoft.com/kb/313405/EN-US/
If you have a username and password that could use some
obscuring, then investigate the aspnet_setreg.exe utility
that was originally developed for ASP.NET.
"How to use the ASP.NET utility to encrypt credentials and
session state connection strings"
http://support.microsoft.com/default...b;en-us;329290
If you still need to know the where that assembly is then
this MAY be of some help:
"HOW TO: Determine the Executing Application's Path"
http://msdn.microsoft.com/library/de...ingapppath.asp
'Any fool can write code that a computer can understand.
Good programmers write code that humans can understand.'
Martin Fowler,
'Refactoring: improving the design of existing code', p.15