Discussion Locked

link to dabase through VBscript

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

I have used my Personal Web Server and macromedia's ultradev to created asp search and results pages that are linked to an access database.... and it worked fine... but I don't know how to change the code so that it has to connect to a database onceI upload everything to the server... ultradev prepares an include file .

so my two questions are:

1. what is the necessary code to link the database to the pages without specifying a path for the database.
2. I am using asp pages and accessdatabase, so what should the server have to safely process these pages.

Thank you
Fatima

6 replies

by hclarius

If you have the appropriate access or the SA will do it for you, you could set up a "system" DSN through the ODBC administrator. then use the DSN to connect:
code snippet
<%
Dim SQL
SQL=Request.Form("sql_statement")
'CONNECT TO DATABASE AND EXECUTE SQL STATEMENT
Set connectionToDatabase=Server.CreateObject("ADODB.Connection")
connectionToDatabase.ConnectionTimeOut=50
connectionToDatabase.Open "DSN=your.dsn.here"
Set recordSet=Server.CreateObject("ADODB.Recordset")
recordSet.Open SQL, connectionToDatabase
'CREATE LIST
Do while Not recordSet.EOF
Response.Write "" & trim(recordSet("PLANT"))
recordSet.MoveNext
Loop
Response.Write("")
'CLOSE DATABASE AND FREE Connection
connectionToDatabase.Close
Set connectionToDatabase=Nothing
%>
Hope I'm not to far off

by mark fenwick

It is hard to tell exactly what you are after but, assuming your web server is based on IIS, it sounds like you may need to create a System Data Source (DSN) and connect to it programmatically.

1) Use the OSBC manager to create a System Data Source connection to your Access database. System DSNs are better on a web server as they are not dependant on who the logged on user is.

2) Have a look at the code below which uses Microsoft's ActiveX Data Objects (ADO) to connect to a DSN called Projects and display the 'TaskID' field for every record in a table called 'Tasks'

Hope this helps

Mark

<%

Dim adoCN, adoRS

' Create an ADO Connection object instance
Set adoCN = CreateObject("ADODB.Connection") ' Create an ADO Recordset object instance
Set adoRS = CreateObject("ADODB.Recordset")

' Open a connection to the database
adoCN.Open "Projects" ', UserName, Password

' Create a redordset containing the entire Tasks table
adoRS.Open "SELECT * FROM Tasks", adoCN

' If the record set is not empty parse it outputting TaskID field to a web page
If Not adoRS.BOF And Not adoRS.EOF Then
Do While Not adoRS.EOF
Response.Write (adoRS.Fields("TaskID") & "
")
adoRS.MoveNext
Loop
End If

' Clean up after we are done
adoRS.Close
adoCN.Close
Set adoRS = Nothing
Set adoCN = Nothing

%>

by fhiray

Sorry; I should have been more specific..

I want to place the database and asp pages on one of the free homepages sites... so I don't have the option of contacting the administrator to set-up a DSN-less connection is what I am looking... I don'thave a clear picture of the process itself so I might sound a little bit off.

I am assuming you could do a DSN-less connection on a server.. I am also assuming that the connection could be made regardless of the the application/web server used...does this sound logical? if so what is then the connection method and code?

Kind regards;

This discussion is closed to new replies.