|
| |
|
|
DesiMcK
Posts: 446 Joined: 4/26/2004 From: Essex, UK Status: offline
|
Connecting to a db - 5/22/2004 18:26:22
I am using some downloaded code and do not know how to connect to a db. This is the adapted code I am using: Function OpenDB()
Dim cnDB ' As ADODB.Connection
Set cnDB = Server.CreateObject("ADODB.Connection")
cnDB.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=/Deanes/eOrganiser/eOrganiser.mdb;"
cnDB.Open
Set OpenDB = cnDB
End Function It returns the following error: Microsoft JET Database Engine error '80004005'
'C:\Deanes\eOrganiser\eOrganiser.mdb' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
/Deanes/eOrganiser/include.asp, line 29
I am work live inline in FP 2003 and do not understand why the cod eis directing to the c:/ drive???? Desi
|
|
|
|
BeTheBall
Posts: 6381 Joined: 6/21/2002 From: West Point Utah USA Status: offline
|
RE: Connecting to a db - 5/22/2004 18:42:51
Try: Data Source=" & Server.Mappath("/Deanes/eOrganiser/eOrganiser.mdb")
_____________________________
Duane Some people are like Slinkies . . . Not really good for anything . . . . . But they still bring a smile to your face when you push them down a flight of stairs.
|
|
|
|
DesiMcK
Posts: 446 Joined: 4/26/2004 From: Essex, UK Status: offline
|
RE: Connecting to a db - 5/22/2004 18:50:03
I think that worked to connect ... now another error on the index page.. <!--#include file="include.asp" -->
<%
Const ICON_TASK = 1
Const ICON_EVENT = 2
Call Main
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Sub Main
'
' Processing for this page starts in this routine. It
' contains a dispatcher to call the appropriate routine,
' based on what function was needed.
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub Main
Dim cnDB ' As ADODB.Connection
Set cnDB = OpenDB()
If Request("month") = "" Or Request("year") = "" Then
ShowCalendar cnDB, Month(Date), Year(Date)
Else
ShowCalendar cnDB, _
CInt(Request("month")), CInt(Request("year"))
End If
CloseDB cnDB
End Sub The error reads quote:
Object required: 'OpenDB()' This happens on several pages with the same line of code. Desi
|
|
|
|
davids
Posts: 211 Joined: 1/26/2003 From: Belgium (American) Status: offline
|
RE: Connecting to a db - 5/23/2004 11:58:34
If you are trying to use the function above, then just call it: Sub Main
OpenDB()
If Request("month") = "" Or Request("year") = "" Then
ShowCalendar cnDB, Month(Date), Year(Date)
Else
ShowCalendar cnDB, _
CInt(Request("month")), CInt(Request("year"))
End If
CloseDB cnDB
End Sub The last line of your Sub looks a bit off. You should create another Sub/Function to close the connection: Sub CloseDB()
cnDB.Close
Set cnDB = Nothing
End Sub
Then call it at the end: CloseDB()
_____________________________
Davids International Relocation Technology
|
|
|
|
DesiMcK
Posts: 446 Joined: 4/26/2004 From: Essex, UK Status: offline
|
RE: Connecting to a db - 5/23/2004 13:06:20
Thanks for the reply. I now get the error: Variable undefined: 'CnDB' This is the code for the include page where the function resides: <!-- METADATA TYPE="typelib" FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
<!-- METADATA TYPE="typelib" FILE="C:\winnt\system32\scrrun.dll" -->
<%
Option Explicit
Const DQ = """"
Const SQ = "'"
Const ACTION = "a"
Const ACTION_CREATE = "c"
Const ACTION_CREATE_SAVE = "cs"
Const ACTION_UPDATE = "u"
Const ACTION_UPDATE_SAVE = "us"
Const ACTION_DELETE = "d"
Const ACTION_DELETE_SAVE = "ds"
Const ACTION_RETRIEVE = "r"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Function OpenDB
'
' This routine opens up a database connection and returns
' a live database connection to the caller.
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function OpenDB()
Dim cnDB ' As ADODB.Connection
Set cnDB = Server.CreateObject("ADODB.Connection")
cnDB.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" _
& " Data Source=" & Server.Mappath("/Deanes/eOrganiser/eOrganiser.mdb")
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Sub CloseDB
'
' This routine closes the database connection and clears
' the object reference.
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub CloseDB(cnDB)
cnDB.Close
Set cnDB = Nothing
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Sub WriteLine
'
' This routine prints a line of HTML to the browser and
' includes a carriage return/line feed at the end of the
' line. That cleans up the HTML output for debugging
' purposes.
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub WriteLine(strData)
Response.Write strData & vbCrLF
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Sub WriteComment
'
' This routine prints a comment into the HTML output.
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub WriteComment(strData)
WriteLine "<!-- " & strData & " -->"
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Sub PrintHeader
'
' This routine prints the HTML at the top of each
' page in the system. It also includes the toolbar
' on the side of each file.
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub PrintHeader(strTitle)
WriteLine "<html>"
WriteLine "<head><title>eOrganizer - " & strTitle & "</title>"
IncludeFile "styles.css"
WriteLine "</head>"
IncludeFile "toolbar.html"
WriteLine "<span class=ph>" & strTitle & "</span>"
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Sub PrintFooter
'
' This routine prints the HTML at the bottom of each
' page in the system.
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub PrintFooter()
WriteLine "</td></tr></table>"
WriteLine "</body></html>"
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Sub IncludeFile
'
' This routine reads a file and dumps it to the screen. It
' allows for variable names to be included instead of the
' hardcoded names required by the SSI directives.
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub IncludeFile(strFilename)
If strFilename = "" Then Exit Sub
On Error Resume Next
Dim objFSO, objFile, strContents
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = _
objFSO.OpenTextFile(Server.MapPath(strFilename), _
ForReading, False)
strContents = objFile.ReadAll
Response.Write strContents & vbCrLf
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
End Sub
%> And this is the code for the page which uses the function (with your suggested ammendments): <!--#include file="include.asp" -->
<%
Const ICON_TASK = 1
Const ICON_EVENT = 2
Call Main
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Sub Main
'
' Processing for this page starts in this routine. It
' contains a dispatcher to call the appropriate routine,
' based on what function was needed.
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub Main
OpenDB()
If Request("month") = "" Or Request("year") = "" Then
ShowCalendar cnDB, Month(Date), Year(Date)
Else
ShowCalendar cnDB, _
CInt(Request("month")), CInt(Request("year"))
End If
CloseDB cnDB
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Sub ShowCalendar
'
' This routine generates the calendar grid and puts all the
' events into it.
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ShowCalendar(cnDB, intMonth, intYear)
Dim rsEvents ' As ADODB.Recordset
Dim rsTasks ' As ADODB.Recordset
Dim strSQL ' As String
Dim datCurrent ' As Date
Dim intWeekday ' As Integer
Dim intPreviousMonthDays ' As Integer
Dim intCurrentMonthDays ' As Integer
Dim i ' As Integer
Dim intMonthLink ' As Integer
Dim intYearLink ' As Integer
Dim strColor ' As String
datCurrent = CDate(intMonth & "/1/" & intYear)
intCurrentMonthDays = _
Day(DateAdd("d", -1, DateAdd("m", 1, datCurrent)))
intWeekday = Weekday(datCurrent)
Set rsEvents = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM tblEvents " _
& " WHERE ((Month(StartDate) = " & intMonth _
& " AND Year(StartDate) = " & intYear & "))" _
& " OR ((Month(EndDate) = " & intMonth _
& " AND Year(EndDate) = " & intYear & "))"
rsEvents.Open strSQL, cnDB, adOpenStatic
Set rsTasks = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM tblTasks " _
& " WHERE Month(DueDate) = " & intMonth _
& " AND Year(DueDate) = " & intYear
rsTasks.Open strSQL, cnDB, adOpenStatic
'
' Print calendar header information and
' setup table.
'
PrintHeader "Calendar for " _
& MonthName(intMonth) & " " & intYear
WriteLine "<table width=560 border=1 " _
& "cellspacing=0 cellpadding=0>"
'
' Add weekday names to column headings
'
WriteLine "<tr>"
For i = 1 To 7
WriteLine "<td width=80 align=center>"
WriteLine "<span class=calhead>" _
& WeekdayName(i) & "</span>"
WriteLine "</td>"
Next ' i
WriteLine "</tr>"
'
' The first row of calendar cells will contain gray
' boxes for all the days in the previous month.
'
WriteLine "<tr>"
If intWeekday <> 1 then
intPreviousMonthDays = Day(DateAdd("d", -1, datCurrent))
For i = intWeekday -1 to 1 Step - 1
CreateCell intPreviousMonthDays - i + 1, "#CCCCCC", ""
Next ' i
End If
'
' Start main loop through days of the month. When we hit
' 7 days in a row, the loop starts a new table row.
'
For i = 1 to intCurrentMonthDays
'
' Mark the current date's box in a
' different color.
'
If Date = CDate(intMonth & "/" & i & "/" & intYear) Then
strColor = "#66CCFF"
Else
strColor = "#FFFFFF"
End If
CreateCell i, strColor, _
GetDayItems(rsEvents, rsTasks, intMonth, i, intYear)
'
' Start a new row if we have 7 days in the grid
'
If intWeekday = 7 Then
intWeekday = 1
WriteLine "</tr>"
WriteLine "<tr>"
Else
intWeekday = intWeekday + 1
End If
Next ' i
'
' Add days of next month to grid in last row.
'
If intWeekday <= 7 and intWeekday > 1 Then
For i = intWeekday To 7
CreateCell i - intWeekday + 1, "#CCCCCC", ""
Next ' i
End If
WriteLine "</tr></table>"
rsTasks.Close
rsEvents.Close
'
' Add navigation buttons (previous, next) to bottom of calendar
'
WriteLine "<table width=560 border=0 " _
& "cellspacing=5 cellpadding=0><tr>"
intMonthLink = intMonth - 1
intYearLink = intYear
If intMonth = 1 Then
intMonthLink = 12
intYearLink = intYearLink - 1
End If
WriteLine "<td width=80 valign=top><span class=calcell>"
WriteLine "<a href=" & DQ & Request("SCRIPT_NAME") _
& "?month=" & intMonthLink _
& "&year=" & intYearLink & DQ _
& "><< Previous</a></span></td>"
'
' Add navigation to middle of bottom row of calendar. This
' allow the user to pick any month/year to view.
'
WriteLine "<td width=400 align=center>"
WriteLine "<form action=" _
& DQ & Request.ServerVariables("SCRIPT_NAME") & DQ _
& " method=post>"
WriteLine "<span class=calcell>Select Month: "
WriteLine "<select name=Month size=1>"
For i = 1 To 12
Response.Write "<option value=" & DQ & i & DQ
If i = Month(datCurrent) Then
Response.Write " SELECTED"
End If
WriteLine ">" & MonthName(i) & "</option>"
Next ' i
WriteLine "</select>"
WriteLine "Year: "
WriteLine "<input type=Text name=Year " _
& "size=6 maxlength=4 value=" _
& DQ & intYear & DQ & ">"
WriteLine "<input type=submit name=cmdSubmit value=View>"
WriteLine "</form>"
WriteLine "</td>"
intMonthLink = intMonth + 1
intYearLink = intYear
If intMonth = 12 Then
intMonthLink = 1
intYearLink = intYearLink + 1
End If
WriteLine "<td width=80 valign=top align=right>" _
& "<span class=calcell>"
WriteLine "<a href=" & DQ & Request("SCRIPT_NAME") _
& "?month=" & intMonthLink _
& "&year=" & intYearLink & DQ _
& ">Next >></a></span></td>"
WriteLine "</tr></table>"
PrintFooter
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Function GetDayItems
'
' This routine displays the events in each calendar cell.
' The events are returned to the caller as a string so that
' they can be printed into the calendar cell.
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function GetDayItems(rsEvents, rsTasks, intCurMonth, _
intCurDay, intCurYear)
Dim blnShowEvent ' As Boolean
Dim i ' As Integer
Dim strResult ' As String
Dim intStartMonth
Dim intStartDay
Dim intStartYear
Dim intEndMonth
Dim intEndDay
Dim intEndYear
If rsTasks.RecordCount > 0 Then rsTasks.MoveFirst
Do Until rsTasks.EOF
If Day(rsTasks("DueDate")) = intCurDay Then
strResult = strResult & CreateIcon(ICON_TASK, rsTasks)
End If
rsTasks.MoveNext
Loop
If rsEvents.RecordCount > 0 Then rsEvents.MoveFirst
Do Until rsEvents.EOF
blnShowEvent = False
intStartMonth = Month(rsEvents("StartDate"))
intStartDay = Day(rsEvents("StartDate"))
intStartYear = Year(rsEvents("StartDate"))
intEndMonth = Month(rsEvents("EndDate"))
intEndDay = Day(rsEvents("EndDate"))
intEndYear = Year(rsEvents("EndDate"))
'
' Non-wrapping case - start and end month/year are the same.
'
If intStartMonth = intCurMonth _
And intEndMonth = intCurMonth _
And intStartYear = intCurYear _
And intEndYear = intCurYear Then
blnShowEvent = (intStartDay <= intCurDay) _
And intEndDay >= intCurDay
Else
'
' Wrapping case - if event started in
' previous month, only check day.
'
If intStartMonth < intCurMonth Then
' event started before current month
blnShowEvent = (intCurDay <= intEndDay)
ElseIf intEndMonth > intCurMonth Then
' event ended after current month
blnShowEvent = (intCurDay >= intStartDay)
End If
End If
If blnShowEvent Then
strResult = strResult & CreateIcon(ICON_EVENT, rsEvents)
End If
rsEvents.MoveNext
Loop
GetDayItems = strResult
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Sub CreateCell
'
' This function puts content into a cell, including
' all the necessary HTML and formatting tags.
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub CreateCell(strNumber, strColor, strText)
WriteLine "<td width=80 valign=top bgcolor=" & strColor & ">"
WriteLine "<table cellpadding=0 cellspacing=0>"
WriteLine "<tr><td width=1 valign=top>" _
& "<img src=pics/spacer.gif width=1 height=70></td>"
WriteLine "<td width=79 valign=top><span class=calcell><b>" _
& strNumber & "</b><br>"
WriteLine strText
WriteLine "</td></tr>"
WriteLine "</table></td>"
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Function CreateIcon
'
' This function generates an icon for an item to
' be added to the calendar. This routine knows
' what fields to pull, based on the type of icon
' to be shown.
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function CreateIcon(intCode, rsData)
Dim strResult ' As String
Dim lngID ' As Long
Dim datStart ' As Date
Dim datEnd ' As Date
Dim strGraphic ' As String
Dim strPage ' As String
If intCode = ICON_TASK Then
strGraphic = "pics/task.gif"
strPage = "tasks.asp"
lngID = rsData("pkTaskID")
datStart = rsData("StartDate")
datEnd = rsData("DueDate")
ElseIf intCode = ICON_EVENT Then
strGraphic = "pics/event.gif"
strPage = "events.asp"
lngID = rsData("pkEventID")
datStart = rsData("StartDate")
datEnd = rsData("EndDate")
End If
strResult = "<a href=" & DQ & strPage _
& "?" & ACTION & "=" & ACTION_UPDATE _
& "&id=" & lngID & DQ & ">" _
& "<img src=" & DQ & strGraphic & DQ _
& " height=16 width=16 border=0 alt=" & DQ _
& rsData("Name")
If rsData("Description") <> "" Then
strResult = strResult & vbCrLf & rsData("Description")
End If
strResult = strResult & vbCrLf & vbCrLf _
& "Start Date: " & FormatDateTime(datStart) & vbCrLf _
& "End Date: " & FormatDateTime(datEnd) _
& DQ & "></a> "
CreateIcon = strResult
End Function
%>
Thanks for your help. Desi
< Message edited by DesiMcK -- 5/23/2004 13:07:16 >
|
|
|
|
DesiMcK
Posts: 446 Joined: 4/26/2004 From: Essex, UK Status: offline
|
RE: Connecting to a db - 5/23/2004 13:14:52
Some progress - the error is now 'The application is using arguments that are of the wrong type, are out of acceptable range, or are in conflict with one another. ' Is this to do with the actual access databse I set up or with the asp code? Desi
|
|
|
|
davids
Posts: 211 Joined: 1/26/2003 From: Belgium (American) Status: offline
|
RE: Connecting to a db - 5/23/2004 15:41:23
Does it tell you the filename and line number of the error?
_____________________________
Davids International Relocation Technology
|
|
|
|
DesiMcK
Posts: 446 Joined: 4/26/2004 From: Essex, UK Status: offline
|
RE: Connecting to a db - 5/23/2004 15:43:33
Line 62 - 'rsEvents.Open strSQL, cnDB, adOpenStatic'
|
|
|
|
DesiMcK
Posts: 446 Joined: 4/26/2004 From: Essex, UK Status: offline
|
RE: Connecting to a db - 5/23/2004 16:59:57
I read this article and used the third option - Include the Adovbs.inc file with all the constants. You can copy the Adovbs.inc file to your Web projects directory on the Web server from [drive]:\Program files\Common files\System\ADO. Is this the wrong thing to do?? desi
|
|
|
|
davids
Posts: 211 Joined: 1/26/2003 From: Belgium (American) Status: offline
|
RE: Connecting to a db - 5/23/2004 17:31:40
This line <!-- METADATA TYPE="typelib" FILE="C:\Program Files\Common Files\System\ado\msado15.dll" --> is new to me. I usually include the adovbs or a cut-down version of it in the main page: <!--#include file="adovbs.asp" -->
Try changing the line:rsEvents.Open strSQL, cnDB, adOpenStatic torsEvents.Open strSQL, cnDB, 3 and see what happens. Then you should be able to figure out if the ADO constants are working.
_____________________________
Davids International Relocation Technology
|
|
|
|
DesiMcK
Posts: 446 Joined: 4/26/2004 From: Essex, UK Status: offline
|
RE: Connecting to a db - 5/23/2004 17:44:28
You are a genius - the adovbs.asp worked!!!! Well almost - the problem not is that the calendar is not displaying properly - Click here to view the page Thanks, Desi
|
|
|
|
DesiMcK
Posts: 446 Joined: 4/26/2004 From: Essex, UK Status: offline
|
RE: Connecting to a db - 5/23/2004 17:51:03
It seems that January works for all years but no other months. Would this be anything to do with the line datCurrent = CDate(intMonth & "/1/" & intYear)
I'm in th UK so the dating system is different from that in the US - ie UK:04/01/2004 is the 4th of Jan not the 1st of Apr I'm clutching at straws!!! Edit - Yes it was to do with the dating system - I changed the line to datCurrent = CDate("1/" &intMonth & "/" & intYear) and it seems to be OK - For now!!! Thanks verymuch for you help. I would have given up without it!! Desi
< Message edited by DesiMcK -- 5/23/2004 17:53:41 >
|
|
|
|
davids
Posts: 211 Joined: 1/26/2003 From: Belgium (American) Status: offline
|
RE: Connecting to a db - 5/23/2004 17:59:10
Genius I am not. The men who responded above are many times more competent than I am. I'm a b-grade coder who just tries to give back to these forums that have helped me so much.
_____________________________
Davids International Relocation Technology
|
|
|
|
DesiMcK
Posts: 446 Joined: 4/26/2004 From: Essex, UK Status: offline
|
RE: Connecting to a db - 5/23/2004 18:03:03
Seeing is in the eye of the beholder - in my eyes you (all) are geniuses!!
|
|
|
|
davids
Posts: 211 Joined: 1/26/2003 From: Belgium (American) Status: offline
|
RE: Connecting to a db - 5/24/2004 2:59:11
Jaybee, sorry, I don't think I'd seen your posting yet when I wrote that.
_____________________________
Davids International Relocation Technology
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|