Click here to Skip to main content
15,884,066 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have a connection class named "connection" in app-code folder and I called it in aspx.cs file like
C#
connection c=new connection();

It works fine on local host but when I upload all files then it throw error "The type or namespace name 'connection' could not be found (are you missing a using directive or an assembly reference?)"
How can i fix this?
my connection file code:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Web.UI.WebControls;
using System.Configuration;


/// <summary>
/// Summary description for connection
/// </summary>
public class connection
{
    public SqlConnection con = new SqlConnection();
    public SqlCommand cmd = new SqlCommand();
    public SqlDataAdapter adp = new SqlDataAdapter();
    public DataSet ds = new DataSet();
    public DataRow dr;
    public SqlCommandBuilder scb;
	public connection()
	{
        con.ConnectionString = ConfigurationManager.ConnectionStrings["email"].ConnectionString;
        adp.SelectCommand = cmd;
        cmd.Connection = con;
		//
		// TODO: Add constructor logic here
		//
	}
    public void ddlbind(string query, string text, string value, DropDownList id)
    {

        ds.Clear();
        cmd.CommandText = query;
        adp.Fill(ds, "vt");
        id.DataSource = ds.Tables["vt"];
        id.DataTextField = text;
        id.DataValueField = value;
        id.DataBind();
        id.Items.Insert(0, "--Select--");
    }
    public void gridbind(GridView id, string query)
    {
        ds.Clear();
        cmd.CommandText = query;
        adp.Fill(ds, "vt");
        id.DataSource = ds.Tables["vt"];
        id.DataBind();
    }
    public void databind(DataList id, string query)
    {
        ds.Clear();
        cmd.CommandText = query;
        adp.Fill(ds, "vt");
        id.DataSource = ds.Tables["vt"];
        id.DataBind();
    }
    public void detailsbind(DetailsView id, string query)
    {
        ds.Clear();
        cmd.CommandText = query;
        adp.Fill(ds, "vt");
        id.DataSource = ds.Tables["vt"];
        id.DataBind();
    }
    public void listbind(ListView id, string query)
    {
        ds.Clear();
        cmd.CommandText = query;
        adp.Fill(ds, "vt");
        id.DataSource = ds.Tables["vt"];
        id.DataBind();
    }
}


and .aspx page code is-
C#
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Net.Mail;

public partial class bulkemail : System.Web.UI.Page
{
    connection c = new connection();
    public string server1 = "gmail.com", user_id = "avatys99@gmail.com", pass = "9198430645";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                c.cmd.CommandText = "SELECT * FROM SYS.TABLES";
                c.adp.Fill(c.ds, "dk");
                DropDownList1.DataSource = c.ds.Tables["dk"];
                DropDownList1.DataTextField = c.ds.Tables["dk"].Columns["name"].ToString();
                DropDownList1.DataValueField = c.ds.Tables["dk"].Columns["name"].ToString();
                DropDownList1.DataBind();
                DropDownList1.Items.Insert(0, "--Select--");

                c.cmd.CommandText = "select count(*) as dd from excel";
                c.adp.Fill(c.ds, "vt");
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0} Exception caught.", ex);
            }
        }

    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        string body = "Name : " + txtsubject.Text + "<br />message : " + txtmsg.Text;
        try
        {
            Label lblname = new Label();
            lblname.Text = DropDownList1.SelectedItem.Text;

            MailMessage Msg = new MailMessage();
            // Sender e-mail address.
            Msg.From = new MailAddress("avatys99@gmail.com");
            // Recipient e-mail address.
            c.cmd.CommandText = "select * from" + " [" + DropDownList1.SelectedItem.Value + "]" + "";
            c.adp.Fill(c.ds, "vt1");
            //string s = c.ds.Tables["vt1"].Rows[i]["elist"].ToString();
            int i = 0;

            int eid = Convert.ToInt32(c.ds.Tables["vt"].Rows[0]["dd"].ToString());
            for (i = 0; i < eid; i++)
            {
                string s = c.ds.Tables["vt1"].Rows[i]["email"].ToString();
                Msg.To.Add(s);
            }

            Msg.To.Add("mishradhiraj66@gmail.com");


            Msg.Subject = txtsubject.Text;
            Msg.IsBodyHtml = true;
            Msg.Body = body;
            // your remote SMTP server IP.
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.Credentials = new System.Net.NetworkCredential("avatys99@gmail.com", "9198430645");
            smtp.EnableSsl = true;
            smtp.Send(Msg);
            Msg = null;

            txtsubject.Text = "";
            txtmsg.Text = "";
            lblmsg.Text = "Mail send Successfully";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>alert('Mail send Successfully' )</script>)");
        }
        catch (Exception ex)
        {
            Console.WriteLine("{0} Exception caught.", ex);
            lblmsg.Text = "Mail not Send";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>alert('Mail not Send' )</script>)");
        }
    }
}
Posted
Updated 2-May-14 2:14am
v3
Comments
CHill60 2-May-14 13:12pm    
Are you saying you are trying to build this from the server?

1 solution

SQL
If your project is a web application project, can you please check if the Build Action property of the class (Select class and hit F4) is set as 'Compile Only'. It should not be set as 'Content'.

When you deploy to web server, a web application project wraps its app_code class files in a dll and would be available in the bin folder. Make sure that you have deployed your bin folder to the web server.

If your project is a website type, then deploying the app_code folder on the root should make the site work.

Let us know if this works for you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900