I create website on asp.net, is name ExpenseReport

First, I create 'DBConnect' class in App_Code by using namespace ExpenseReport

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;

namespace ExpenseReport
{
    public partial class DBConnect
    {
        private SqlConnection objConn;
        private SqlCommand objCmd;
        private SqlTransaction Trans;
        private String strConnString;
        private String strCommandString;
        private static String empID;
        private static String empName;

        public DBConnect()
        {
            strConnString = ConfigurationManager.ConnectionStrings["Con"].ToString();
        }

        public SqlDataReader QueryDataReader(String strSQL)
        {
            SqlDataReader dtReader;
            objConn = new SqlConnection();
            objConn.ConnectionString = strConnString;
            objConn.Open();

            objCmd = new SqlCommand(strSQL, objConn);
            dtReader = objCmd.ExecuteReader();
            return dtReader; //*** Return DataReader ***//
        }

        public DataSet QueryDataSet(String strSQL)
        {
            DataSet ds = new DataSet();
            SqlDataAdapter dtAdapter = new SqlDataAdapter();
            objConn = new SqlConnection();
            objConn.ConnectionString = strConnString;
            objConn.Open();

            objCmd = new SqlCommand();
            objCmd.Connection = objConn;
            objCmd.CommandText = strSQL;
            objCmd.CommandType = CommandType.Text;

            dtAdapter.SelectCommand = objCmd;
            dtAdapter.Fill(ds);
            return ds;   //*** Return DataSet ***//
        }
    }
}

Second, I create all page that I needs and all page use DBConnect class

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Common;

namespace ExpenseReport
{
    public partial class Index : System.Web.UI.Page
    {
        DBConnect DB = new DBConnect();
        bool isLogin = false;
                
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            IsCheck(txtUsername.Text, txtPassword.Text);
        }

        private void IsCheck(string username, string password)//ตรวจสอบค่าที่รับเข้ามา
        {
            string role = "";
            string empName = "";
            string empID = "";

            string SQL = "SELECT empUsername, empPassword, empType, empID, empName FROM Employee WHERE empUsername = '" + username + "' AND empPassword = '" + password + "'";

            DataSet ds;

            ds = DB.QueryDataSet(SQL);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (username == ds.Tables[0].Rows[0]["empUsername"].ToString())
                {
                    if (password == ds.Tables[0].Rows[0]["empPassword"].ToString())
                    {
                        isLogin = true;

                        role = ds.Tables[0].Rows[0]["empType"].ToString();
                        empName = ds.Tables[0].Rows[0]["empName"].ToString();
                        empID = ds.Tables[0].Rows[0]["empID"].ToString();
                    }
                    else
                    {
                        isLogin = false;
                    }
                }
                else
                {
                    isLogin = false;
                }
            }
            else
            {
                isLogin = false;
            }

            if (isLogin)
            {
                MyTicket(username, role, empName, empID); //เรียกใช้ ticket
            }
            else
            {
                Label1.Text = "Login Failed";
            }           
        }
    }
}

It's OK when I runs on my computer.

After that, I upload website into my hosting (host:godaddy), It's error

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0246: The type or namespace name 'DBConnect' could not be found (are you missing a using directive or an assembly reference?)

Why???
What could I do?
Please suggest me !!

Try importing you name space ExpenseReport in index page too
and then create any instance of Dbclass that you have done.

In reall this should not be required,but it may help in your case.
:)

I change coding follow you suggest

But It's error. Pleaseeee

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0246: The type or namespace name 'ExpenseReport' could not be found (are you missing a using directive or an assembly reference?)

Source Error:

Line 10: using System.Web.UI.HtmlControls;
Line 11: using System.Data.Common;
Line 12: using ExpenseReport;
Line 13: 
Line 14:     public partial class Index : System.Web.UI.Page


Source File: d:\hosting\7644078\html\ExpenseReport\Index.aspx.cs    Line: 12

My coding...

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Common;
using ExpenseReport;

    public partial class Index : System.Web.UI.Page
    {
        DBConnect DB = new DBConnect();
        bool isLogin = false;
                
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            IsCheck(txtUsername.Text, txtPassword.Text);
        }

        private void IsCheck(string username, string password)//ตรวจสอบค่าที่รับเข้ามา
        {
            string role = "";
            string empName = "";
            string empID = "";

            string SQL = "SELECT empUsername, empPassword, empType, empID, empName FROM Employee WHERE empUsername = '" + username + "' AND empPassword = '" + password + "'";

            DataSet ds;

            ds = DB.QueryDataSet(SQL);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (username == ds.Tables[0].Rows[0]["empUsername"].ToString())
                {
                    if (password == ds.Tables[0].Rows[0]["empPassword"].ToString())
                    {
                        isLogin = true;

                        role = ds.Tables[0].Rows[0]["empType"].ToString();
                        empName = ds.Tables[0].Rows[0]["empName"].ToString();
                        empID = ds.Tables[0].Rows[0]["empID"].ToString();
                    }
                    else
                    {
                        isLogin = false;
                    }
                }
                else
                {
                    isLogin = false;
                }
            }
            else
            {
                isLogin = false;
            }

            if (isLogin)
            {
                MyTicket(username, role, empName, empID); //เรียกใช้ ticket
            }
            else
            {
                Label1.Text = "Login Failed";
            }           
        }

        void MyTicket(string username, string role, string empName, string empID) //Ticket
        {
            //FormsAuthenticationTicket ticket;//สร้าง Ticket
            //HttpCookie cookie = null; //สร้าง cookies เพื่อเก็บค่าเป็น cookies
            //ticket = new FormsAuthenticationTicket(1, username, DateTime.Now, DateTime.Now.AddMinutes(5), false, "");
            //string encrypt = FormsAuthentication.Encrypt(ticket);
            //cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypt);


            HttpCookie cookie = new HttpCookie("mylogin");

            cookie.Values["empID"] = empID;
            cookie.Values["empName"] = empName;

            Response.Cookies.Add(cookie);

            if (role == "Executive")
            {
                Response.Redirect("~/Executive/Home.aspx");
            }
            else if (role == "Employee")
            {
                Response.Redirect("~/Employee/Home.aspx");
            }
            else if (role == "Account")
            {
                Response.Redirect("~/Account/Home.aspx");
            }
        }
    }

First remove the change i told you to make. Because it has result into few more error.

And check where is the .cs file stored,i mean your Dbconnect class file?
Is it in appcode or is it in a different project. The problem may be of path,when you are hosting it,it is not getting the reference.

Check once again and play with the paths and all.

Did you tried using a different name as you namespace name??
Try it once...

Like put it as ExpenseSummary in place of ExpenseReport.

DBConnect.cs class file is store in App_Code in my project

I don't know that I should do.

did you tried renaming the namespace name or not??

Before, I create name is ExpenseClaim

It has error same same

So I create new project is ExpenseReport and coding again

Last, It has error same old project


I try to fix it but It can't :(

I have gone through several sites for your problem and the result is that it isn't a code or server configuration error.

You need to change a setting in your control panel for your website. Setting your website working directory as a virtual dir will resolve the issue.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.