Following function can get the connection string from web.config file. Please let me know your comments if it helped and saved your time. Thanks
Public Shared Function GetConnectionString() As String
Dim settings As ConnectionStringSettingsCollection = ConfigurationManager.ConnectionStrings
' Return No connection string found if there is nothing found
Dim Constr = "No ConnectionString Found"
If Not settings Is Nothing Then
For Each cs As ConnectionStringSettings In settings
If cs.Name = "XYZConnectionString" Then
Constr = cs.ConnectionString
Exit For
End If
Next
End If
Return Constr
End Function
No comments:
Post a Comment