473,795 Members | 2,911 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2737
"Jessard" <Je*****@discus sions.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 ConfigurationSe ttings functionality. If your
assembly is called "MyConnection.d ll" create a configuration
file "MyConnection.d ll.config" that resides in the same
directory as the assembly. Add your connection string to it:

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<appSettings>
<add key="MyDatabase .Connection"

value="server=( local);database =mydatabase;Tru sted_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.Configur ation;
...

string connectionStrin g =

ConfigurationSe ttings.AppSetti ngs.Get("MyData base.Connection ");

or even

private SqlConnection connection =
new SqlConnection(

ConfigurationSe ttings.AppSetti ngs.Get("MyData base.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.e xe 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.Reflecti on.Assembly.Get ExecutingAssemb ly().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*****@discus sions.microsoft .com> wrote in message
news:3B******** *************** ***********@mic rosoft.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 ConfigurationSe ttings functionality. If your
assembly is called "MyConnection.d ll" create a configuration
file "MyConnection.d ll.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.con fig).

Richard
--
www.richardgrimes.com
my email ev******@zicf.b et 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 ConfigurationSe ttings functionality. If your
assembly is called "MyConnection.d ll" create a configuration
file "MyConnection.d ll.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*
configuratio n 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
"CreateInstance AndUnwrap" 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:

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

I suspect that the "AppSetting s" 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.Reflect ion.Assembly.Ge tExecutingAssem bly().Location"
http://msdn.microsoft.com/library/de...emblytopic.asp
http://msdn.microsoft.com/library/de...ationtopic.asp

FileInfo AssemblyLocatio n = new FileInfo (

System.Reflecti on.Assembly.Get ExecutingAssemb ly().Location
);
string assemblyDirecto ry =
AssemblyLocatio n.Directory.Ful lName;

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.co nfig).

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
5323
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 written in C#. I created a small .exe file to test that the library builds propertly from configuration and that it communicates properly. This work great in the System.Windows.Forms. However, when I use the library in a web enviroment things...
5
4603
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 to add a dictionary of name-value pairs. In other words, instead of a single name-value, I want to add a name-value collection in there. I could do this:
1
6436
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 evidenced by the fact that it is running on a production box using the same web.config (but not the same parent web.config). When I call the EncryptSymmetric() method, I get this error: Server Error in '/Store' Application....
4
1918
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 NameValueCollection. Basically I want to do something similiar to what occurs with a System.Configuration.Provider.ProviderBase Initialise method - the provider is passed a NameValueCollection containing attribute names and their associated...
6
4818
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 install the dll to the same directory as the exe which uses it, everything works as expected but if I load the dll in any other directory, I get the following error... 2007-02-04 16:36:51,171 DEBUG CentrifugeBHO.CentrifugeBHO - dllPath =...
8
10223
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
7285
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 internet-account. I am using cdosys with 'late binding'. I try to send mail with an attachment to a few mailaddresses (strTo) The *exact same code* (with other smtpserver-login and pw strings) does work on various other PC's with various other...
7
10828
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 code. The configuration section is contained within the exe (it's a simple test case!) and everything works well debugging within the IDE or if the application is deployed on a drive or share that has been granted full trust. For the share the...
3
12062
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 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. (machine.config) ---> System.Security.SecurityException: Request for the permission of type
0
2623
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 ExeConfigurationFileMap();
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10439
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10215
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7541
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.