C# 我很难建立一个简单的数据库实现的网站

C# 我很难建立一个简单的数据库实现的网站,c#,asp.net,database,sqlite,C#,Asp.net,Database,Sqlite,这是我在这里的第一个问题,所以请耐心等待我。:) 所以,我花了几个小时试图解决这个问题,但还没有找到解决方案。 问题很简单: 我正在使用Visual Studio 2013 Ultimate 90天试用版和ASP.Net Framework 4.5和C#创建一个简单的网站,用户可以在其中创建帐户,这意味着他们的帐户数据需要保存到数据库中 我使用的数据库工具是SQLite,因为我读到这是一个用于小型数据库的好工具 因此,在我实际输入测试用户的信息并单击“创建帐户!”按钮之前,我的应用程序运行良好。

这是我在这里的第一个问题,所以请耐心等待我。:) 所以,我花了几个小时试图解决这个问题,但还没有找到解决方案。 问题很简单:

我正在使用Visual Studio 2013 Ultimate 90天试用版和ASP.Net Framework 4.5和C#创建一个简单的网站,用户可以在其中创建帐户,这意味着他们的帐户数据需要保存到数据库中

我使用的数据库工具是SQLite,因为我读到这是一个用于小型数据库的好工具

因此,在我实际输入测试用户的信息并单击“创建帐户!”按钮之前,我的应用程序运行良好。此时,我的应用程序会出现以下错误:

---------------------------------------------------------------------------- 访问路径“C:\Program Files(x86)\IIS” Express\databaseFile.db3'被拒绝

描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源

异常详细信息:System.UnauthorizedAccessException:访问 路径“C:\Program Files(x86)\IIS Express\databaseFile.db3”被拒绝

ASP.NET无权访问请求的资源。考虑 向ASP.NET请求授予对资源的访问权限 身份。ASP.NET具有基本进程标识(通常为 {MACHINE}\ASPNET(位于IIS 5上)或IIS 6和IIS 7上的网络服务,以及 在以下情况下使用的IIS 7.5上配置的应用程序池标识: 应用程序没有模拟。如果申请是 通过模拟,身份将为 匿名用户(通常为IUSR_MACHINENAME)或经过身份验证的 请求用户

要授予ASP.NET对文件的访问权限,请在文件中的文件上单击鼠标右键 在浏览器中,选择“属性”并选择“安全”选项卡。单击“添加” 添加适当的用户或组。突出显示ASP.NET帐户, 并选中所需访问权限的框

源错误:

第28行:)“第29行:第30行:
System.Data.SQLite.SQLiteConnection.CreateFile(“databaseFile.db3”);
//创建将承载数据库第31行的文件:
使用(System.Data.SQLite.SQLiteConnection con=new System.Data.SQLite.SQLiteConnection(“数据源=databaseFile.db3”)) 第32行:{

源文件:c:\Users\Alex\Documents\Visual Studio 2013\Projects\WebDataBase\WebDataBase\SignUpForm.aspx.cs行:30

堆栈跟踪:

[UnauthorizedAccessException:访问路径“C:\Program Files” (x86)\IIS Express\databaseFile.db3'被拒绝。]
System.IO.\uuu Error.WinIOError(Int32 errorCode,字符串maybeFullPath) +217 System.IO.FileStream.Init(字符串路径、文件模式、文件访问权限、Int32权限、布尔用户权限、文件共享共享、, Int32 bufferSize、FileOptions选项、安全属性secAttrs、, 字符串msgPath,布尔bFromProxy,布尔useLongPath,布尔 checkHost)+1305 System.IO.FileStream..ctor(字符串路径,文件模式 模式,文件访问,文件共享共享,Int32 bufferSize)+63
System.Data.SQLite.SQLiteConnection.CreateFile(字符串 databaseFileName)+38 WebDataBase.SignUpForm.AddNewUser(字符串pw) 在c:\Users\Alex\Documents\Visual Studio中 2013\Projects\WebDataBase\WebDataBase\SignUpForm.aspx.cs:30
WebDataBase.SignUpForm.Button\u CREATE\u ACCOUNT\u Click1(对象发送者, c:\Users\Alex\Documents\Visual Studio中的事件参数 2013\Projects\WebDataBase\WebDataBase\SignUpForm.aspx.cs:71
System.Web.UI.WebControls.Button.OnClick(EventArgs e)+9653178
System.Web.UI.WebControl.Button.RaisePostBackEvent(字符串 事件参数)+103
System.Web.UI.WebControl.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串 事件参数)+10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,String eventArgument)+13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35 System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔IncludeStagesSafterAsyncPoint) +1724年

---------------------------------------------------------------------------- 好的,我读到,要解决这个问题,我所要做的只是授予对数据库文件的访问权,但我不能这样做,因为数据库文件还不存在

有人能帮我吗

谢谢!:D

哦,如果你需要,这是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SQLite;

namespace WebDataBase
{
    public partial class SignUpForm : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void AddNewUser(string pw)
        {
            string email = TextBox_EMAIL.Text;
            string username = TextBox_USERNAME.Text;

            string createTableQuery = @"CREATE TABLE IF NOT EXISTS [UserData] (
                          [ID] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
                          [Email] NVARCHAR(30)  NULL,
                          [Username] NVARCHAR(12)  NULL,
                          [Password] NVARCHAR(12) NULL
                          )";

            System.Data.SQLite.SQLiteConnection.CreateFile("databaseFile.db3");        // Create the file which will be hosting our database
            using (System.Data.SQLite.SQLiteConnection con = new System.Data.SQLite.SQLiteConnection("data source=databaseFile.db3"))
            {
                using (System.Data.SQLite.SQLiteCommand com = new System.Data.SQLite.SQLiteCommand(con))
                {
                    con.Open();                             // Open the connection to the database

                    com.CommandText = createTableQuery;     // Set CommandText to our query that will create the table
                    com.ExecuteNonQuery();                  // Execute the query

                    com.CommandText = "INSERT INTO UserData (ID,Email,Username,Password) Values ('" + email + "','" + username + "','" + pw + "')";     // Add the first entry into our database 
                    com.ExecuteNonQuery();      // Execute the query
                    //com.CommandText = "INSERT INTO UserData (ID,Email,Username,Password) Values ('key two','value value')";   // Add another entry into our database 
                    // com.ExecuteNonQuery();      // Execute the query

                    com.CommandText = "Select * FROM UserData";      // Select all rows from our database table

                    using (System.Data.SQLite.SQLiteDataReader reader = com.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            string row = (reader["ID"] + " : " + reader["Email"] + " : " +
                                reader["Username"] + " : " + reader["Password"]);     // Display the value of the key and value column for every row
                            Label1.Text = row;
                        }
                    }
                    con.Close();        // Close the connection to the database
                }
            }

        }

        protected void Button_CREATE_ACCOUNT_Click1(object sender, EventArgs e)
        {
            Label1.Text = "";
            string pw = TextBox_PASSWORD.Text;
            string confirmedPw = TextBox_CONFIRM_PASSWORD.Text;

            // Check if "password" and "confirm password" values are the same
            if (pw.Equals(confirmedPw, StringComparison.Ordinal))
            {
                AddNewUser(pw);
            }
            else
            {
                Label1.Text = "Passwords are not matching.  Please make sure they are matching.";
            }
        }
    }
}

您需要在
C:\Program Files(x86)\IIS Express\
文件夹本身(我可能不建议这样做)上授予应用程序权限,或者在项目文件夹中实际使用另一个文件夹(在您的情况下,看起来是
C:\Users\Alex\Documents\Visual Studio 2013\Projects\WebDataBase\WebDataBase
)相反,这将是我的建议。

您是否以管理员身份运行Visual Studio?