這是一個非常簡單的網站,用戶填寫輸入並可以將它們保存在sql數據庫中,也可以發送電子郵件。不過我有兩個錯誤,這是第一次:兩個常見錯誤阻止本網站正常工作
試圖附加自動命名的數據庫文件 C:\用戶\桌面\ Dpp2012New \ App_Data文件\ dppdatabase.mdf失敗。 A 數據庫中存在相同的名稱,或者指定的文件不能被 打開,或者它位於UNC共享上。
描述:在執行 當前Web請求期間發生未處理的異常。請查看堆棧跟蹤以獲取有關該錯誤的更多信息以及源代碼的位置。
異常詳細信息:System.Data.SqlClient.SqlException:試圖附加自動命名的數據庫文件 C:\用戶\桌面\ Dpp2012New \ App_Data文件\ dppdatabase.mdf失敗。 A 數據庫中存在相同的名稱,或者指定的文件不能被 打開,或者它位於UNC共享上。
這是第二個:
類型的未處理的異常 'System.Data.SqlClient.SqlException' 出現在system.data.dll
表示:
'('。sql
它獲取的代碼cmd.ExecuteNonQuery();
下面是我的代碼:
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)
{
}
}
我已經嘗試了一些解決方案,但他們沒有work.Any幫助將非常感激。
它只是保存的信息,從而爲插入(我猜cuz Im初學者在C#中)下一次,頁面重新加載,我們可以再次添加數據。 – programmer21
我不明白你問題的第二部分,你會介意嗎? – programmer21
你的桌子是什麼樣的? – born2bmild