The type or namespace name "server" cannot be found (is the using command or assembly reference missing ?)

Source: Internet
Author: User

Today Code , Copied to a C # class, and the compilation result is incorrect.
Database = server. mappath ("data. mdb ");
Error: The type or namespace name "server" cannot be found (whether the using command orProgramSet Reference ?)

But I did reference the namespace using system. Web. Why?
Because the complete path of the server is system. Web. httpcontext. Current. server. Using system. web is obviously not enough, but server can be directly written into the class inherited from the built-in page class. mappath "data. mdb "), it should be because the page class already contains these class paths.

the solutions to these errors are summarized as follows
1. Ensure that the correct assembly references:
ensure that the Assembly containing the namespace is referenced. If you are developing in Visual Studio. NET, go to the project menu and click Add reference. On the. NET tab, select the Assembly that contains the namespace you want to import, or browse to the folder that contains the assembly. If you are using the command line compiler, add the corresponding switch (/reference) to the compilation statement ).
2. Correct namespace:
(1) * If you execute this statement from the class inherited by the page class, you can simply use
database = server. mappath ("data. mdb ");
(2) if you are in a common class
A) Place the using statement at the top of the code file containing the type reference, make sure to import the namespace to the project:
using system. web;
database = httpcontext. current. server. mappath ("data. mdb ");
B) if there is no using statement, the reference to the type is fully Limited:
database = system. web. httpcontext. current. server. mappath ("data. mdb ");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.