Hi
I am trying to get ASP.NET to communicate with MYSQL from the tutorial. I have placed the "connectionstrings driver Code" into the Web Config.
The third line following the "try" instruction has connection details. The first object following the second bracket "ConfigurationManager" is stated as not recognised in the current context.
Would somebody please confirm whether there is an error in the code.
Ray
I am trying to get ASP.NET to communicate with MYSQL from the tutorial. I have placed the "connectionstrings driver Code" into the Web Config.
The third line following the "try" instruction has connection details. The first object following the second bracket "ConfigurationManager" is stated as not recognised in the current context.
Would somebody please confirm whether there is an error in the code.
Ray
Hi,
I believe I have made some progress on this ticket by adding the following at the top of the Code
using System.Data.Odbc; Recommended in Tutorial
using System.Configuration; Additional to Tutorial Code
using System; Additional toTutortial Code
The program appears to Compile successfully with no errors recorded but I now have the following Response.
An error occured: ExecuteReader: Connection property has not been initialized..
Would somebody please advise on the code to initialise the Reader.
My Code is as I read the tutorial with the amendments to the Web Config. File as the tutorial:-
Source code from Web Developer 2008
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Default.aspx.cs
using System.Data.Odbc;
using System.Configuration;
using System;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
using (OdbcConnection connection = new OdbcConnection(ConfigurationManager.ConnectionStrings["MySQLConnStr"].ConnectionString))
{
connection.Open();
using (OdbcCommand command = new OdbcCommand("SELECT id,name,login,password FROM employees"))
using (OdbcDataReader dr = command.ExecuteReader())
{
while (dr.Read())
Response.Write(dr["name"].ToString() + "<br />");
dr.Close();
}
connection.Dispose();
}
}
catch (Exception ex)
{
Response.Write("An error occured: " + ex.Message);
}
}
}
Rgds Ray
I believe I have made some progress on this ticket by adding the following at the top of the Code
using System.Data.Odbc; Recommended in Tutorial
using System.Configuration; Additional to Tutorial Code
using System; Additional toTutortial Code
The program appears to Compile successfully with no errors recorded but I now have the following Response.
An error occured: ExecuteReader: Connection property has not been initialized..
Would somebody please advise on the code to initialise the Reader.
My Code is as I read the tutorial with the amendments to the Web Config. File as the tutorial:-
Source code from Web Developer 2008
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Default.aspx.cs
using System.Data.Odbc;
using System.Configuration;
using System;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
using (OdbcConnection connection = new OdbcConnection(ConfigurationManager.ConnectionStrings["MySQLConnStr"].ConnectionString))
{
connection.Open();
using (OdbcCommand command = new OdbcCommand("SELECT id,name,login,password FROM employees"))
using (OdbcDataReader dr = command.ExecuteReader())
{
while (dr.Read())
Response.Write(dr["name"].ToString() + "<br />");
dr.Close();
}
connection.Dispose();
}
}
catch (Exception ex)
{
Response.Write("An error occured: " + ex.Message);
}
}
}
Rgds Ray
© net-tutorials.com 2006 - 2010