This is a very simple website that the user fills the inputs and can save them in sql database and can send an email too. However I got two errors,this is the first:
An attempt to attach an auto-named database for file C:\Users...\Desktop\Dpp2012New\App_Data\dppdatabase.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: An attempt to attach an auto-named database for file C:\Users...\Desktop\Dpp2012New\App_Data\dppdatabase.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
And this is the second one:
Unhandled Exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
that shows :
incorrect syntax near '('. sql
which gets to code cmd.ExecuteNonQuery();
Below is my code:
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source= LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\user\Documents\Visual Studio 2015\WebSites\WebSite4\App_Data\Database.mdf;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2&emr=1&osid=1#identifier");
}
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "save ('"+txtName.Text+"','"+txtLtName.Text+"','"+compName.Text+"','"+address0ne.Text+"','"+addressTwo.Text+"','"+cityName.Text+"','"+reionName.Text+"','"+postCode.Text+"','"+countryName.Text+"','"+emailAddress.Text+"')";
cmd.ExecuteNonQuery();
con.Close();
}
protected void TextBox3_TextChanged(object sender, EventArgs e)
{
}
}
I have tried some solutions but they didn't work.Any help would be much appreciated.