ASP DSN-Less Connection Issues
-
09-07-2021 - |
Pergunta
Sorry if this isn't the appropriate place to put this question, but I'm new to the forums.
My issue relates to ASP and a DSN-less connection. I have a website, which was built quite a while ago using DSN connections to an Access database, which ran on a 2003 server. I have to replicate this site, but our servers (hosted through Fasthosts) are now 2008 servers, and don't support ODBC.
I have set up DSN-less connections, but I'm still not getting it right obviously as I keep getting Object required: 'object' on each page. I'm not really savvy with ASP, so if anybody can provide some answers that would be great!
The original code I had was this:
//Get the 5 newest news items
Dim objRec2, sql2,
newstext sql2="SELECT TOP 5 news_date, news_text FROM news ORDER BY news_date DESC"
set objRec2=Server.CreateObject("ADODB.Recordset")
objRec2.Open sql2, "dsn=database"
Which I then changed to this:
//Get the 5 newest news items
set conob2 = Server.CreateObject("ADODB.Connection")
conob2.Provider="Microsoft.Jet.OLEDB.4.0"
conob2.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & server.MapPath("database.mdb") Set rsuni2 = Server.CreateObject("ADODB.Recordset")
sql2="SELECT TOP 5 news_date, news_text FROM news ORDER BY news_date DESC"
objRec2.Open sql, conob
I then get the error:
Microsoft VBScript runtime error '800a01a8'
Object required: 'objRec2'
index.asp, line 20
I'm running a 'WhileNot' statement to get the news_text and news_date like this:
<%While Not objRec2.EOF
newstext = Replace(objRec2("news_text"), vbCrLf, "<br />")
%>
<p><span class="bold">Date: <%=objRec2("news_date")%></span><br />
<%=newstext%></p>
Can anybody help with this please???
Many thanks!
Solução
After your change are you seem to be missing:
set objRec2=Server.CreateObject("ADODB.Recordset")
which would cause the exact error you encounter (and which is unrelated to the connection).