无法解决ASP.NET

时间:2016-07-17 05:18:20

标签: asp.net

我正在使用ProfileDAL和ProfileBLL的3层架构。我认为我的创建代码很好,但我总是遇到这个特殊的错误。

我的数据库名称是CottonyDB.mdf。下面是错误的图片和我的web.config。

数据库错误: Error for database

web.config中: web.config file

继承我的创建代码:

公共类ProfileDAL     {         string strConnectionString = ConfigurationManager.ConnectionStrings [“CottonyDBString”]。ToString();

    public int create_Account(string Username, string pwd1, string email, string mobile, string pwdSalt, string mblVerified, string emailVerified)
    {
        var returnValue = 0;

        using (SqlConnection con = new SqlConnection(strConnectionString))
        {
            using (SqlCommand cmd = new SqlCommand("INSERT INTO ACCOUNT (Username,PasswordHash,Email,Mobile,PasswordSalt,MobileVerified,EmailVerified) Values (@Username,@PasswordHash,@email,@mobile,@pwdSalt,@mblVerified,@emailVerified)", con))
            {
                SqlParameter[] prms = new SqlParameter[7];

                prms[0] = new SqlParameter("@Username", SqlDbType.NChar, 20);
                prms[0].Value = Username;

                prms[1] = new SqlParameter("@PasswordHash", SqlDbType.NVarChar, 20);
                prms[1].Value = pwd1;

                prms[2] = new SqlParameter("@Email", SqlDbType.NChar, 20);
                prms[2].Value = email;

                prms[3] = new SqlParameter("@Mobile", SqlDbType.NChar, 10);
                prms[3].Value = mobile;

                prms[4] = new SqlParameter("@PasswordSalt", SqlDbType.NVarChar, 20);
                prms[4].Value = pwdSalt;

                prms[5] = new SqlParameter("@MobileVerified", SqlDbType.NVarChar, 10);
                prms[5].Value = mblVerified;

                prms[6] = new SqlParameter("@EmailVerified", SqlDbType.NVarChar, 10);
                prms[6].Value = emailVerified;

                cmd.Parameters.AddRange(prms);
                con.Open();
                returnValue = cmd.ExecuteNonQuery();
                con.Close();



            }
            return returnValue;




        }




    }

}

1 个答案:

答案 0 :(得分:1)

从连接字符串中删除Initial Catalog=CottonyDB;,它已经知道要使用哪个数据库,因为您使用的是AttachDbFileName

看看这个问题 - Cannot attach the file *.mdf as database