Results 1 to 2 of 2

Thread: application configuration file

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    145

    application configuration file

    Hi all,

    Can anybody share me how to define the connection string in the config file. I tried but I keep on getting this error:

    The ConnectionString property has not been initialized.

    I made use of the web.config in asp.net successfully but I couldn't get this to work in windows forms.

    Please help.

    Marivic

  2. #2
    Addicted Member
    Join Date
    Mar 2001
    Location
    Devon, UK
    Posts
    181
    Here is my app.config file
    <?xml version="1.0" encoding="Windows-1252"?>
    <configuration>
    <appSettings>
    <add key="ConnectionString" value="initial catalog=SP;data source=******;user id=sa;password=*******" />
    <add key="Version" value="1.21" />
    </appSettings>
    </configuration>

    I then access it in my variables class - make sue you import System.Configuration

    Private Shared m_sConnStr As String = ConfigurationSettings.AppSettings("ConnectionString")
    Private Shared m_sVersion As String = ConfigurationSettings.AppSettings("Version")

    Imports System.Configuration
    Public Class cVariables
    Public Shared ReadOnly Property ConnStr() As String
    Get
    Return m_sConnStr
    End Get
    End Property

    Public Shared ReadOnly Property Version() As String
    Get
    Return m_sVersion
    End Get
    End Property

    End class
    Wind and waves resolves all problems.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width