ASP.NET connection file problem

G

Guest

Hello friends,
I have some problem in my ASP.NET connection
'Connection file code
<%
dim connstr
connstr=("Provider=Microsoft.Jet.OLEDB.4.0;data
source="&server.mappath("database/it.mdb")&"")
%>
follwoing error message occur when i execute the page
Compiler Error Message: BC30451: Name 'connstr' is not declared.

'Below is the file where i am using it

<!-- #include file="connection.aspx"-->
<script language="VB" runat="server">
Public Sub searchsh()
Response.Write ("<table align=center width=100% cellspacing=4 cellpadding=0
border=0><tr>")
Response.Write ("<td width=30% align=middle valign=top bgcolor=SaddleBrown>")
Response.Write ("<table align=center width=100% cellspacing=2 cellpadding=0
border=0><tr>")
Response.Write ("<td width=100% align=middle><font size=2 color=Azure
face=Arial, Helvetica, sans-serif>")
Response.Write ("<b>NAME</b></font></td></tr></table></td>")
Response.Write ("<td width=30% align=middle valign=top bgcolor=SaddleBrown>")
Response.Write ("<table align=center width=100% cellspacing=2 cellpadding=0
border=0><tr>")
Response.Write ("<td width=100% align=middle><font size=2 color=Azure
face=Arial, Helvetica, sans-serif>")
Response.Write ("<b>ADDRESS</b></font></td></tr></table></td>")

Response.Write ("<td width=15% align=middle valign=top bgcolor=SaddleBrown>")
Response.Write ("<table align=center width=100% cellspacing=2 cellpadding=0
border=0>")
Response.Write ("<tr><td width=100% align=middle>")
Response.Write ("<font size=2 color=Azure face=Arial, Helvetica,
sans-serif><b>HELLO</b></font></td>")
Response.Write ("</tr></table></td>")
Response.Write ("<td width=15% align=middle valign=top bgcolor=SaddleBrown>")
Response.Write ("<table align=center width=100% cellspacing=2 cellpadding=0
border=0>")
Response.Write ("<td width=100% align=middle><font size=2 color=Azure
face=Arial, Helvetica, sans-serif><b>Email</b></font></td>")
Response.Write ("</table></td></tr>")

Dim sqlq="SELECT * from softhouse where cityID Like'"&Request.Form("city")&"'"
Dim objdatareader as new OLEDBDataReader
Dim cmdobj as new OLEDBCommand(sqlq,objconn)
'objDataReader=cmdobj.Executereader()
</script>


<%if Request.Form("searchchoice")=1 then
searchsh
end if
%>
 
M

Miha Markic [MVP C#]

Hard to tell where the error is. It is obvious that there is something wrong
with connstr.
Try with
Dim connstr="Provider=Microsoft.Jet.OLEDB.4.0;data
source="&server.mappath("database/it.mdb")&""
 
R

Ranjan

Try to store this string in a web.config file, and use it from there, using
ConfigSettings.AppSettings.

Please note that you have declared a variable within tags of the
Connection.aspx file, which becomes a private variable, hence you cannot
use it. In any case though, this is a bad practice, and yuou should go for
the web.config file.

Ranjan
http://dotnetjunkies.com/weblog/dotnut
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top