Hi All,
I am trying to connect to the database through DSN. i have set it up
as System DSN, but when i open the page, i get error "(0x80004005)
[Microsoft][ODBC Driver Manager] Data source name not found and no
default driver specified.
below is the code which i am using:
<%
' Quick security check, make sure we have an active session
'If Session("dbDispList") = "" or Session("dbConn") = "" Then
Response.Redirect "GenericError.asp"
Dim strDBPath ' path to our Access database (*.mdb) file
' Get the parameters set in the Config File
strType = UCase(Session("dbType"))
strConn = Session("dbConn")
strTable = Session("dbRs")
strDisplay = Session("dbDispList")
strWhere = Session("dbWhere")
intPrimary = Session("dbKey")
intOrderBy = Session("dbOrder")
strDBPath = Server.MapPath("acsdata.mdb")
' Check to see if the Order was specified by a parameter
If Request.QueryString("ORDER").Count > 0 Then
' Check if an ASC/DESC toggle is required (- for desc, + for asc)
if abs(intOrderBy) = abs(Request.QueryString("ORDER")) then
intOrderBy = 0 - intOrderBy
else
intOrderBy = Request.QueryString("ORDER")
end if
Session("dbOrder") = intOrderBy
End If
' Open Connection to the database
set xConn = Server.CreateObject("ADODB.Connection")
xConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath
& ";"
' Open Recordset and get the field info
strsql = "SELECT * FROM [" & strTable & "]"
Select Case strType
Case "UDF"
strsql = "SELECT " & strFields & " FROM " & strTable
Case "SQL"
strsql = Replace(strsql,"[","")
strsql = Replace(strsql,"]","")
End Select
set xrs = Server.CreateObject("ADODB.Recordset")
xrs.Open strsql, xConn
intFieldCount = xrs.Fields.Count
Dim aFields()
ReDim aFields(intFieldCount,3)
For x = 1 to intFieldCount
aFields(x, 1) = xrs.Fields(x-1).Name
aFields(x, 2) = xrs.Fields(x-1).Type
aFields(x, 3) = xrs.Fields(x-1).DefinedSize
Next
xrs.Close
Set xrs = Nothing
%>
<HTML>
<HEAD>
<TITLE><%= Session("dbTitle") %></TITLE>
</HEAD>
<BODY>
<FONT FACE="Verdana, Arial, Helvetica">
<%
' Reopen the Recordset using the parameters passed
strsql = "SELECT * FROM [" & strTable & "]"
Select Case strType
Case "UDF"
strsql = "SELECT " & strFields & " FROM " & strTable
Case "SQL"
strsql = Replace(strsql,"[","")
strsql = Replace(strsql,"]","")
End Select
If (strWhere & "x") <> "x" Then strsql = strsql & " WHERE " & strWhere
If intOrderBy <> 0 Then
if intOrderBy > 0 then
strsql = strsql & " ORDER BY [" & aFields(intOrderBy, 1) & "]"
else
strsql = strsql & " ORDER BY [" & aFields(abs(intOrderBy), 1) & "]
DESC"
end if
end if
set xrs = Server.CreateObject("ADODB.Recordset")
xrs.Open strsql, xConn, 1, 2
%>
<!-- Main Body Start -->
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR>
<TD ROWSPAN=2 WIDTH="1"><FONT SIZE=5 FACE="Verdana, Arial,
Helvetica"><STRONG><EM><%= Session("dbTitle") %></EM></STRONG></FONT>
</TD>
<TD BGCOLOR=#99CCCC ALIGN=RIGHT WIDTH="*"><FONT SIZE=3 FACE="Verdana,
Arial, Helvetica">
<A HREF="<%=Session("dbExitPage")%>">Back</A>
<% If Session("dbCanAdd") = 1 Then %>
|
<A HREF="<%=Session("dbGenericPath")%>GenericEdit.asp?
CMD=NEW">Add New Record</A>
<% End If %>
|
<A HREF="<%=Session("dbViewPage")%>">Refresh</A>
<% If Session("dbDebug") = 1 Then %>
|
<A HREF="<%=Session("dbGenericPath")
%>GenericInfo.asp">db Info</A>
<% End If %>
</TD>
</TR>
<TR><TD> </TD></TR>
</TABLE>
<P>
<TABLE CELLPADDING=1 CELLSPACING=0 BORDER=0 BGCOLOR=#99CCCC>
<TR><TD>
<TABLE CELLPADDING=2 CELLSPACING=2 BORDER=0 WIDTH=100%
BGCOLOR=#99CCCC>
<TR>
<% For x = 1 to intFieldCount
If Mid(strDisplay, x, 1) = "1" Then
strConn = "ORDER=" & x
' Don't display BLOB's as sortable
If aFields(x,2) = 201 Then %>
<TH><%=aFields(x,1)%></TH>
<% Else %>
<TH><A HREF="GenericList.asp?<%=strConn%>"><%=aFields(x,1)%></A></
TH>
<% End If
End If
Next %>
<TH> </TH>
</TR>
<%
intCount = 0
Do While NOT xrs.EOF
intCount = intCount + 1 %>
<TR> <%
x = 0
For Each xField in xrs.Fields
x = x + 1
curVal = xField.Value
' Every other line will have a shaded background
If intCount mod 2 = 0 Then
bgcolor="#FFFFCC"
Else
bgcolor="White"
End If
' If on the Key field, build the link used to load the Viewer,
Editor, or Deleter
If x = CInt(intPrimary) Then
Session("zcurTable") = strTable
Session("zcurDisplay") = strDisplay
Session("zcurKeyField") = aFields(x,1)
strLink = "KEY=" & xField.Value
End If
If Mid(strDisplay, x, 1) = "1" Then %>
<TD BGCOLOR=<%= bgcolor %> ALIGN="LEFT">
<% ' Empty / Null / Blank
If IsNull(curVal) OR (Trim(curVal) & "x" = "x") Then curVal =
" "
' Password
If UCase(Left(aFields(x,1),8)) = "PASSWORD" Then curVal = "*****"
' Image
If (UCase(Left(aFields(x,1),3)) = "IMG") Then
If Session("dbMaxImageSize") = 0 Then
curVal = LT & "IMG SRC=" & QUOTE & curVal & QUOTE & GT
Else
curVal = LT & "IMG SRC=" & QUOTE & curVal & QUOTE & " WIDTH=" &
QUOTE & Session("dbMaxImageSize") & QUOTE & GT
End If
End If
' Date / Time
If aFields(x,2) = 135 Then curVal = FormatDateTime(curVal,2)
' Boolean
If aFields(x,2) = 11 Then
If curVal Then
curVal = "Yes"
Else
curVal = "No"
End If
End If
' Currency
If aFields(x,2) = 6 Then curval = FormatCurrency(curval,2,-1)
' Integers, Currency - right align
If (aFields(x,2) = 3) OR (aFields(x,2) = 6) Then curVal = "<div
align=right>" & curVal & "</div>"
' Display Memo field, replace carriage returns with <BR> tags.
If aFields(x,2) = 201 Then curVal =
replace(curVal,chr(10)," <br>")
Response.Write curVal %> </TD> <%
End If
Next
If (Session("dbDispView") <> "") and Session("dbKey") > 0 Then %>
<TD BGCOLOR=<%= bgcolor %> ALIGN="RIGHT"><A HREF="<%=
Session("dbGenericPath") %>GenericView.asp?<%= strLink %>">View</A></
TD>
<% End If
If (Session("dbCanEdit") = 1) and Session("dbKey") > 0 Then %>
<TD BGCOLOR=<%= bgcolor %> ALIGN="RIGHT"><A HREF="<%=
Session("dbGenericPath") %>GenericEdit.asp?<%= strLink %>">Edit</A></
TD>
<% End If
If (Session("dbCanDelete") = 1) and Session("dbKey") > 0 Then %>
<TD BGCOLOR=<%= bgcolor %> ALIGN="RIGHT"><A HREF="<%=
Session("dbGenericPath") %>GenericDelete.asp?<%= strLink %>">Delete</
A></TD>
<% End If
xrs.MoveNext %>
</TR>
<% Loop %>
</TABLE>
</TD></TR>
</TABLE>
<HR SIZE="1"> <%
Response.Write intCount & " records"
xrs.Close
Set xrs = Nothing
xConn.Close
Set xConn = Nothing
%>
<!-- Main Body End -->
</BODY>
</HTML>
Please help.
thanks,
navin
Bob Barrows [MVP] - 08 Oct 2007 13:20 GMT
> ' Open Connection to the database
> set xConn = Server.CreateObject("ADODB.Connection")
> xConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath
> & ";"
This is not the connection string to use for an ODBC DSN. However, I would
suggest forgetting about using a DSN and supplying the actual file path to
your database file in strDBPath.

Signature
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Daniel Crichton - 12 Oct 2007 10:04 GMT
Bob wrote on Mon, 8 Oct 2007 08:20:52 -0400:
>> ' Open Connection to the database set xConn =
>> Server.CreateObject("ADODB.Connection")
>> xConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
>> strDBPath & ";"
> This is not the connection string to use for an ODBC DSN. However, I
> would suggest forgetting about using a DSN and supplying the actual
> file path to your database file in strDBPath.
Looking at the original code that's exactly what was being done:
strDBPath = Server.MapPath("acsdata.mdb")
So the intro about a System DSN was completely irrelevant because nowhere in
that code is the DSN being referenced.

Signature
Dan
Bob Barrows [MVP] - 12 Oct 2007 11:20 GMT
> Bob wrote on Mon, 8 Oct 2007 08:20:52 -0400:
>
[quoted text clipped - 13 lines]
> So the intro about a System DSN was completely irrelevant because
> nowhere in that code is the DSN being referenced.
Then he either misreported his error message: "[Microsoft][ODBC Driver
Manager] ..." or he has not shown us the actual code..
If the former, then this is likely to be a permissions problem and he needs
to make sure the user has read-write permissions to the folder containing
the database. If using Anonymous, then the user is the IUSR_machinename
account.

Signature
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"