views:

498

answers:

3

Could anybody supply a sample code, showing how to integrate the app.config file with an application written in VB.NET. Specifically I need to extract database connect strings from the app.config file.

+1  A: 

Have a look at these links

Grabbing connectionString from App.config

and

Get connection string from app.config

astander
A: 

See:

Public Shared Function GetConnectionString(ByVal strConnection As String) As String
   'Declare a string to hold the connection string
   Dim sReturn As New String("")
   'Check to see if they provided a connection string name
   If Not String.IsNullOrEmpty(strConnection) Then
      'Retrieve the connection string fromt he app.config
      sReturn = ConfigurationManager. & _
      ConnectionStrings(strConnection).ConnectionString
   Else
      'Since they didnt provide the name of the connection string
       'just grab the default on from app.config
      sReturn = ConfigurationManager. & _
      ConnectionStrings("YourConnectionString").ConnectionString
   End If
   'Return the connection string to the calling method
   Return sReturn
End Function
Brij
A: 

Someone please add the config file along and pls specify which *version of framewor*k you ae using

sandeep pal