显示不了数据库连接信息,请高手指教,代码如下
终极管理员 知识笔记 85阅读
% @页面语言=' c# '代码隐藏=' web窗体1 .aspx。cs ' autoeventwireup=' false ' inherits=' web应用程序1 .网表单1"% % @导入名称空间="系统数据SqlClient"% % @导入命名空间='系统。数据' %!DOCTYPEHTMLPUBLIC '-//W3C//dtdhtml 4.0 transitional//EN ' HTML HEAD title web form 1/title meta name=' GENERATOR ' content=' Microsoft visual studio .net 7.1"meta name="
yle="color: rgba(0, 0, 0, 1)">CODE_LANGUAGE" Content="C#"><meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="">
<script Language="C#" runat="server">
void Page_Load()
{string strConnection="Persist Security Info=false;";
strConnection+="user id=sa;password=sa;database=Northwind;";
conn_str.Text=strConnection;
SqlConnection nwConn=new SqlConnection(strConnection);
try
{
nwConn.Open();
conn_open.Text="连接成功";
nwConn.Close();
conn_close.Text="连接关闭";
}
catch(Exception e)
{
conn_close.Text="连接失败";
conn_close.Text=e.ToString();
}
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<h4>连接测试例子:
<asp:label id="conn_str" runat="server" /></h4>
<asp:label id="conn_open" runat="server" /><br>
<asp:label id="conn_close" runat="server" /><br>
</form>
</body>
</HTML>
只能显示 “连接测试例子”字样。

标签: