ConnectionString 属性尚未初始化。
ConnectionString 属性尚未初始化。 说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.InvalidOperationException: ConnectionString 属性尚未初始化。
源错误:
行 28: end if
行 29: conn=new oledbconnection()
行 30: conn.open()
行 31: com=new oledbcommand(comstr,conn)
行 32: dim rd as oledbdatareader
源文件: D:\My Documents\My Web Sites\mysite2\login.aspx 行: 30
堆栈跟踪:
[InvalidOperationException: ConnectionString 属性尚未初始化。]
System.Data.OleDb.OleDbConnection.PermissionDemand() +46
System.Data.OleDb.OleDbConnectionFactory.PermissionDemand(DbConnection outerConnection) +22
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +89
System.Data.OleDb.OleDbConnection.Open() +19
ASP.login_aspx.onlogin_click(Object sender, EventArgs e) in D:\My Documents\My Web Sites\mysite2\login.aspx:30
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +75
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +97
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +491
下面是完整代码
<%@ Page Language="vb" Debug="true" %>
<%@ Import Namespace="system.data" %>
<%@ Import Namespace="system.data.oledb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html dir="ltr" xmlns="http://www.
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>管理员登录</title>
<script language="vb" runat="server" type="text/vb" id="script1">
dim conn as new oledbconnection
sub page_load(sender as object,e as eventargs)
dim constr As String
dim data=(ConfigurationSettings.AppSettings("data"))
constr="Provider=Microsoft Jet 4.0 OLE DB provider;Data Source="&server.MapPath (data)
conn.connectionstring=constr
'数据库连接
end sub
Sub onlogin_click(sender As Object, e As EventArgs)
dim com as oledbcommand
dim comstr As String
comstr="select 用户名,密码 from admin where 用户名='"
comstr=comstr & trim(username.text) & "'and 密码='" & trim(password.text) & "'"
if username.text="" or Instr(username.text,"=")>0 or Instr(username.text,"%")>0 or Instr(username.text,chr(32))>0 or Instr(username.text,"?")>0 or Instr(username.text,"&")>0 or Instr(username.text,";")>0 or Instr(username.text,",")>0 or Instr(username.text,"'")>0 or Instr(username.text,",")>0 or Instr(username.text,chr(34))>0 or Instr(username.text,chr(9))>0 or Instr(username.text," ")>0 or Instr(username.text,"$")>0 then
response.write("出错啦...请不要输入非法的字符!")
response.end
end if
conn=new oledbconnection()
conn.open()
com=new oledbcommand(comstr,conn)
dim rd as oledbdatareader
rd=com.executereader()
if not rd.read() then
message.text="用户名或密码错误!"
rd.close
conn.close
exit sub
else
session("username")="username.text"
session("password")="password.text"
session.timeout="60"
response.redirect("manage.aspx")
rd.close
conn.close
end if
end sub
Sub onreset_click(sender As Object, e As EventArgs)
username.text=""
password.text=""
end sub
</script>
<style type="text/css">
.style1 {
font-weight: normal;
text-align: center;
}
.style2 {
text-align: center;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<h1 class="style1"> </h1>
<h1 class="style1"> </h1>
<h1 class="style1"> </h1>
<h1 class="style1"> <strong>管理员登录</strong></h1>
<p class="style2">
<asp:Label runat="server" Text="用户名" id="Label1"></asp:Label>
<strong>
<asp:TextBox runat="server" id="username"></asp:TextBox>
</strong></p>
<p class="style2"><strong>
<asp:Label runat="server" Text="密码" id="Label2"></asp:Label>
<asp:TextBox runat="server" id="password"></asp:TextBox>
</strong></p>
<div class="style2">
<p>
<asp:Button runat="server" Text="登录" id="Button1" OnClick="onlogin_click" Width="40px"/>
<asp:Button runat="server" Text="重置" id="Button2" OnClick="onreset_click"/>
</p>
<p>
<asp:Label runat="server" Text="" id="message"></asp:Label>
</p>
</div>
</form>
</body>
</html>
编辑平台是Expression Web,请高手帮忙,拜谢了!!-_-