Reputation: 13
I am using 3 tier architecture with ProfileDAL and ProfileBLL. I think my code for create is fine but i always encounter this particular error.
My database name is CottonyDB.mdf. Below are the pics for the error and my web.config.
Error for database:
web.config:
Heres my code for create:
public class 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;
}
}
}
Upvotes: 1
Views: 56
Reputation: 17039
Remove Initial Catalog=CottonyDB;
from your connection string, it already knows which database to use because you are using AttachDbFileName
.
Have a look at this SO question - Cannot attach the file *.mdf as database
Upvotes: 1