473,398 Members | 2,165 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,398 software developers and data experts.

Configuration for DLL

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
Jul 21 '05 #1
4 2712
"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
Jul 21 '05 #2
perhaps you can use this call:
System.Reflection.Assembly.GetExecutingAssembly(). Location

--- Nick

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Jessard" <Je*****@discussions.microsoft.com> wrote in message
news:3B**********************************@microsof t.com...
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

Jul 21 '05 #3
UAError wrote:
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:
Nope. DLLs do not have config files. Take a look at the links you give. The
clue is in the title "from an *Application* Configuration File"
"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


ConfigSettings.GetConfig will retrieve values from the *application's*
configuration file.

Take a look at this:

http://www.grimes.demon.co.uk/dotnet/configFAQ.htm#003

Also, since the OP said he will use VBScript the config file will be for the
process that runs the VBScript file (cscript.exe) in which case the config
file would have to be in the same folder as that file (and be called
cscript.exe.config).

Richard
--
www.richardgrimes.com
my email ev******@zicf.bet is encrypted with ROT13 (www.rot13.org)
Jul 21 '05 #4
"Richard Grimes [MVP]" <read my sig> wrote:
UAError wrote:
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:
Nope. DLLs do not have config files. Take a look at the links you give. The
clue is in the title "from an *Application* Configuration File"
"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


ConfigSettings.GetConfig will retrieve values from the *application's*
configuration file.

Take a look at this:

http://www.grimes.demon.co.uk/dotnet/configFAQ.htm#003

Silly me, I should have know better. The reason I wrote this
was because that's the way NUnit (
www.nunit.com
http://www.microsoft.com/MSPress/books/6778.asp
) works - but of course I now realize that it uses
"CreateInstanceAndUnwrap" to make it behave that way (as you
outline in
http://www.grimes.demon.co.uk/dotnet/configFAQ.htm#001
)

So I guess the OP is limited to something like

"A custom configuration file AppSettings reader class"
http://www.codeproject.com/csharp/Cu...ile_Reader.asp

or rolling his own ala:

"Application Configuration Using Configuration Files"
on "Visual C# .NET Code Samples"
http://www.microsoft.com/downloads/d...displaylang=en

I suspect that the "AppSettings" class in the

"Framework - How-To Configuration Settings" project in
"101 Visual Basic .NET Code Samples"
http://www.microsoft.com/downloads/d...DisplayLang=en

does something similar.

So the OP will still have to use

"System.Reflection.Assembly.GetExecutingAssembly() .Location"
http://msdn.microsoft.com/library/de...emblytopic.asp
http://msdn.microsoft.com/library/de...ationtopic.asp

FileInfo AssemblyLocation = new FileInfo (

System.Reflection.Assembly.GetExecutingAssembly(). Location
);
string assemblyDirectory =
AssemblyLocation.Directory.FullName;

to get the assembly's directory.

Also, since the OP said he will use VBScript the config file will be for the
process that runs the VBScript file (cscript.exe) in which case the config
file would have to be in the same folder as that file (and be called
cscript.exe.config).

Richard

'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
Jul 21 '05 #5

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

Similar topics

0
by: phillip | last post by:
This is interesting, I have attached my web.config file and the exception I have been logging. I created a library which provide data access to a database and a control system. The library is...
5
by: Water Cooler v2 | last post by:
I know that we can add a single name value entry in app.config or web.config in the configuration/configSettings/appSettings section like so: <add key="key" value="value" /> Question: I want...
1
by: Jess Chadwick | last post by:
I am attempting to use the Enterprise Library (Jan 2006) Cryptography block to encrypt a credit card number in my ASP.NET 2.0 Commerce Server application. Everything is configured correctly, as...
4
by: Michael Lang | last post by:
I was basically wanting to know how to use the System.Configuration namespace to be able to load an arbitrary number of unknown attributes on an element in a custom section in the .config into a...
6
by: Jeff Hegedus | last post by:
I have a dll that requires some configuration data. I put the configuration data in a custom configuration section in a config file that is loaded in the installation folder of the dll. If I...
8
by: Alberto | last post by:
Can you tell me how to read and modify a value in the app.config file using this class? Thank you very much
7
by: Arno R | last post by:
Hi all, I am sending mail from my apps with CDO nowadays. However I have one client where this will not work until now. I am thinking this is related to the provider where the client has his...
7
by: =?Utf-8?B?RG91Z2llIEJyb3du?= | last post by:
Hi I've written custom configuration section (inherits from System.Configuration.ConfigurationSection) to simplify the contents of the config file and to make life easier when accessing them in...
3
by: Mike | last post by:
Hi I have problem as folow: Caught Exception: System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Request for the permission of type...
0
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?= | last post by:
Hi, thanks, mister The code string rutaConfig = tbRutaConfigServicioBase.Text; '// Map to the application configuration file. ExeConfigurationFileMap configFile = New...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.