Asp.net global connection string to access database

  • Thread starter Thread starter Colin Graham
  • Start date Start date
C

Colin Graham

i am currently developing an asp.net web application which is linked
to an Access database.

The main problem that i have is in creating a global connection string
that i can use. When i put my string into either the appsettings or a
global settings module i get an error on the server.mappath part of
the string. how can i get round this as i dont want to have to use a
specific path for the web application. it seems that this should be
easy as i can use a relative path in other parts of the system.

I suppose i could set a session state value or application state value
on start up but i hope someone can shed some light on my issue.

thanks in advance

C
 
Colin,
Try this.
In your webconfig:
<appSettings>
<add key="DBPath" value="db/file.mdb" />
</appSettings>
And simply use this function:
Private Function GetConnectionString() As String
Dim strPath As String = System.Configuration.ConfigurationSettings.
AppSettings("DBPath")
Return Server.MapPath(strPath)
End Function

Or anything simular,
Hope this helps
-Jeff
4/4/2005 6:01:35 PM
 
Back
Top