Detailed handling of Some Problems in iis access (Vs normal access)

Source: Internet
Author: User

Today, a garden friend asked me a question. The question generally means that a new project can be created and debugged normally in vs, but various problems may occur during iis access. I personally think this problem is easy to solve, because my friends and I are far away and can only use QQ videos for operations. However, I found that communication in this way is really inconvenient. Simply sort out these problems, so that you can easily clarify the handling methods.

Because my current project does not have this problem, I can only create a simple project, and then operate locally to try to make this problem happen, this is also because I have never sorted out such issues. Now, I will sort out some of my problems and explain how to solve them. If you still have some problems, but I didn't think of them now, please leave a message for me and I will sort them out.

First, let's talk about the first problem: database access problems. I'm afraid this is the most common problem. This operation is very simple. I will not elaborate on the specific details and you will understand it at a glance.

First, we created a new Web project and added a page named test. aspx, which adds a button. When you click this button, it connects to the database to extract data from the database and display it on the page's gridView.
Copy codeThe Code is as follows:
Protected void button#click (object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection (@ "Data Source =. \ sqlexpress; Initial Catalog = DbLog; Integrated Security = True ");
SqlCommand cmd = conn. CreateCommand ();
Try
{
String SQL = "select top 10 * from log ";
SqlDataAdapter sda = new SqlDataAdapter (SQL, conn );
DataTable dt = new DataTable ();
Sda. Fill (dt );

GridView1.DataSource = dt;
GridView1.DataBind ();
}
Catch (Exception ex)
{
String errmsg = ex. Message;
Response. Write (ex. Message );
}
}

If an exception occurs during database connection, we can print out the exception information directly. Now let's look at the results.

The figure above shows the result obtained after running through F5 in vs. It is obvious that the result is correct. Now let's take a look at the result displayed under iis. What, you don't know how to put it in IIS for access. Well, let me briefly describe how to create a new virtual directory or website in IIS, then, enter the project path.

An error occurs during access to IIS. It does not display data in the database, but the exception information displayed in the exception information. Why? Why did I fail to open the database when I check the exception message? For this reason, we can consider several aspects.

    Database Configuration problems, because this blog will be very long if you want to describe the database configuration, so a brief description is given, it is generally possible to enable several of them in the database.

2. If it is not a database configuration problem, the database password we opened may be incorrect. Check whether the server to open the database is correct and whether the database name is correct. Because the access is verified by Windows, there is no Password error.

3. Permission issues. This should be the most important issue, which will make some people crazy. In fact, the principle of controlling user access during project operations is the same. The database prohibits the user access.

As for permission issues, let's talk about which user is IIS running? If we log on to the operating system as an administrator, an error still occurs. In fact, IIS runs in a user named iis_user. This name may vary in different IIS versions. Network_services is also required in IIS, but IIS7 is the user, because I installed IIS7. if we use the Server 2003 system, you can directly set permissions on IIS. I use server 2003 in my company, so it is clear.

 

First, an error is reported. Due to insufficient permissions, we can add permissions to him. Select the project folder, add the iis_users user, and grant specific permissions to the user.

Some Garden friends may scold me. Why can't I see the Database Failure error? I can only say sorry, because I did not simulate the error. Because I use Windows 7, what database connection error should I expect when a configuration error occurs. I will try again when simulating the login error. However, setting permissions should solve all permission errors.

To sum up, Iis login errors are very basic, as long as we make good use of the search engine, this type of problem is generally easy to solve. This podcast is a common sense post. It is easy to know, but if you cannot find the cause, it is also annoying, so I would like to share it with you.

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.