conn.Close() error, missing directive?

F

FC

Hello All:
I am getting the following error: Compiler Error Message: CS0246: The
type or namespace name 'conn' could not be found (are you missing a
using directive or an assembly reference?)

This error point to the line conn.Close() on my finally statement. I am
pretty new at this and I did not find much on the web. Any help would
be greatly appreciated. My code is as follows:

<%@ Page Language="C#" debug="true" %>
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "System.Data.SqlClient" %>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
<%
string ConnString = "ommitted for security reasons"
try
{
string stmt = @"select * from gbook";
SqlConnection conn = null;
conn = new SqlConnection(ConnString);
conn.Open();
SqlCommand cmd = new SqlCommand(stmt,conn);
SqlDataReader reader = cmd.ExecuteReader();

while ( reader.Read() )

%>
<table width="790" border="0" align="center" cellpadding="3"
cellspacing="3">
<tr>
<td><table width="100%" border="1" cellspacing="3" cellpadding="3">
<tr>
<td width="40%"><strong><font size="2" face="Verdana, Arial,
Helvetica, sans-serif">
On
<%
Response.Write(reader.GetString(1));//this worked before I put the
HTML
//Response.Write(" ");
//Response.Write(reader.GetString(2));
%>
said:</font></strong></td>
<td width="60%"><font size="2" face="Verdana, Arial,
Helvetica, sans-serif">
message goes here</font></td>
</tr>
</table></td>
</tr>
</table>
<% }
catch(SqlException e)
{
Response.Write(e.Message);
}
finally
{
conn.Close();
}
%>
</body>
</html>

Thanks in advance.
 
P

Pat

SqlConnection conn = new
SqlConnection(ConfigurationSettings.AppSettings["YourConnectionStringKeyValu
e"]);
Try this it should help
Patrick
 

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

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top