2009-12-07 8 views
2

누구나 샘플 코드를 제공하여 app.config 파일을 VB.NET으로 작성된 응용 프로그램과 통합하는 방법을 보여줄 수 있습니까? 특히 app.config 파일에서 데이터베이스 연결 문자열을 추출해야합니다.VB.NET 샘플 app.config 액세스

답변

1

참조 :

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