tags:

views:

39

answers:

3

This is for a Windows Application.

In a class I want to referee to my connectionstring called freighthelper which is located in the settings.settings file in my project. How do I do this?

I have tried with this without success.

_connection.ConnectionString = FreightHelper.Properties.Settings.Default.freighthelper; 
A: 

try this: _connection.ConnectionString=Settings.Default. freighthelper; to read form a setting files.

NOte: connection string better to place in App.confing

E.g:

<connectionStrings>
    <add name="Name" connectionString="Data Source=Instance Name;Integrated Security=True;MultipleActiveResultSets=True;"
      providerName="System.Data.EntityClient" />
anishmarokey
+1  A: 

Hi,

Why do you need to store your connection string in a settings file? It is usually put in the config file and retrieved like this: http://msdn.microsoft.com/en-us/library/ms254494%28VS.80%29.aspx

GôTô
It seams like my connectionstring already is stored in the config file like this.
hejahv
A: 

It seams like my connectionstring already is stored in the config file like this.

 <connectionStrings>
    <add name="FreightHelper.Properties.Settings.freighthelper" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=&quot;S:\Gemensamt\FRAKTER\Freight Helper\Db\freighthelper.accdb&quot;"
        providerName="System.Data.OleDb" />
</connectionStrings>

But when I try to do like the example "Example: Retrieving a Connection String by Provider Name" it get error that I'm missing namespaces. What kind of namespaces shall I use for ConnectionStringSettingsCollection etc.?

hejahv
You should add this to your original question, if you want to increase your chance of getting a response.
Simpzon