ASP.net/SQL newbie Question
-
I followed the article here http://www.kirupa.com/net/sql\_asp\_introduction.htm everything compiles ok but when it get to opening the database I get error message An attempt to attach an auto-named database for file C:\Path\Games.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share I do not have any other databases with the same name and it is on the C drive so leads me to believe for some reason it can not open the database. could someone please help me with this. Thanks
-
I followed the article here http://www.kirupa.com/net/sql\_asp\_introduction.htm everything compiles ok but when it get to opening the database I get error message An attempt to attach an auto-named database for file C:\Path\Games.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share I do not have any other databases with the same name and it is on the C drive so leads me to believe for some reason it can not open the database. could someone please help me with this. Thanks
-
ok i figured out what was wrong, .net 2.0 needed to be reinstalled, my app now runs but does not write to the database, is there something wrong with my code to write to the database? SqlConnection connection; protected void Page_Load(object sender, EventArgs e) { connection = new SqlConnection(ConfigurationManager.ConnectionStrings["GameConnection"].ConnectionString); } protected void btnSubmit_Click(object sender, EventArgs e) { SqlCommand command = new SqlCommand("INSERT INTO gameTable(gameName, gamePlatform) VALUES (@id_gameName,@id_gmaePlatform)", connection); SqlParameter nameContent = new SqlParameter("@id_gameName", SqlDbType.VarChar); nameContent.Value = txtName.Text; command.Parameters.Add(nameContent); SqlParameter platformContent = new SqlParameter("@id_gamePlatform", SqlDbType.VarChar); platformContent.Value = txtPlatform.Text; command.Parameters.Add(platformContent); connection.Open(); command.BeginExecuteNonQuery(); connection.Close(); Response.Redirect("Results.aspx"); }
-
ok i figured out what was wrong, .net 2.0 needed to be reinstalled, my app now runs but does not write to the database, is there something wrong with my code to write to the database? SqlConnection connection; protected void Page_Load(object sender, EventArgs e) { connection = new SqlConnection(ConfigurationManager.ConnectionStrings["GameConnection"].ConnectionString); } protected void btnSubmit_Click(object sender, EventArgs e) { SqlCommand command = new SqlCommand("INSERT INTO gameTable(gameName, gamePlatform) VALUES (@id_gameName,@id_gmaePlatform)", connection); SqlParameter nameContent = new SqlParameter("@id_gameName", SqlDbType.VarChar); nameContent.Value = txtName.Text; command.Parameters.Add(nameContent); SqlParameter platformContent = new SqlParameter("@id_gamePlatform", SqlDbType.VarChar); platformContent.Value = txtPlatform.Text; command.Parameters.Add(platformContent); connection.Open(); command.BeginExecuteNonQuery(); connection.Close(); Response.Redirect("Results.aspx"); }
Planker wrote:
command.BeginExecuteNonQuery(); connection.Close();
You make an asynchronous call to insert data, but you close the connection right after that then how data can be inserted into DB. You might also double check the parameter name
gmaePlatform
as well.