General discussion

Locked

link to dabase through VBscript

By fhiray ·
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

This conversation is currently closed to new comments.

6 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

link to dabase through VBscript

by hclarius In reply to link to dabase through VB ...

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 "<OPTION VALUE=" & recordSet("field") & ">" & trim(recordSet("PLANT"))
recordSet.MoveNext
Loop
Response.Write("</SELECT>")
'CLOSE DATABASE AND FREE Connection
connectionToDatabase.Close
Set connectionToDatabase=Nothing
%>
Hope I'm not to far off

Collapse -

link to dabase through VBscript

by fhiray In reply to link to dabase through VB ...

Poster rated this answer

Collapse -

link to dabase through VBscript

by Mark Fenwick In reply to link to dabase through VB ...

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") & "<br>")
adoRS.MoveNext
Loop
End If

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

%>

Collapse -

link to dabase through VBscript

by fhiray In reply to link to dabase through VB ...

Poster rated this answer

Collapse -

link to dabase through VBscript

by fhiray In reply to link to dabase through VB ...

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;

Collapse -

link to dabase through VBscript

by fhiray In reply to link to dabase through VB ...

This question was closed by the author

Back to Web Development Forum
6 total posts (Page 1 of 1)  

Related Discussions

Related Forums