0

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; 
4
  • That's the correct way to do it. What problem are you seeing? Any error message? Commented Sep 24, 2010 at 6:06
  • 1
    Does it work if your remove that first FreightHelper? Commented Sep 24, 2010 at 6:07
  • if that code compiles, then the setting must exist. You should explain more details about "without success": Was the ConnectionString wrong or empty after trying to get it (probably easy to solve)? Or did you just not succeed in connecting to the database (much more possibilities for errors)? Commented Sep 24, 2010 at 7:01
  • Sorry, the code was correct but the problem was that I used code for SQL-database instead of OleDb. You got me to realize this, thanks. Commented Sep 24, 2010 at 7:22

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

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

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" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.