all groups > vb.net data > august 2006 >
You're in the

vb.net data

group:

Accessing connections strings in web.config


Accessing connections strings in web.config Henry
8/13/2006 12:00:00 AM
vb.net data: Hi

Is it possible to access connections strings from web.config from within the
application?

I'm using VS2005 and VB


Sub LogVisit(ByVal network As String, ByVal IsValidNetwork As Boolean)
Dim sqlCmd As SqlCommand
Dim sqlcn As SqlConnection

'this on works, it's a public variable
sqlcn = New SqlConnection(c_cnstr)

'this on doesn't work, it's a connectionstring from web.config
'sqlcn = New SqlConnection(FSBConnectionString)


sqlCmd = New SqlCommand(GetCommand( _
Request.PhysicalApplicationPath + c_scriptDirectory +
"c_insLogVisit.sql"), sqlcn)
sqlcn.Open()
Try

'bla bla bla

Finally
sqlcn.Close()
End Try

End Sub

Re: Accessing connections strings in web.config Jay B. Harlow [MVP - Outlook]
8/13/2006 9:24:19 AM
Henry,
VS 2005 (.NET 2.0) introduced a new connectionStrings section to the
app.config (web.config).

http://msdn2.microsoft.com/en-us/library/bf7sd233.aspx

You can access it via the ConnectionStrings property:

http://msdn2.microsoft.com/en-us/library/system.configuration.configurationmanager.connectionstrings.aspx

http://msdn2.microsoft.com/en-us/library/system.configuration.configurationmanager.connectionstrings.aspx

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


[quoted text, click to view]
| Hi
|
| Is it possible to access connections strings from web.config from within
the
| application?
|
| I'm using VS2005 and VB
|
|
| Sub LogVisit(ByVal network As String, ByVal IsValidNetwork As Boolean)
| Dim sqlCmd As SqlCommand
| Dim sqlcn As SqlConnection
|
| 'this on works, it's a public variable
| sqlcn = New SqlConnection(c_cnstr)
|
| 'this on doesn't work, it's a connectionstring from web.config
| 'sqlcn = New SqlConnection(FSBConnectionString)
|
|
| sqlCmd = New SqlCommand(GetCommand( _
| Request.PhysicalApplicationPath + c_scriptDirectory +
| "c_insLogVisit.sql"), sqlcn)
| sqlcn.Open()
| Try
|
| 'bla bla bla
|
| Finally
| sqlcn.Close()
| End Try
|
| End Sub
|
|

Re: Accessing connections strings in web.config Henry
8/15/2006 9:55:05 PM
[quoted text, click to view]

Thanks, yes that helped!
Henry

AddThis Social Bookmark Button