webForumDet fria alternativet

Från MySQL till Access, hur?

ASP

6 svar · 406 visningar · startad av MadMange

Medlem sedan aug. 200646 inlägg
Frågan#1

Har denna kod som skall generera nyheter till ett forum, dock så använder jag mig av en Access databas och skulle nu behöva hjälp med att ändra från MySQL till Access, alltså db-kopplingen.
någon som har lust att hjälpa till? :r

2:   <%
3:   
4:   
5:   
6:   '#################################################
7:   '# Database options                              #
8:   '#################################################
9:   
10:  const db_Server = "localhost"
11:  const db_Password = "password"
12:  const db_Username = "user"
13:  const db_Database = "aspbb"
14:      
15:  'Database connection
16:  Dim objConn
17:  Set objConn = Server.CreateObject("ADODB.Connection")
18:  objConn.Open "Driver={MySQL ODBC 3.51 Driver};server="&db_Server&";uid="&db_Username&";pwd="&db_Password&";database="&db_Database&""
19:  
20:  '//Converts UNIX timestamps into the format the current webserver use.
21:  Function uTimeStamp(byval dDate) '// Bring the date back from database and show in current session.LCID
22:      on error resume next
23:      uTimeStamp = DateAdd("s", dDate, "01/01/1970 00:00:00")
24:    if err then
25:      cTimeStamp = int(0)
26:    end if
27:  End Function
28:  
29:  
30:    dim strSQL
31:    strSQL = "SELECT * FROM aspbb_topics WHERE tforumid=1 ORDER BY tdatecreate DESC Limit 10"
32:    set objNews = objConn.Execute(strSQL)
33:    
34:    Do Until objNews.EOF
35:      Response.Write "<p><div style=""background-color:#f1f1f1; color:#ff7a00; font-size:12px""><img src=""mods/iconthread.gif"" style=""border:0"" /> <b>" & objNews("ttitle") & "</b>&nbsp;-&nbsp;" & uTimeStamp(objNews("tdatecreate")) & "</div><br/>" & vbNewLine
36:      Response.Write objNews("tbody") & "<br/><br/><br/><br/>" 
37:      Response.write "<div style=""text-align:right""><a href=""http://forum.aspbb.org/topic.asp?TID=" & objNews("tid") & """>Comment</a></div>" & vbNewLine
38:      Response.Write "<br/></p>" & vbNewLine 
39:      objNews.MoveNext
40:    Loop
41:    
42:  objNews.Close : Set objNews = Nothing
43:  objConn.Close : Set objConn = Nothing
44:    
45:  %>
Medlem sedan dec. 19996 721 inlägg
#2

För databaskopplingar kan du kolla på https://www.connectionstrings.com

Sedan måste SQL-frågan ändras till:

SELECT TOP 10 * FROM aspbb_topics WHERE tforumid=1 ORDER BY tdatecreate DESC
Medlem sedan aug. 200646 inlägg
#3

emission skrev:

För databaskopplingar kan du kolla på https://www.connectionstrings.com

Sedan måste SQL-frågan ändras till:

SELECT TOP 10 * FROM aspbb_topics WHERE tforumid=1 ORDER BY tdatecreate DESC

Ok nu ser det ut så här

<%

Set Conn = Server.CreateObject("ADODB.Connection") 
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("../db.mdb")
'//Converts UNIX timestamps into the format the current webserver use.
Function uTimeStamp(byval dDate) '// Bring the date back from database and show in current session.LCID
on error resume next
uTimeStamp = DateAdd("s", dDate, "01/01/1970 00:00:00")
if err then
cTimeStamp = int(0)
end if
End Function

dim strSQL
strSQL = "SELECT TOP 10 * FROM aspbb_topics WHERE tforumid=1 ORDER BY tdatecreate DESC"
set objNews = objConn.Execute(strSQL)

Do Until objNews.EOF
Response.Write "<p><div style=""background-color:#f1f1f1; color:#ff7a00; font-size:12px""><img src=""mods/iconthread.gif"" style=""border:0"" /> <b>" & objNews("ttitle") & "</b>&nbsp;-&nbsp;" & uTimeStamp(objNews("tdatecreate")) & "</div><br/>" & vbNewLine
Response.Write objNews("tbody") & "<br/><br/><br/><br/>" 
Response.write "<div style=""text-align:right""><a href=""http://forum.aspbb.org/topic.asp?TID=" & objNews("tid") & """>Comment</a></div>" & vbNewLine
Response.Write "<br/></p>" & vbNewLine 
objNews.MoveNext
Loop
   
objNews.Close : Set objNews = Nothing
objConn.Close : Set objConn = Nothing
%>

Men då får jag meddelandet :q

Microsoft VBScript runtime  error '800a01a8'

Object required: 'objConn'

/news.asp, line 16
Medlem sedan dec. 20025 483 inlägg
#4

Ersätt samtliga förekomster av objConn med Conn (eller tvärtom).

Medlem sedan aug. 200646 inlägg
#5

Peter S skrev:

Ersätt samtliga förekomster av objConn med Conn (eller tvärtom).

OK!
Funkar detta tror du? (har lite prob med webhotellet)

<%

Set objConn = Server.CreateObject("ADODB.Connection") 
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("../db.mdb")
'//Converts UNIX timestamps into the format the current webserver use.
Function uTimeStamp(byval dDate) '// Bring the date back from database and show in current session.LCID
on error resume next
uTimeStamp = DateAdd("s", dDate, "01/01/1970 00:00:00")
if err then
cTimeStamp = int(0)
end if
End Function

dim strSQL
strSQL = "SELECT TOP 10 * FROM aspbb_topics WHERE tforumid=1 ORDER BY tdatecreate DESC"
set objNews = objConn.Execute(strSQL)

Do Until objNews.EOF
Response.Write "<p><div style=""background-color:#f1f1f1; color:#ff7a00; font-size:12px""><img src=""mods/iconthread.gif"" style=""border:0"" /> <b>" & objNews("ttitle") & "</b>&nbsp;-&nbsp;" & uTimeStamp(objNews("tdatecreate")) & "</div><br/>" & vbNewLine
Response.Write objNews("tbody") & "<br/><br/><br/><br/>" 
Response.write "<div style=""text-align:right""><a href=""http://forum.aspbb.org/topic.asp?TID=" & objNews("tid") & """>Comment</a></div>" & vbNewLine
Response.Write "<br/></p>" & vbNewLine 
objNews.MoveNext
Loop
   
objNews.Close : Set objNews = Nothing
objConn.Close : Set objConn = Nothing
%>
Medlem sedan dec. 20025 483 inlägg
#6

Tycker det ser rätt ut.

Medlem sedan aug. 200646 inlägg
#7

Peter S skrev:

Tycker det ser rätt ut.

Jepp det funkar nu! Tack för hjälpen :birp

256 ms totalt · 4 externa anrop · v20260731065814-full.a51de22e
127 ms — deklarationer (db)
0 ms — hämta statistik (cache)
124 ms — hämta tråd, inlägg och bilagor (db)
128 ms — ändringar (db)