Link to home
Start Free TrialLog in
Avatar of matt_swinburne
matt_swinburne

asked on

Config file database

I am using an application configuration file to store the location of a database but am not sure of the syntax in getting the dblocation from the config file. (app.config)

Using this in the config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 
 <appSettings>
 
 <add key="Location" value="\\network\folder\"/>
 
  </appSettings>

</configuration>

Tried this code in the main form
  Dim dbLocation As String
        dbLocation = ConfigurationSettings.AppSettings("DatabaseLocation")
but i get:
Name 'configuration settings' is not declared.

Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of doobdave
doobdave

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of matt_swinburne
matt_swinburne

ASKER

Unfortunatley it uses the configurationsettings and so i am still gettign the same error.  From what i have read you shouldnt have to declare configurationsettings and it should be auto generated by .net at some point?
Is that the EXACT error msg you're getting? I only ask 'cos there seems to be a space between "configuration" and "settings"...
what do you mean seems to be a space?  I cant see one?  (Copied and pasted your line in and said same thing)

dbLocation = Configuration.ConfigurationSettings.AppSettings.Item("DatabaseLocation")

thanks for the help
Where you outline the error msg you receive:
"Name 'configuration settings' is not declared."

Is this the EXACT error message you get when you attempt to run your code?
Or do you get a blue line under your code with the message you specify appearing in the task list?
If not, please provide the exact message, as this could give us a clue as to what the problem may be.
Hi Doob i have solved the problem now but thanks for your help neway
Ok,
maybe you can post how you solved it so that others who may encounter the same problem in the future will be able to get a solution... up to you, otherwise ask tech support to delete this question and refund your points.

Regards,
David
I used the following code to bind my db;

Dim dbLocation As String

        dbLocation = System.Configuration.ConfigurationSettings.AppSettings("DatabaseLocation")
       

        OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Database Password=;Data Source=" & dbLocation & ";Password=;Jet OLEDB:Engine Type=5;Jet OLEDB:Global Bulk Transactions=1;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:New Database Password=;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Encrypt Database=False"



And in my config file i used the following code;

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="DatabaseLocation" value= "C:\Documents and Settings\matthewm\Desktop\Project\Actual\Actual.mdb"/>
</appSettings>
</configuration>


Hope this helps anyone with similar problems