How to write Connection String In App.Config File?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GR M
    New Member
    • Dec 2010
    • 19

    How to write Connection String In App.Config File?

    Hi..
    I want to write the connection string of my application in app.config file. I dont know how to write it or how to dynamically change it from my application source code either. My App.config file shows like..
    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <system.diagnostics>
            <sources>
                <!-- This section defines the logging configuration for My.Application.Log -->
                <source name="DefaultSource" switchName="DefaultSwitch">
                    <listeners>
                        <add name="FileLog"/>
                        <!-- Uncomment the below section to write to the Application Event Log -->
                        <add name="EventLog"/>
                    </listeners>
                </source>
            </sources>
            <switches>
                <add name="DefaultSwitch" value="Information" />
            </switches>
            <sharedListeners>
                <add name="FileLog"
                     type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" 
                     initializeData="FileLogWriter"/>
                <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
                <add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="Medicine_Management_System"/> 
            </sharedListeners>
        </system.diagnostics>
    </configuration>
    My Connection string is like this..
    Code:
    Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\User5\My Documents\Medicine_Stores_Management.accdb; User Id=Admin; Password=
    So plz help me this out.
    Thanks in advance.
  • David Gluth
    New Member
    • Oct 2010
    • 46

    #2
    Go to your applications property page.
    Select Settings.
    Give it a name, select connection string and enter you connection sting as the value. When you save the application it will be added to app config for you.
    I would end the string at accdb; the in code append “User ID=Admin; Password=xxx” to the end of myCN

    Comment

    Working...