Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADODB connection

Status
Not open for further replies.

PFairhurst

Programmer
Jul 30, 2002
18
GB
I have a web page which loads up information from an Access database with an ADODB connection, but everytime I load up the page it asks me whether I want to connect to the database. Is there a way to do this automatically and not have to click on 'Yes' everytime I load the page up?

Any help would be great. Thanks
Pete
 
This code uses odbc, but it might help you. Also here is a link to some examples.

Set Conn = Nothing
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.ConnectionTimeout = 300
Conn.Open "dsn=dsnname",
"username",
"password"
Set rs=Server.CreateObject("ADODB.Recordset")


Don't forget to close what you open.

cornboy88
[noevil]
 
Sorry, should have put this in my first message. My connection connects fine and loads up of the correct information from my recordsets but when I first load up the page I get 'This page is accessing a data source on another domain. Do you want to allow this?' and I do but I want to do it automatically without clicking yes everytime.
Pete
 
give up the code PFairhurst, I help at your own risk, if I brake it sorry! But if I fixed it, let me know with a
star.gif
[thumbsup2]
admin@onpntwebdesigns.com
 
Here's the code for my database connection

<html>
<head>
<title>Planner</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<script type=&quot;text/vbscript&quot;>
dim rsSet
dim rsWeek1
dim rsWeek2
sub loadDB ()
set cnn = CreateObject(&quot;ADODB.connection&quot;)
cnn.Provider = &quot;Microsoft.Jet.OLEDB.4.0&quot;
cnn.open &quot;\\hill\vb\emp.mdb&quot;
set rsSet = CreateObject(&quot;ADODB.recordset&quot;)
rsSet.CursorType = adOpenDynamic
rsSet.open &quot;Employees&quot;,cnn
set rsWeek1 = CreateObject(&quot;ADODB.recordset&quot;)
rsWeek1.activeConnection = cnn
rsWeek1.LockType = 4
rsWeek1.CursorType = adOpenDynamic
rsWeek1.open &quot;week1&quot;,cnn
set rsWeek2 = CreateObject(&quot;ADODB.recordset&quot;)
rsWeek2.CursorType = adOpenDynamic
rsWeek2.LockType = 4
rsWeek2.open &quot;week2&quot;,cnn
end sub
 
are you trying to do this on the client side script?

Can't do it that way. has to be a server side scripting.

looks like all you need to do is change the <script tags to <% %> and save the page as a .asp I help at your own risk, if I brake it sorry! But if I fixed it, let me know with a
star.gif
[thumbsup2]
admin@onpntwebdesigns.com
 
Can't seem to get it to work. Do you mean to change
<script type=&quot;text/vbscript&quot;>
</script>

to

<%

%>?

 
yes but there's a little more to it then that.

In order to test asp pages you will need to have IIS installed or PWS. then you will need to test the pages from the folder.

Go to administrative tools in your control panel and see if you have a icon for IIS ()internet information services) if you do not you will need to install this with your windows installation cd via add/remove programs.

let me know if you need assistance with that. What OS are you running? I help at your own risk, if I brake it sorry! But if I fixed it, let me know with a
star.gif
[thumbsup2]
admin@onpntwebdesigns.com
 
I've tried what you said (I think!) and it's not connecting to the database anymore. I'm pretty new to VBscript and haven't quite got the hang of it yet. Can you see if it is something to do with my code. Thanks for all your help.
Pete

<html>
<head>
<title>Planner</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<% type=&quot;text/vbscript&quot;

dim rsSet
dim rsWeek1
dim rsWeek2
sub awayLoad ()
if monAMaway.value = &quot;&quot; then
msgbox &quot;Away text box is empty please fill it in&quot;,64
Exit sub
End if
monPMaway.value = monAMaway.value
tueAMaway.value = monAMaway.value
tuePMaway.value = monAMaway.value
wedAMaway.value = monAMaway.value
wedPMaway.value = monAMaway.value
thursAMaway.value = monAMaway.value
thursPMaway.value = monAMaway.value
friAMaway.value = monAMaway.value
friPMaway.value = monAMaway.value
End sub
sub loadDB ()
set cnn = CreateObject(&quot;ADODB.connection&quot;)
cnn.Provider = &quot;Microsoft.Jet.OLEDB.4.0&quot;
cnn.open &quot;\\hill\vb\emp.mdb&quot;
set rsSet = CreateObject(&quot;ADODB.recordset&quot;)
rsSet.CursorType = adOpenDynamic
rsSet.open &quot;Employees&quot;,cnn
set rsWeek1 = CreateObject(&quot;ADODB.recordset&quot;)
rsWeek1.activeConnection = cnn
rsWeek1.LockType = 4
rsWeek1.CursorType = adOpenDynamic
rsWeek1.open &quot;week1&quot;,cnn
set rsWeek2 = CreateObject(&quot;ADODB.recordset&quot;)
rsWeek2.CursorType = adOpenDynamic
rsWeek2.LockType = 4
rsWeek2.open &quot;week2&quot;,cnn
end sub
sub allClick()

if allWeek(0).checked Then
monAM.value = &quot;away&quot;
monPM.value = &quot;away&quot;
tueAM.value = &quot;away&quot;
tuePM.value = &quot;away&quot;
wedAM.value = &quot;away&quot;
wedPM.value = &quot;away&quot;
thursAM.value = &quot;away&quot;
thursPM.value = &quot;away&quot;
friAM.value = &quot;away&quot;
friPM.value = &quot;away&quot;

End if
if allWeek(1).checked Then
monAM.value = &quot;holiday&quot;
monPM.value = &quot;holiday&quot;
tueAM.value = &quot;holiday&quot;
tuePM.value = &quot;holiday&quot;
wedAM.value = &quot;holiday&quot;
wedPM.value = &quot;holiday&quot;
thursAM.value = &quot;holiday&quot;
thursPM.value = &quot;holiday&quot;
friAM.value = &quot;holiday&quot;
friPM.value = &quot;holiday&quot;
End if
if allWeek(2).checked Then
monAM.value = &quot;home&quot;
monPM.value = &quot;home&quot;
tueAM.value = &quot;home&quot;
tuePM.value = &quot;home&quot;
wedAM.value = &quot;home&quot;
wedPM.value = &quot;home&quot;
thursAM.value = &quot;home&quot;
thursPM.value = &quot;home&quot;
friAM.value = &quot;home&quot;
friPM.value = &quot;home&quot;
End if
if allWeek(3).checked Then
monAM.value = &quot;office&quot;
monPM.value = &quot;office&quot;
tueAM.value = &quot;office&quot;
tuePM.value = &quot;office&quot;
wedAM.value = &quot;office&quot;
wedPM.value = &quot;office&quot;
thursAM.value = &quot;office&quot;
thursPM.value = &quot;office&quot;
friAM.value = &quot;office&quot;
friPM.value = &quot;office&quot;
End if

End sub
sub displayRes

if monAll.checked Then
monPM.value = monAM.value
monPMaway.value = monAMaway.value
End if
if tueAll.checked Then
tuePM.value = tueAM.value
tuePMaway.value = tueAMaway.value
End if
if wedAll.checked Then
wedPM.value = wedAM.value
wedPMaway.value = wedAMaway.value
End if
if thursAll.checked Then
thursPM.value = thursAM.value
thursPMaway.value = thursAMaway.value
End if
if friAll.checked Then
friPM.value = friAM.value
friPMaway.value = friAMaway.value
End if

End sub
Function returnValue (strName,strAway)
if strAway = &quot;home&quot; Then
returnValue = &quot;home&quot;
Exit Function
End if
if strAway = &quot;holiday&quot; Then
returnValue = &quot;holiday&quot;
Exit Function
End if
if strAway = &quot;office&quot; Then
returnValue = &quot;office&quot;
Exit Function
End if
if strAway = &quot;away&quot; Then
select case (strName)
case &quot;mon am&quot;
returnValue = monAMaway.value
case &quot;mon pm&quot;
returnValue = monPMaway.value
case &quot;tues am&quot;
returnValue = tueAMaway.value
case &quot;tues pm&quot;
returnValue = tuePMaway.value
case &quot;wed am&quot;
returnValue = wedAMaway.value
case &quot;wed pm&quot;
returnValue = wedPMaway.value
case &quot;thurs am&quot;
returnValue = thursAMaway.value
case &quot;thurs pm&quot;
returnValue = thursPMaway.value
case &quot;fri am&quot;
returnValue = friAMaway.value
case &quot;fri pm&quot;
returnValue= friPMaway.value
case else
returnValue = &quot;away&quot;
End select
End if

End Function
Function check_pin(pin)
check_pin = false
if cdbl(pin) = cdbl(code.value) Then
check_pin = true
end if
End Function
sub submit_OnClick()
strNo = searchExec(nameSelect.value)
if check_pin(rsSet(&quot;pin number&quot;)) = false Then
msgbox &quot;Pin Code Invalid&quot;,64
Code.value = &quot;&quot;
Exit sub
End if
Code.value = &quot;&quot;
if Cstr(rsWeek1(&quot;date&quot;)) = weekselect.options(0).value Then

searchWeek(strNo)
rsWeek1(&quot;mon am&quot;) = returnValue (&quot;mon am&quot;,monAM.value)
rsWeek1(&quot;mon pm&quot;) = returnValue (&quot;mon pm&quot;,monPM.value)
rsWeek1(&quot;tues am&quot;) = returnValue (&quot;tues am&quot;,tueAM.value)
rsWeek1(&quot;tues pm&quot;) = returnValue (&quot;tues pm&quot;,tuePM.value)
rsWeek1(&quot;wed am&quot;) = returnValue (&quot;wed am&quot;,wedAM.value)
rsWeek1(&quot;wed pm&quot;) = returnValue (&quot;wed pm&quot;,wedPM.value)
rsWeek1(&quot;thurs am&quot;) = returnValue (&quot;thurs am&quot;,thursAM.value)
rsWeek1(&quot;thurs pm&quot;) = returnValue (&quot;thurs pm&quot;,thursPM.value)
rsWeek1(&quot;fri am&quot;) = returnValue (&quot;fri am&quot;,friAM.value)
rsWeek1(&quot;fri pm&quot;) = returnValue (&quot;fri pm&quot;,friPM.value)
rsWeek1.UpdateBatch
msgbox &quot;Successfully Updated&quot;,64
Else
searchWeekA(strNo)
rsWeek2(&quot;mon am&quot;) = returnValue (&quot;mon am&quot;,monAM.value)
rsWeek2(&quot;mon pm&quot;) = returnValue (&quot;mon pm&quot;,monPM.value)
rsWeek2(&quot;tues am&quot;) = returnValue (&quot;tues am&quot;,tueAM.value)
rsWeek2(&quot;tues pm&quot;) = returnValue (&quot;tues pm&quot;,tuePM.value)
rsWeek2(&quot;wed am&quot;) = returnValue (&quot;wed am&quot;,wedAM.value)
rsWeek2(&quot;wed pm&quot;) = returnValue (&quot;wed pm&quot;,wedPM.value)
rsWeek2(&quot;thurs am&quot;) = returnValue (&quot;thurs am&quot;,thursAM.value)
rsWeek2(&quot;thurs pm&quot;) = returnValue (&quot;thurs pm&quot;,thursPM.value)
rsWeek2(&quot;fri am&quot;) = returnValue (&quot;fri am&quot;,friAM.value)
rsWeek2(&quot;fri pm&quot;) = returnValue (&quot;fri pm&quot;,friPM.value)
rsWeek2.updateBatch
msgbox &quot;Successfully Updated&quot;,64
End if

End sub

Function searchExec (name)
strPos = InStr(name,&quot; &quot;)
surname = Right(name,Len(name) - strPos)
first = Left(name, strPos)
rsSet.moveFirst
do
if rsSet(&quot;LastName&quot;) = Trim(surname) AND rsSet(&quot;FirstName&quot;) = Trim(first) Then
searchExec = rsSet(&quot;EmployeeNumber&quot;)
Exit Function
End if
rsSet.moveNext
loop until rsSet.EOF
searchExec = 0

End Function

sub searchWeek(strNo)
rsWeek1.MoveFirst
do
if rsWeek1(&quot;EmployeeNumber&quot;) = strNo Then
Exit sub
End if
rsWeek1.moveNext
loop until rsWeek1.EOF

End sub
sub searchWeekA(strNo)

rsWeek2.moveFirst
do
if rsWeek2(&quot;EmployeeNumber&quot;) = strNo Then
Exit sub
End if
rsWeek2.moveNext
loop until rsWeek2.EOF

End sub
%>
</head>
 
this is what you need to do.
I'm assuming this is only intended for IE users seeing as you are using client side vbscript for your validation.

first thing
you cannot use the msgbox function via server side.

take this line out of the <% %> type=&quot;text/vbscript&quot;
asp defaults to VBScript

Take all of your validation and place it in your form checking the conditions that need to be met in order to submit the form. You can use the msgbox function via client side.

You cannot reference the record set information unless you connect to the database in the beginning of the page. Not neccesary though as you'll see in a minute

take all of the server side code that is to be run. (all code within the <% %>
save it as a seperate file with the .asp extension.

place in your form tag the action attribute
<form method=&quot;post&quot; action=&quot;db.asp&quot; onSubmit=&quot;do val first()&quot;>

still with me?[lol]

here's the syntax of what you are doing
form filled out by user -->
validation is run via client side and returns false on conditions -->
all good submit values to DB and run the DB.asp to insert etc.-->
here's where if you need to do any validation while submiting to the DB comes in.
If you have a condition that is not met or met in error do
<%
Response.write &quot;A error has occured, check entries!&quot;
Response.write(&quot;<input type='button' value='OK'&quot;)
Response.write(&quot;onClick='vbscript:history.go(-1)'>&quot;)
or you can use
Response.redirect &quot;form.asp&quot;

this writes the the page A error has occured, check entries! and on clicking the OK button sends them back to the form or the last page to correct as needed.

I'll take a look at the code and change it in a bit and post it if you havn't done so already. Got to work though!

hope that helps I help at your own risk, if I brake it sorry! But if I fixed it, let me know with a
star.gif
[thumbsup2]
admin@onpntwebdesigns.com
 
try this to open the DB
cnn.open &quot;Driver=Microsoft Access Driver (*.mdb); DBQ=&quot; & server.mappath(&quot;\hill\vb\emp.mdb&quot;)& &quot;;&quot;

remember though to test this on IIS you need to exact path on your system then change to the server path when uploading
so

on your system
cnn.open &quot;Driver=Microsoft Access Driver (*.mdb); DBQ=&quot; & server.mappath(&quot;C:\hill\vb\emp.mdb&quot;)& &quot;;&quot; I help at your own risk, if I brake it sorry! But if I fixed it, let me know with a
star.gif
[thumbsup2]
admin@onpntwebdesigns.com
 
Thank you! You've solved most of my problems and it's starting to look better, but when I load up the db.asp (the server side) it doesn't connect to the database it just says
'[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified'

so I then used microsft jet as the provider and I got the message 'Could not find installable ISAM'. Sorry to be such a pain. Pete
 
teh only time I've ever seen this error or actually jsut heard of it is a result in the driver files missing for access.

try reinstalling access or office.

you can also try putting the DB in the folder with the asp page. Just in case the path is incorrect. then all you need is
cnn.open &quot;Driver=Microsoft Access Driver (*.mdb); DBQ=&quot; & server.mappath(&quot;\emp.mdb&quot;)& &quot;;&quot; I help at your own risk, if I brake it sorry! But if I fixed it, let me know with a
star.gif
[thumbsup2]
admin@onpntwebdesigns.com
 
you can also try this conenction string.
cnn.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0; Data Source=&quot; & Server.MapPath(&quot;\emp.mdb&quot;) & &quot;;&quot;

this is also a dsn-less connection string I help at your own risk, if I brake it sorry! But if I fixed it, let me know with a
star.gif
[thumbsup2]
admin@onpntwebdesigns.com
 
Finally got a connection string that SEEMS to connect in

set conn = Server.CreateObject(&quot;ADODB.connection&quot;)
conn.open &quot;DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=\\hill\vb\emp.mdb; DefaultDir=\\hill\vb; uid=sa;pwd=;DriverID=25;FIL=MSAccess;&quot;
set rsSet = server.CreateObject(&quot;ADODB.recordset&quot;)
rsSet.open &quot;Employees&quot;, conn
set rsWeek1 = server.CreateObject(&quot;ADODB.recordset&quot;)
set rsWeek2 = server.CreateObject(&quot;ADODB.recordset&quot;)
rsWeek1.LockType = adLockBatchOptimistic
rsWeek2.LockType = adLockBatchOptimistic
rsWeek1.open &quot;week1&quot; , conn
rsWeek2.open &quot;week2&quot; , conn

but .LockType = adLockBatchOptimistic does not seem to be recognised. Is this anything to do with the connection or just VBscript? If so, is there any other way of saving changes to the database? Aslo, how do I access the variable from the client side form in the server side asp file?
Any help would be great, thank you.
Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top