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 !!

Dani AI

Generated

This is a classic "host can't find the class" situation: the site runs locally but the GoDaddy deployment throws CS0246 for DBConnect because the runtime on the host does not see a compiled type or source for that class. confirmed it works locally and pointed at the hosting/virtual-directory angle — good hint. Two distinct deployment models explain most cases: a Web Site (App_Code compiled dynamically by IIS) versus a Web Application (all code compiled into a DLL under bin). The server error means the ExpenseReport type is not present in the host's compilation scope.

Checklist to isolate and fix (do these in order):

  • Verify the App_Code folder sits in the application root (same folder as web.config and Index.aspx) and that DBConnect.cs is really uploaded with a .cs extension (not .txt) and non-zero size.
  • Confirm the project type: if it’s a Web Application, compile/publish locally and upload the compiled DLL(s) from bin — do not rely on App_Code on the server. If it’s a Web Site, leave source in App_Code but ensure the hosting control panel has that folder configured as an ASP.NET application (convert the folder to an application/virtual directory so IIS compiles App_Code).
  • Keep namespaces consistent: either wrap pages and helper classes in the same ExpenseReport namespace or reference the fully qualified ExpenseReport.DBConnect. Mismatched namespaces can hide types at runtime.
  • Check for leftover partial-class mismatches; if DBConnect is declared partial without another part, change to a plain public class DBConnect.

A few code/quality tips to apply while debugging (reduces other runtime problems): avoid static fields for per-request data, always dispose connections, and switch to parameterized queries to prevent SQL injection. Example pattern:

using (var conn = new SqlConnection(connString))
using (var cmd = new SqlCommand("SELECT ... FROM Employee WHERE empUsername=@u AND empPassword=@p", conn))
{
  cmd.Parameters.AddWithValue("@u", username);
  cmd.Parameters.AddWithValue("@p", password);
  new SqlDataAdapter(cmd).Fill(ds);
}

If these checks still fail, publish the site from Visual Studio (or build into a DLL and drop it in bin) and, if needed, contact GoDaddy support with the full error text and the path shown on the host so they can confirm the folder is an application and the correct .NET version is set.

Recommended Answers

All 8 Replies

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.

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.