Where to store to connecting string in WinForm Application

  • Thread starter Thread starter ad
  • Start date Start date
A

ad

We usually store the connection string of Web Applicaiton in Web.Config.
Now I want to develop WinForm Application.
Where is the better place to store the conneciton string?
 
Hello,

Store the Connection String in de app.config. But don't forget to encrypt
the app.config or the connectionsting alone.

Yours,

Mark Monster
 
Can u share your simple encrypt and decrypt functions as .NET's cryptro so
complex for me?
 
Unless he has password in the connection string, he probably does not need
to encrypt it.
 
I have store my connection string in ap.config, like:
<configuration>
<appSettings/>
<section name="microsoft.visualstudio.testtools"
type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection,
Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=8.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<connectionStrings>
<add name="myDataBase" connectionString="Data Source=.\;Initial
Catalog=SchoolGov;Integrated Security=True" />
</connectionStrings>
</configuration>

How can I read the connectionString into my applicaton?
 
In Web.Config add
<add key="ConnectionString"
value="server=(local);database=YOURDATABASE;integrated security=true;" />
And in your code use:-
Public conn As New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Hope that helps
Patrick
 
Back
Top