Path to access DB

T

Thomas Makro

Hi everybody.

I need to have several aspx files, each with access to the same MS
Access database.

So, I could hardcode the path to the .MDB file in every aspx file, but
this would only work on my local machine, since the production web
server has the webfiles (including the MDB file), elsewhere, ie. on
e:\web\customer123\databases, where I have the .MDB files in
C:\Inetpub\wwwroot\somefolder\db.

Therefore, I want to use relative paths using server variables, like
this:
Dim strDBpath As String = GetServerVariable("APPL_PHYSICAL_PATH") &
"db\mydb.mdb"
This I can hardcode in every aspx file, but there has to be a smarter
way, so that I only have this code in one file, where all the aspx
files can access it.

The WEBconfig seems ideal for this, but it doesn't allow code, so how
do I do this?


Regards,
Thomas
 
G

Guest

Hi Thomas,

How about using DSN ? You keep your db anywhere in your system....you've to
create a DSN for that MDB...and refer that DSN name in your application where
every you want.

Cheers,

Jerome. M
 
M

Mark Rae

Dim strDBpath As String = GetServerVariable("APPL_PHYSICAL_PATH") &
"db\mydb.mdb"
This I can hardcode in every aspx file, but there has to be a smarter
way, so that I only have this code in one file, where all the aspx
files can access it.

Since you're using VB.Net, can't you just define a public variable in a code
module?
 
T

Thomas Makro

Hi Jerome.

I don't have access to the production server by other means than FTP,
so I cannot create a system DSN. Furthermore, I can't get the server
admin to create it, because it isn't supported by the webhosting
company.

Regards,
Thomas
 
R

Riki

Thomas said:
Hi everybody.

I need to have several aspx files, each with access to the same MS
Access database.

So, I could hardcode the path to the .MDB file in every aspx file, but
this would only work on my local machine, since the production web
server has the webfiles (including the MDB file), elsewhere, ie. on
e:\web\customer123\databases, where I have the .MDB files in
C:\Inetpub\wwwroot\somefolder\db.

Therefore, I want to use relative paths using server variables, like
this:
Dim strDBpath As String = GetServerVariable("APPL_PHYSICAL_PATH") &
"db\mydb.mdb"
This I can hardcode in every aspx file, but there has to be a smarter
way, so that I only have this code in one file, where all the aspx
files can access it.

The WEBconfig seems ideal for this, but it doesn't allow code, so how
do I do this?

Since the connection string has two parts, just store them separately
in web.config:
<add key="strConn1" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" />
<add key="strConn2" value="db\mydb.mdb" />

Then, use this code in all your pages to retrieve the entire string:
Dim strConn As String=ConfigurationSettings.AppSettings("strConn1") &
Server.MapPath(ConfigurationSettings.AppSettings("strConn2")
 
E

Elton Wang

Hi Thomas,

You can have public readonly property in codebehind of
Global.aspx.

Public ReadOnly Property DbPath() As String
Get
Return (dbpath)
End Get
End Function

So you can call it in any page within the application.

HTH

Elton Wang
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top