Discussion Locked

ASP: How to access database

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

ASP: How to access database which is located on different computer?

hi

I am trying to create a web page which access information from the MS Access
database. Currently i have the database adn teh application on teh same computer. But I want to have my database on seprate computer.
So in order to connect my web page to the database in different computer..what is the process involved here. I think i need to do readings on
DCOM. Any feedback will be helpful? any good sites that you can recommend to read....etc etc.

Thanks,
Sukhi

7 replies

by e1nstein

Hi,

The easiest way would be to utilize the Windows UNC. You can refer the Access database file on other computer by using:
"\\\\"

If that does not suit your needs, than you might need the DCOM. Basically, you have to create a COM ActiveX that reads the Access file and put it on the machine where the database file resides. And then use MTS to declare that particular COM ActiveX to be used in your web server machine. And in your ASP you just have to call the function of the COM ActiveX.

Hope this help.

Adi

by chrandrob

Forget DCOM, that's a much more advanced topic than what you are looking for. Get a good book or visit a good site on ADO.

Basically, there are two ways to make an ADO connection to an Access database. Like this:

1) Set MyConn = Server.CreateObject("ADODB.Connection")
MdbFilePath = "\\ServerName\PathData\database.mdb"
MyConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"

2) Create a DSN to the database on the computer where the website is hosted by going tothe Data Sources in the Control Panel. Then the connection can be made like this:

Set MyConn = Server.CreateObject("ADODB.Connection")
MyConn.Open "DSN=DSN-Name;"

by tg_willis

I agree with answer #2. You want to keep your dependencies on dbs relatively thin so that your application can adapt as requirements change(more easily move from access to SQL Server to Oracle to DB2 ro what have you). Get comfortable using ADO and open your connections based on conection strings. Then when you're ready to move the app to SQL Server, all you do is change the connection string and Voila(almost anyway). You may also think about encapsulating all db access into a generic COM compontent that your Web page uses.

2 methods is all you need
public RecordSet OpenSQL(string ConnectionString,string SQL)

public void ExecSQL(string ConnectionString,string SQL)

Once you get that working, you can pretty much hit any db that ADOcan get to with one component. It should prove to be a very useful component.

Another thing to think about, perhaps another component to handle connection strings that maybe are stored in the registry or Active Directory, so that an administratorcan configure the connection without recompiling code. This comes in pretty handy when you have to migrate between Development and production.

My .02

Tom

This discussion is closed to new replies.