access_asp thread: Provider error '80020005' Type mismatch. /utils/forum/f_main.asp, line 454
Hi I am getting a Provider error Type Mismatch. Can anybody figure out
what is causing this problem. I have specified the line number where the
error occurs. This is a downloaded code from the website and trying to use
it for my purposes.
<%
// this file is the main communication point that contains all forum-related
// functionality.
// ---------------------------------------------
// uri functions.
// these functions should be used whenever you need a <a href="...">
// tag. instead of specifying an asp page and adding some cryptic
// parameters, you call one of these functions.
// with this approach, you can centralize the url-parameters
// in one place.
//
// you have to modify the asp filenames in the following functions,
// when you change the name of the real files.
var m_Conn; // the database-connection.
var m_Dic; // scripting.dictionary
//--------------------------------------------------------------------------------
// build the internal map of name-value pairs from a given url.
function fromURL(url1)
{
var nStart = url1.indexOf("?", 0);
if (nStart != -1)
{
var url = "" + url1.substr(nStart + 1, url1.length - nStart);
var url_element = url.split("&");
//if the url has no parameters
if (url_element[0] == null || url_element[0] == undefined)
return;
//if the url has parameters
else
{
for (x = 0; x < url_element.length - 1; x++)
{
//add key-item to object
var vItem = url_element[x].split("=");
m_Dic.Add(vItem[0], vItem[1]);
}
}
}
}
//--------------------------------------------------------------------------------
// returns all values of the internal map url-encoded
// in the form "name=value&name=value&name=value&" etc.
// you can append this directly to an url.
function toUrl()
{
var x, s = "", a, b;
a = (new VBArray(m_Dic.Keys())).toArray();
b = (new VBArray(m_Dic.Items())).toArray();
for (x = 0; x < m_Dic.Count; x++)
s += ("" + a[x]) + "=" + Server.URLEncode(("" + b[x])) + "&";
if (s.charAt(s.length - 1) == "&")
s = s.substr(0, s.length - 1);
return s;
}
//--------------------------------------------------------------------------------
// the same as "toUrl" except that the value of the
// map-entry specified by "name" is replaced by "new_value".
function toUrlValue(key, new_item)
{
var x, s = "", a, b;
if (!m_Dic.Exists(key))
m_Dic.Add (key, new_item);
a = (new VBArray(m_Dic.Keys())).toArray();
b = (new VBArray(m_Dic.Items())).toArray();
for (x = 0; x < m_Dic.Count; x++)
{
if (a[x] == key)
s += a[x] + "=" + Server.URLEncode(new_item) + "&";
else
s += a[x] + "=" + Server.URLEncode(b[x]) + "&";
}
if (s.charAt(s.length - 1) == "&")
s = s.substr(0, s.length - 1);
return s;
}
//--------------------------------------------------------------------------------
// the same as "toUrl" except that the value of the
// map-entry specified by "name1" is replaced by "new_value1" and
// the value of "name2" is replaced by "new_value2".
function toUrlValue2( key1, new_item1, key2, new_item2 )
{
var x, s = "", a, b;
if (!m_Dic.Exists(key1))
m_Dic.Add (key1, new_item1);
if (!m_Dic.Exists(key2))
m_Dic.Add (key2, new_item2);
a = (new VBArray(m_Dic.Keys())).toArray();
b = (new VBArray(m_Dic.Items())).toArray();
for (x = 0; x < m_Dic.Count; x++)
{
if (a[x] == key1)
s += a[x] + "=" + Server.URLEncode(new_item1) + "&";
else if (a[x] == key2)
s += a[x] + "=" + Server.URLEncode(new_item2) + "&";
else
s += a[x] + "=" + Server.URLEncode(b[x]) + "&";
}
if (s.charAt(s.length - 1) == "&")
s = s.substr(0, s.length - 1);
return s;
}
// content page.
function getUriNoContent()
{
return "nocontent.asp";
}
//reply.asp
function getUriReplyForum()
{
return "/forums/reply.asp?" + toUrl();
}
//reply.asp
function getUriSendReply()
{
return "/forums/insert_reply.asp?" + toUrl();
}
//mail.asp
function getUriReplyAuthor()
{
return "/forums/mail.asp?" + toUrl();
}
//modify.asp
// list page.
function getUriModifyCurMsg(id)
{
return "/forums/modify.asp?" + toUrlValue2("modify", id, "select", id);
}
//delete.asp
function getUriDeleteCurMsg(id)
{
return "/forums/delete.asp?" + toUrlValue2("delkind", "one", "del", id);
}
//delete.asp
function getUriDeleteCurMsgSubs(id)
{
return "/forums/delete.asp?" + toUrlValue2("delkind", "branch", "del", id);
}
//index.asp
function getUriSelectMsg(id)
{
return "/forums/forum.asp?" + toUrlValue("select", id);
}
//index.asp
function getUriListWithForum(forum_id)
{
return "/forums/forum.asp?" + toUrlValue("forumid", forum_id);
}
//insert_reply.asp
// reply page(s).
function getUriInsertReply()
{
return "/forums/reply.asp?" + toUrl();
}
//failure.asp
function getUriReplyError(err_text)
{
return "/forums/failure.asp?err_txt=" + Server.UrlEncode(err_text);
}
//index.asp
function getUriMain(article_id)
{
strUrl = "/forums/forum.asp?" + toUrl();
return appendAnchor(strUrl, article_id);
}
//send_mail.asp
// mail page(s).
function getUriSendMail()
{
return "/forums/send_mail.asp?" + toUrl();
}
//failure.asp
function getUriMailError(err_text)
{
return "/forums/failure.asp?err_txt=" + Server.UrlEncode(err_text);
}
//insert_new.asp
// new page(s).
function getUriInsertNew()
{
return "/forums/insert_new.asp?" + toUrl();
}
//failure.asp
function getUriNewError(err_text)
{
return "/forums/failure.asp?err_txt=" + Server.UrlEncode(err_text);
}
//insert_modify.asp
// modify page(s).
function getUriModify()
{
return "/forums/insert_modify.asp?" + toUrl();
}
//failure.asp
function getUriModifyError(err_text)
{
return "/forums/failure.asp?err_txt=" + Server.UrlEncode(err_text);
}
//new.asp
// misc page(s).
function getUriNew(forum_id)
{
return "/forums/new.asp?" + toUrlValue("forumid", forum_id);
}
// ---------------------------------------------
// faked constructor.
// always call this immediately after you created
// a new instance of this class.
function init()
{
m_Dic = Server.CreateObject("Scripting.Dictionary");
//db connection
m_Conn = Server.CreateObject("ADODB.Connection");
m_Conn.Open ("Provider=Microsoft.Jet.OLEDB.4.0;" +
"Persist Security Info=False;" +
"Data Source=" + Server.MapPath("/bin/db/forum.mdb"));
// read in all parameters from the current page's url.
fromURL("" + myselfComplete());
}
function readArticles(forum_id)
{
m_Dic.Item("forumid") = forum_id;
}
// ---------------------------------------------
// checks, whether the forum is currently in admin mode.
// in admin mode, you can modify and delete articles.
function isInAdminMode()
{
var isInAdminMode = false;
if (Request("ad") != "")
{
if ("" + Request("ad") == ADMIN_PW)
isInAdminMode = true;
}
}
// get the id of a forum from its short-name.
// returns null if not found.
// you may need to strengthen the sql query (the 'LIKE')
// when you have forums with similar names.
function getForumId(forum_name)
{
var rs = m_Conn.Execute( "SELECT * FROM Forum WHERE Shortname LIKE '%" +
forum_name + "%'" );
if (!rs.BOF && !rs.EOF)
return rs("ID");
else
return null;
}
// creates a forum with a long name.
// returns the id of the forum.
// if the forum already exists, only its it
// is returned.
function createForum(forum_long_name)
{
var rs = m_Conn.Execute( "SELECT * FROM Forum WHERE Name LIKE '%" +
forum_long_name + "%'" );
if (!rs.BOF && !rs.EOF)
return rs("ID");
else
{
rs.Close;
rs = Server.CreateObject("ADODB.Recordset");
rs.Open ("Forum", m_Conn, 2, 3);
rs.AddNew;
rs("Name") = forum_long_name;
rs.Update;
return rs("ID");
}
}
// returns the long name of a forum, given the id of a forum.
function getForumName(forum_id)
{
var rs = m_Conn.Execute( "SELECT * FROM Forum WHERE ID=" + forum_id );
return rs("Name");
}
// gets the recordset of an article, given the id of the article.
function getArticleRs(article_id)
{
return m_Conn.Execute("SELECT * FROM Article WHERE ID=" + article_id);
}
// gets the recordset of a forum, given the id of the forum.
function getForumRs(forum_id)
{
return m_Conn.Execute("SELECT * FROM Forum WHERE ID=" + forum_id);
}
// gets the recordset with all forums.
function getForumsRs()
{
return m_Conn.Execute( "SELECT * FROM Forum" );
}
// gets the recordset with all forums sorted by category
function getForumsRsSortedByCategory()
{
return m_Conn.Execute( "SELECT * FROM Forum ORDER BY Forum.Category" );
}
// insert a child-article for an already present article.
// set 'parent_id' to zero for inserting a root article
// for the given forum.
function insertNew(parent_id, forum_id, subject, author_name, author_email,
text, email_notify, user_id)
{
var rs = Server.CreateObject("ADODB.Recordset");
rs.Open ("Article", m_Conn, 2, 3);
//assortment of the entries:
//every entry has a position-number (position), which determines the assortment
//of the output. The most up-to-date entry of the first level gets the lowest
number.
//The answer-entries get the first number of their parent`s position and,
after a ".",
//the next number which is sorted ascending.
var sql_pos;
var rs_pos;
var sql_child;
var rs_child;
var position;
var last;
var x;
var indent;
//if it is a parent entry
if (parent_id == "0")
{
sql_pos = "SELECT * FROM Article WHERE ForumID =" + forum_id + " ORDER BY
[Position]";
rs_pos = m_Conn.Execute(sql_pos);
if (rs_pos.Eof)
position = Number("999999");
else
{
x = (Number(rs_pos("Position")) - 1);
//if there are more than 999999 entries
if (x == 0)
x = 1;
while (x.length < 6)
x = "0" + x;
position = Number(x);
}
indent = "0";
} //if it is a child entry
else
{
sql_pos = "SELECT * FROM Article WHERE ID =" + parent_id;
rs_pos = m_Conn.Execute(sql_pos);
sql_child = "SELECT * FROM Article WHERE ParentID =" + parent_id + " ORDER BY
Date DESC";
rs_child = m_Conn.Execute(sql_child);
indent = (rs_pos("Indent") + 1);
//if there are no other children
if (rs_child.Bof && rs_child.Eof)
{
position = rs_pos("Position") + ".000001";
}
//if there are other children
else
{
last = "" + rs_child("Position");
last = last.substr(last.length - 6, 6);
x = "" + (Number(last) + 1);
while (x.length < 6)
x = "0" + x;
//if there are more than 999999 childs
if (Number(x) > 999999)
x = "999999";
position = rs_pos("Position") + "." + x;
}
}
//Database entry
// output todays date and the current time in the format "07/08/2001 20:40:03"
var dNow = new Date();
rs.AddNew();
rs("ParentID") = parent_id;
rs("ForumID") = forum_id;
rs("Subject") = subject;
rs("AuthorName") = author_name;
rs("AuthorEmail") = author_email;
rs("Date") = dNow.toLocaleString(); Line 454
rs("Text") = text;
rs("Notify") = email_notify;
rs("Position") = "" + position;
rs("Indent") = indent;
rs("UserID") = user_id;
rs.Update();
// mark the added article as selected.
m_Dic.Item("select") = rs("ID");
return rs("ID");
}
// modifes an already present article.
function modifyArticle(article_id, subject, author_name, author_email, text,
email_notify, user_id)
{
m_Conn.Execute ("UPDATE Article SET Article.Subject=\"" + subject +
"\",Article.AuthorName=\"" + author_name +
"\",Article.AuthorEmail=\"" + author_email +
"\",Article.Text=\"" + text +
"\",Article.Notify=\"" + email_notify +
"\",Article.UserID=\"" + user_id +
"\" WHERE Article.ID=" + article_id);
var rs = Server.CreateObject("ADODB.Recordset");
rs.Open ("Article", m_Conn, 2, 3);
}
// deletes an article and all its childred, given the
// article id of this article.
// retun the number of items deleted
function deleteArticle(article_id, bAll)
{
var parent_position, forum_id;
var rs_p, sql_p;
sql_p = "SELECT * FROM Article WHERE ID =" + Request("del");
rs_p = m_Conn.Execute(sql_p);
parent_position = rs_p("Position");
forum_id = Request("forumid");
if (bAll) // delete all children
{
var nArticles = 0;
var sqlNum = "SELECT * FROM Article WHERE [Position] LIKE '%" + parent_position +
"%' AND ForumID =" + forum_id;
var rsNum = m_Conn.Execute(sqlNum);
while (!rsNum.Eof)
{
nArticles++;
rsNum.MoveNext;
}
m_Conn.Execute ("DELETE FROM Article WHERE [Position] LIKE '%" + parent_position +
"%' AND ForumID =" + forum_id);
return nArticles;
}
else
{
m_Conn.Execute ("DELETE FROM Article WHERE ID =" + Request("del") +
" AND ForumID =" + forum_id);
}
return 1;
}
// appends an anchor-link "#xxx" to an url.
function appendAnchor( url, anchor_name )
{
return url; // hack
// remove any '?' or '&' at the end.
while (url.length > 0 && (charAt(url.length - 1) == "&" || charAt(url.length
- 1) == "?"))
url = url.substr(0, url.length - 1);
// append the anchor.
url = url + "#" &anchor_name;
}
function replaceAll(string, src, dest)
{
while (string.indexOf(src) != -1)
string = string.replace(src, dest);
return string;
}
function doCode(fString, fOTag, fCTag, fROTag, fRCTag)
{
var fOTagPos = fString.indexOf(fOTag);
var fCTagPos = fString.indexOf(fCTag);
while (fCTagPos != -1 && fOTagPos != -1)
{
fString = replaceAll(fString, fOTag, fROTag);
fString = replaceAll(fString, fCTag, fRCTag);
fOTagPos = fString.indexOf(fOTag);
fCTagPos = fString.indexOf(fCTag);
}
return fString;
}
function ReplaceCode(fString)
{
if (fString == "")
fString = " ";
else
{
fString = doCode(fString, "[b]", "[/b]", "<b>", "</b>");
fString = doCode(fString, "[s]", "[/s]", "<s>", "</s>");
fString = doCode(fString, "[strike]", "[/strike]", "<s>", "</s>");
fString = doCode(fString, "[u]", "[/u]", "<u>", "</u>");
fString = doCode(fString, "[i]", "[/i]", "<i>", "</i>");
fString = doCode(fString, "[font=Andale Mono]", "[/font]", "<font
face=\"Andale Mono\">", "</font>");
fString = doCode(fString, "[font=Arial]", "[/font]", "<font face=\"Arial\">",
"</font>");
fString = doCode(fString, "[font=Arial Black]", "[/font]", "<font face=\"Arial
Black\">", "</font>");
fString = doCode(fString, "[font=Book Antiqua]", "[/font]", "<font face=\"Book
Antiqua\">", "</font");
fString = doCode(fString, "[font=Century Gothic]", "[/font]", "<font
face=\"Century Gothic\">", "</font>");
fString = doCode(fString, "[font=Courier New]", "[/font]", "<font
face=\"Courier New\">", "</font>");
fString = doCode(fString, "[font=Comic Sans MS]", "[/font]", "<font
face=\"Comic Sans MS\">", "</font>");
fString = doCode(fString, "[font=Georgia]", "[/font]", "<font
face=\"Georgia\">", "</font>");
fString = doCode(fString, "[font=Impact]", "[/font]", "<font
face=\"Impact\">", "</font>");
fString = doCode(fString, "[font=Tahoma]", "[/font]", "<font
face=\"Tahoma\">", "</font>");
fString = doCode(fString, "[font=Times New Roman]", "[/font]", "<font
face=\"Times New Roman\">", "</font>");
fString = doCode(fString, "[font=Trebuchet MS]", "[/font]", "<font
face=\"Trebuchet MS\">", "</font>");
fString = doCode(fString, "[font=Script MT Bold]", "[/font]", "<font
face=\"Script MT Bold\">", "</font>");
fString = doCode(fString, "[font=Stencil]", "[/font]", "<font
face=\"Stencil\">", "</font>");
fString = doCode(fString, "[font=Verdana]", "[/font]", "<font
face=\"Verdana\">", "</font>");
fString = doCode(fString, "[font=Lucida Console]", "[/font]", "<font
face=\"Lucida Console\">", "</font>");
fString = doCode(fString, "[red]", "[/red]", "<font color=red>", "</font>");
fString = doCode(fString, "[green]", "[/green]", "<font color=green>", "</font>");
fString = doCode(fString, "[blue]", "[/blue]", "<font color=blue>", "</font>");
fString = doCode(fString, "[white]", "[/white]", "<font color=white>", "</font>");
fString = doCode(fString, "[purple]", "[/purple]", "<font color=purple>",
"</font>");
fString = doCode(fString, "[yellow]", "[/yellow]", "<font color=yellow>",
"</font>");
fString = doCode(fString, "[violet]", "[/violet]", "<font color=violet>",
"</font>");
fString = doCode(fString, "[brown]", "[/brown]", "<font color=brown>", "</font>");
fString = doCode(fString, "[black]", "[/black]", "<font color=black>", "</font>");
fString = doCode(fString, "[pink]", "[/pink]", "<font color=pink>", "</font>");
fString = doCode(fString, "[orange]", "[/orange]", "<font color=orange>",
"</font>");
fString = doCode(fString, "[gold]", "[/gold]", "<font color=gold>", "</font>");
fString = doCode(fString, "[beige]", "[/beige]", "<font color=beige>", "</font>");
fString = doCode(fString, "[teal]", "[/teal]", "<font color=teal>", "</font>");
fString = doCode(fString, "[navy]", "[/navy]", "<font color=navy>", "</font>");
fString = doCode(fString, "[maroon]", "[/maroon]", "<font color=maroon>",
"</font>");
fString = doCode(fString, "[limegreen]", "[/limegreen]", "<font
color=limegreen>", "</font>");
fString = doCode(fString, "[h1]", "[/h1]", "<h1>", "</h1>");
fString = doCode(fString, "[h2]", "[/h2]", "<h2>", "</h2>");
fString = doCode(fString, "[h3]", "[/h3]", "<h3>", "</h3>");
fString = doCode(fString, "[h4]", "[/h4]", "<h4>", "</h4>");
fString = doCode(fString, "[h5]", "[/h5]", "<h5>", "</h5>");
fString = doCode(fString, "[h6]", "[/h6]", "<h6>", "</h6>");
fString = doCode(fString, "[size=1]", "[/size=1]", "<font size=1>", "</font>");
fString = doCode(fString, "[size=2]", "[/size=2]", "<font size=2>", "</font>");
fString = doCode(fString, "[size=3]", "[/size=3]", "<font size=3>", "</font>");
fString = doCode(fString, "[size=4]", "[/size=4]", "<font size=4>", "</font>");
fString = doCode(fString, "[size=5]", "[/size=5]", "<font size=5>", "</font>");
fString = doCode(fString, "[size=6]", "[/size=6]", "<font size=6>", "</font>");
fString = doCode(fString, "[list]", "[/list]", "<ul>", "</ul>");
fString = doCode(fString, "[list=1]", "[/list=1]", "<ol type=1>", "</ol>");
fString = doCode(fString, "[list=a]", "[/list=a]", "<ol type=a>", "</ol>");
fString = doCode(fString, "[*]", "[/*]", "<li>", "</li>");
fString = doCode(fString, "[left]", "[/left]", "<div align=left>", "</div>");
fString = doCode(fString, "[center]", "[/center]", "<center>", "</center>");
fString = doCode(fString, "[centre]", "[/centre]", "<center>", "</center>");
fString = doCode(fString, "[right]", "[/right]", "<div align=right>", "</div >");
fString = doCode(fString, "[code]", "[/code]", "<pre>", "</pre>");
fString = doCode(fString, "[quote]", "[/quote]", "<blockquote>quote:<hr
height=1 noshade>", "<hr height=1 noshade></blockquote>");
fString = replaceAll(fString, "[br]", "<br>");
fString = doCode(fString, "[img]", "[/img]", "<img src=\"", "\">");
fString = replaceUrls(fString);
}
return fString;
}
function replaceUrls(fString)
{
fString = doCode(fString, "[url=\"", "\"]", "<a href=\"", "\"
target=\"_blank\">");
fString = doCode(fString, "[url="", ""]", "<a href=\"", "\"
target=\"_blank\">");
fString = replaceAll(fString, "<a href=\""", "<a href=\"");
fString = replaceAll(fString, ""\" target", "\" target");
fString = replaceAll(fString, "[/url]", "</a>");
return fString;
}
// remove illegal HTML and DHTML tags/events from the passed string
// also censor swear words
function stripIllegalHTML(string)
{
string = "" + string;
// remove swear words
string = replaceAll(string, "****", "procreate");
string = replaceAll(string, "****", "Procreate");
string = replaceAll(string, "****", "PROCREATE");
string = replaceAll(string, "****", "poop");
string = replaceAll(string, "****", "POOP");
string = replaceAll(string, "****", "Poop");
string = replaceAll(string, "****", "plumb");
string = replaceAll(string, "****", "PLUMB");
string = replaceAll(string, "****", "Plumb");
string = replaceAll(string, "**** ", "pelican ");
string = replaceAll(string, "**** ", "PELICAN ");
string = replaceAll(string, "**** ", "Pelican ");
// remove markup
string = replaceAll(string, "<", "<");
string = replaceAll(string, ">", ">");
// replace quotes
string = replaceAll(string, "\"", """);
string = replaceAll(string, "'", "'");
return string;
}
%>