Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I need some help.. I've created a dll that holds a number of functions that makes calls to a sql database. in each function is a connection string. I'd like to be able to populate that connection string from a file. I was thinking that this would make it much easiser to change from dev to production env. Question is.. can I do this and how.

 

thanks for any help

shannon

JvCoach23

VB.Net newbie

MS Sql Vet

Posted
maybe I'm over simplifying but couldn't you just use appropriate Stream classes and write your paths to a file that way... The other option would be to use an xml file using XmlDocument class.
Posted
maybe I'm over simplifying but couldn't you just use appropriate Stream classes and write your paths to a file that way... The other option would be to use an xml file using XmlDocument class.

 

not sure what you mean.. I tried writing out my connection string to a file.. that worked fine. I tried reading my connection string in through a stream to a variable... that didn't seem to work. what you are saying may be true.. i'm not very good at this stuff.. still learning.. and so much to learn.

JvCoach23

VB.Net newbie

MS Sql Vet

Posted
not sure what you mean.. I tried writing out my connection string to a file.. that worked fine. I tried reading my connection string in through a stream to a variable... that didn't seem to work. what you are saying may be true.. i'm not very good at this stuff.. still learning.. and so much to learn.

 

 

I'm not all that familiar with SQL so when you say connection string is it just the path to the SQL database or the code that you use to open the connection. If you are talking about the code to open the source I don't know what to tell you... if you are simply talking about a string path then all you have to do is write it out to a file.... I think I probably over simplified your problem... sorry I couldn't help

Posted

Add a new app. config file ... Add -> Add new Item,->Application Configuration File

this file can contain yer various DB connection strings

 

<configuration>

<appsettings>

<add key="key1" value="my key1 value">

<add key="key2" value="my key2 value">

<add key="key3" value="12345">

<add key="key4" value="true">

</appsettings>

</configuration>

 

To read the app.config u code

 

string s1 = System.Configuration.ConfigurationSettings.AppSettings["key1"];

MessageBox.Show(s1);

string s2= System.Configuration.ConfigurationSettings.AppSettings["key2"];

MessageBox.Show(s2)

Posted
Add a new app. config file ... Add -> Add new Item,->Application Configuration File

this file can contain yer various DB connection strings

 

<configuration>

<appsettings>

<add key="key1" value="my key1 value">

<add key="key2" value="my key2 value">

<add key="key3" value="12345">

<add key="key4" value="true">

</appsettings>

</configuration>

 

To read the app.config u code

 

string s1 = System.Configuration.ConfigurationSettings.AppSettings["key1"];

MessageBox.Show(s1);

string s2= System.Configuration.ConfigurationSettings.AppSettings["key2"];

MessageBox.Show(s2)

 

thanks for the lead.. I created a config file..

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<add key="key1" value = "pwd=pmdatagatherer123; UID=pmDataGatherer; server=Ntdts1; database=Monitor"></add>
</configuration>

and tried plugging it into the dll.

 

Dim configfile As String = System.Configuration.ConfigurationSettings.AppSettings("key1")

the configfile is nothing.. so, am i getting close just missing something...

 

thanks

JvCoach23

VB.Net newbie

MS Sql Vet

Posted
thanks for the lead.. I created a config file..

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<add key="key1" value = "pwd=pmdatagatherer123; UID=pmDataGatherer; server=Ntdts1; database=Monitor"></add>
</configuration>

and tried plugging it into the dll.

 

Dim configfile As String = System.Configuration.ConfigurationSettings.AppSettings("key1")

the configfile is nothing.. so, am i getting close just missing something...

 

thanks

 

here is how I have done it in the past

 

 

Dim configurationAppSettings As System.Configuration.AppSettingsReader = new System.Configuration.AppSettingsReader

Dim InitialRun As Boolean

InitialRun = CType(configurationAppSettings.GetValue("InitialRun", _

GetType(System.Boolean)), String)

LabName = CType(configurationAppSettings.GetValue("LabName", _

GetType(System.String)), String)

Posted

What did is the filename of your config file. It must be the same as your assembly name + the .config.

 

eg.

 

MyClassLibrary.dll

MyClassLibrary.dll.config

Posted
here is how I have done it in the past

 

 

Dim configurationAppSettings As System.Configuration.AppSettingsReader = new System.Configuration.AppSettingsReader

Dim InitialRun As Boolean

InitialRun = CType(configurationAppSettings.GetValue("InitialRun", _

GetType(System.Boolean)), String)

LabName = CType(configurationAppSettings.GetValue("LabName", _

GetType(System.String)), String)

 

I changed the name of the config file to be performance.config.. the name of the dll is performance.dll. I changed it just to try it based on the post. Here is what I have in the code.

 

Dim configurationAppSettings As System.Configuration.AppSettingsReader = New System.Configuration.AppSettingsReader
   Dim LabName = CType(configurationAppSettings.GetValue("key1", GetType(System.String)), String)

 

here is the config file info

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<add key="key1" value = "pwd=password; UID=uid; server=(local); database=Monitor"></add>
</configuration>

 

I'm sorry I'm not getting this to work..hope you'll continue the help.

When i step throught he code.. the

CType(configurationAppSettings.GetValue("key1", GetType(System.String)), String)

comes back as nothing

JvCoach23

VB.Net newbie

MS Sql Vet

Posted (edited)
<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<add key="key1" value = "pwd=password; UID=uid; server=(local); database=Monitor"></add>

</configuration>

 

an app config file is in the format

 

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
[b]<appsettings>[/b]
<add key="key1" value = "pwd=password; UID=uid; server=(local); database=Monitor"></add>
[b]</appsettings>[/b]
</configuration> 

 

 

u missed the app settings tag out

 

ALSO as Optical pointed out the config file must be named performance.dll.config BECAUSE the name of yer DLL is perfromance.dll

 

IN general assembly name + ".config"

eg. blah.exe -> blah.exe.config

mydll.dll ->mydll.dll.config

Edited by twistedm1nd
Posted
ok.. i've made those changes.. in stepping through it looks like it is trying to read from the performance.dll.config file. however it says that the key key1 does not exist so it can't read from it. The config file looks just like the one you modified now..

JvCoach23

VB.Net newbie

MS Sql Vet

Posted (edited)

my bad coach its appSettings < yep case sensitivity .. which leads me to the question are XML files case sensitive .. i'm too sleepy now i'll look it up morrow and let ya know >

 

//VB.Net [yep it works now ]

Dim configfile As String = System.Configuration.ConfigurationSettings.AppSettings("key1")

dll1.zip

Edited by PlausiblyDamp
Posted

Sorry PlausiblyDamp, I decided to remove them(binaries) and then decided to leave them on... guess i should have removed them.

Thanks Diesel.

Ty to u too shannon, thats my 1st VB.Net program:p lol

Posted

dog gone if I didn't speak too soon. I was watching the wrong thing. The config file still doesn't seem to be getting populated. My dll troubleshooting skills might be looking in the wrong spots too. but my config perfmon.dll.config file looks like this.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<AppSettings>
<add key="key1" value = "pwd=pmdatagatherer123; UID=pmDataGatherer; server=(local); database=Monitor"></add>
</AppSettings>
</configuration>

 

the code I'm using to try to read it to a string is this

Dim configfile As String = System.Configuration.ConfigurationSettings.AppSettings("key1")

 

when I set a break point in my code to go out and show me when it tries to read from the dll.. i look at teh configfile and it is always = nothing.

JvCoach23

VB.Net newbie

MS Sql Vet

Posted

bit more info.. I tried using this

Dim configurationAppSettings As System.Configuration.AppSettingsReader = New System.Configuration.AppSettingsReader
Dim configfile = CType(configurationAppSettings.GetValue("key1", GetType(System.String)), String)

and the error message I got back said something about couldn't read from the appSettings. Now in the perfmon.dll.config file.. the app setting secition is AppSettings.. not appSettings. in digging around.. I also have a applicaitonconstants.config file.. that does have an applicationSettings section. under that is a <!--database settings--> <DB_CONN> am i trying to work with the config file.

JvCoach23

VB.Net newbie

MS Sql Vet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...